import SwiftUI
import SFSafeSymbols

struct NavigationBarSettingsView: View {

    @Environment(\.language)
    private var language

    @EnvironmentObject
    private var content: Content
    
    @State
    private var showItemPicker = false

    var body: some View {
        ScrollView {
            VStack(alignment: .leading) {
                DetailTitle(
                    title: "Navigation Bar",
                    text: "Customize the navigation bar for all pages at the top of the website")

                HStack {
                    Text("Links")
                        .font(.headline)
                    Button(action: { showItemPicker = true }) {
                        Image(systemSymbol: .squareAndPencilCircleFill)
                            .resizable()
                            .aspectRatio(1, contentMode: .fit)
                            .frame(height: 22)
                            .foregroundColor(Color.gray)
                            .background(Circle()
                                .fill(Color.white)
                                .padding(1))
                    }
                    .buttonStyle(.plain)
                }

                ForEach(content.settings.navigation.navigationItems) { tag in
                    TagView(text: tag.title(in: language))
                    .foregroundStyle(.white)
                }
                Text("Select the tags to show in the navigation bar. The number should be even.")
                    .foregroundStyle(.secondary)

                LocalizedNavigationBarSettingsView(settings: content.settings.navigation.localized(in: language))
            }
            .padding()
        }
        .sheet(isPresented: $showItemPicker) {
            ItemSelectionView(
                isPresented: $showItemPicker,
                selectedItems: $content.settings.navigation.navigationItems)
        }
    }
}

#Preview {
    NavigationBarSettingsView()
        .environmentObject(Content.mock)
        .padding()
}
