import SwiftUI struct SettingsScreen: View { @EnvironmentObject var clientsStore: ClientsStore @Environment(\.router) var router var body: some View { ZStack { // Background color Color.Material.Background.light .ignoresSafeArea() // Content VStack(spacing: 0) { // Header SharedNavigationBar( centerText: .init(text: L10n.Settings.Main.title) ) // List List { // Accounts section SharedSectionTitle(text: L10n.Settings.Section.Accounts.title) ForEach(clientsStore.clients) { client in SharedListRow( iconType: .charCircle(client.credentials.bareJid), text: client.credentials.bareJid, controlType: .switcher(isOn: Binding( get: { client.credentials.isActive }, set: { new in Task { try? await client.credentials.setActive(flag: new) } } )) ) .onTapGesture { print("Tapped account \(client.credentials.bareJid)") } } SharedListRow( iconType: .image(Image(systemName: "plus"), .Material.Elements.active), text: L10n.Settings.Section.Accounts.add, controlType: .none ) .onTapGesture { router.showAlert( .confirmationDialog, title: L10n.Settings.Section.Accounts.add, subtitle: L10n.Settings.Section.Accounts.addHint ) { addAccountSelector } } // Dev section #if DEBUG SharedSectionTitle(text: "Dev tools") SharedListRow( iconType: .image(Image(systemName: "xmark.octagon"), .Rainbow.red500), text: "Clean all data", controlType: .none ) .onTapGesture { router.showAlert( .alert, title: "Delete data", subtitle: "Delete all data from the app?" ) { Button("Delete", role: .destructive) { clientsStore.flushAllData() Database.shared.flushAllData() UserSettings.reset() } } } #endif } .listStyle(.plain) .environment(\.defaultMinListRowHeight, 10) Spacer() } } } @ViewBuilder private var addAccountSelector: some View { Button { print("Add existing account") } label: { Text(L10n.Settings.Section.Accounts.addExists) } Button { print("Add new account") } label: { Text(L10n.Settings.Section.Accounts.addNew) } Button(role: .cancel) {} label: { Text(L10n.Global.cancel) } } }