//
//  SettingsView.swift
//  App
//
//  Created by James Magahern on 3/3/21.
//

import SwiftUI

struct SettingsCategoryCell: View {
    @State var title: String = ""
    
    var body: some View {
        HStack {
            Text(title)
                .bold()
                .frame(height: 34.0)
        }
    }
}

struct AmberSettingsView: View {
    @Environment(\.presentationMode)
        @Binding private var presentationMode
    
    @State private var searchProvider = Settings.shared.searchProvider {
        didSet { Settings.shared.searchProvider = searchProvider }
    }
    
    var body: some View {
        NavigationView {
            List {
                Section(header: Text("Redirect Rules"), content: {
                    Text("To Do")
                })
                
                Section(header: Text("Search Provider"), content: {
                    ForEach(Settings.SearchProviderSetting.allCases, id: \.self, content: { setting in
                        Button(action: { searchProvider = setting }, label: {
                            HStack {
                                Text(setting.rawValue)
                                Spacer()
                                if searchProvider == setting {
                                    Image(systemName: "checkmark")
                                }
                            }
                        }).buttonStyle(PlainButtonStyle())
                    })
                })
            }
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitle("Settings", displayMode: .inline)
            .toolbar(content: {
                #if !targetEnvironment(macCatalyst)
                Button("Done", action: { presentationMode.dismiss() })
                #endif
            })
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct SettingsView_Previews: PreviewProvider {
    static var previews: some View {
        AmberSettingsView()
    }
}
