// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown // SPDX-License-Identifier: GPL-3.0-or-later import SwiftUI /// Building blocks of the Setup tab, after Android's SettingsScreen: titled cards, /// buttons, link rows, rows for sections still to come, and the modal dialog. /// SwiftUI only (the Mac snapshot tool renders them). enum SetupStyle { static var danger: Color { Theme.danger } static let corner: CGFloat = 10 } /// A titled card for one settings group (Android's SettingsCard). struct SetupCard: View { let title: String var subtitle: String? var enabled = true @ViewBuilder let content: () -> Content var body: some View { VStack(alignment: .leading, spacing: 10) { VStack(alignment: .leading, spacing: 3) { Text(title).font(.system(size: 17, weight: .semibold)).foregroundColor(enabled ? Theme.accent : Theme.dim) if let s = subtitle { Text(s).font(.system(size: 13)).foregroundColor(Theme.dim) } } content() } .padding(16) .frame(maxWidth: .infinity, alignment: .leading) .background(Theme.surface, in: RoundedRectangle(cornerRadius: SetupStyle.corner)) } } /// Filled (primary), outlined or destructive button. struct SetupButton: View { enum Kind { case filled, outlined, danger } let title: String var icon: String? var kind: Kind = .outlined var enabled = true let action: () -> Void var body: some View { Button(action: action) { HStack(spacing: 6) { if let icon = icon { Image(systemName: icon).font(.system(size: 13)) } Text(title).font(.system(size: 15, weight: .medium)).lineLimit(1) } .padding(.horizontal, 14).frame(minHeight: 38) .foregroundColor(foreground) .background(background, in: Capsule()) .overlay(Capsule().stroke(kind == .outlined ? Theme.grid : Color.clear, lineWidth: 1)) .contentShape(Capsule()) } .buttonStyle(.plain) .disabled(!enabled) .opacity(enabled ? 1 : 0.4) } private var foreground: Color { switch kind { case .filled: return Theme.background case .outlined: return Theme.text case .danger: return .white } } private var background: Color { switch kind { case .filled: return Theme.accent case .outlined: return .clear case .danger: return SetupStyle.danger } } } /// Small grey explanatory text under a group of buttons. struct SetupNote: View { let text: String init(_ text: String) { self.text = text } var body: some View { Text(text).font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true) } } struct SetupDivider: View { var body: some View { Rectangle().fill(Theme.grid.opacity(0.7)).frame(height: 1) } } /// A tappable row with a label, a detail line and a chevron (Android's LinkRow and NavCard). struct SetupRow: View { let title: String let detail: String var icon: String? var tint: Color = Theme.accent let action: () -> Void var body: some View { Button(action: action) { HStack(spacing: 12) { if let icon = icon { Image(systemName: icon).font(.system(size: 17)).foregroundColor(tint).frame(width: 24) } VStack(alignment: .leading, spacing: 2) { Text(title).font(.system(size: 16, weight: .medium)).foregroundColor(tint) Text(detail).font(.system(size: 12)).foregroundColor(Theme.dim).lineLimit(2) } Spacer(minLength: 8) Image(systemName: "chevron.right").font(.system(size: 13, weight: .semibold)).foregroundColor(tint) } .padding(.vertical, 8) .contentShape(Rectangle()) } .buttonStyle(.plain) } } /// An Android settings section not ported yet: its place in the layout, greyed /// out and marked as coming later. struct ComingLaterRow: View { let title: String let subtitle: String let icon: String var body: some View { HStack(spacing: 12) { Image(systemName: icon).font(.system(size: 16)).foregroundColor(Theme.dim).frame(width: 24) VStack(alignment: .leading, spacing: 2) { Text(title).font(.system(size: 15, weight: .medium)).foregroundColor(Theme.dim) Text(subtitle).font(.system(size: 12)).foregroundColor(Theme.dim.opacity(0.75)).lineLimit(2) } Spacer(minLength: 8) Text("Later").font(.system(size: 11)).foregroundColor(Theme.dim) .padding(.horizontal, 8).padding(.vertical, 3) .overlay(Capsule().stroke(Theme.grid, lineWidth: 1)) .fixedSize() } .padding(.vertical, 4) .accessibilityElement(children: .combine) .accessibilityHint("Coming in a later version") } } /// The Setup tab's modal dialogs. iOS 15 alerts can't hold a text field, so the /// save prompt (and with it every dialog here, for one look) is drawn in SwiftUI. enum SetupDialog: Identifiable { case save case confirmNew case confirmDelete(String) case confirmDeleteTheme(String) case confirmRestore case message(title: String, text: String) var id: String { switch self { case .save: return "save" case .confirmNew: return "new" case .confirmDelete(let n): return "delete:" + n case .confirmDeleteTheme(let n): return "theme:" + n case .confirmRestore: return "restore" case .message(let t, let m): return "msg:" + t + m } } } /// A dimmed backdrop with a centred card: title, message, optional text field, buttons. struct SetupDialogView: View { let title: String let message: String? let confirm: String var destructive = false var cancel: String? = "Cancel" var confirmEnabled = true @ViewBuilder let field: () -> Field let onConfirm: () -> Void let onCancel: () -> Void var body: some View { ZStack { Color.black.opacity(0.55).ignoresSafeArea().onTapGesture(perform: onCancel) VStack(alignment: .leading, spacing: 14) { Text(title).font(.system(size: 19, weight: .semibold)).foregroundColor(Theme.text) if let m = message { Text(m).font(.system(size: 14)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true) } field() HStack(spacing: 10) { Spacer() if let c = cancel { SetupButton(title: c, kind: .outlined, action: onCancel) } SetupButton(title: confirm, kind: destructive ? .danger : .filled, enabled: confirmEnabled, action: onConfirm) } } .padding(20) .frame(maxWidth: 420) .background(Theme.surface, in: RoundedRectangle(cornerRadius: 14)) .overlay(RoundedRectangle(cornerRadius: 14).stroke(Theme.grid, lineWidth: 1)) .padding(24) } } }