import SwiftUI

struct LanguageSettingsView: View {
    @EnvironmentObject private var languageManager: LanguageManager
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        NavigationView {
            List {
                Section(header: Text("select_language".localized).font(.headline).id(languageManager.refreshTrigger)) {
                    ForEach(Language.allCases, id: \.self) { language in
                        HStack {
                            Text(language.flag)
                                .font(.title2)
                            
                            VStack(alignment: .leading, spacing: 4) {
                                Text(language.displayName)
                                    .font(.body)
                                    .fontWeight(.medium)
                                
                                Text(language.rawValue.uppercased())
                                    .font(.caption)
                                    .foregroundColor(.secondary)
                            }
                            
                            Spacer()
                            
                            if languageManager.currentLanguage == language {
                                Image(systemName: "checkmark.circle.fill")
                                    .foregroundColor(.blue)
                                    .font(.title2)
                            }
                        }
                        .contentShape(Rectangle())
                        .onTapGesture {
                            languageManager.switchLanguage(to: language)
                        }
                    }
                }
                
                Section(footer: Text("language_changes_info".localized).font(.caption).foregroundColor(.secondary).id(languageManager.refreshTrigger)) {
                    HStack {
                        Image(systemName: "info.circle")
                            .foregroundColor(.blue)
                        Text(String(format: "current_language".localized, languageManager.currentLanguage.displayName))
                            .font(.body)
                            .id(languageManager.refreshTrigger)
                    }
                }
            }
            .navigationTitle("language_settings".localized)
            .navigationBarTitleDisplayMode(.inline)
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button("done".localized) {
                        dismiss()
                    }
                    .id(languageManager.refreshTrigger)
                }
            }
        }
    }
}

#if DEBUG
struct LanguageSettingsView_Previews: PreviewProvider {
    static var previews: some View {
        LanguageSettingsView()
            .environmentObject(LanguageManager.shared)
    }
}
#endif 