import SwiftUI import BucksleyKit import BucksleyUI struct ContentView: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette @AppStorage(BucksleyTheme.preferenceKey) private var themeRaw = BucksleyTheme.defaultPreference.rawValue var body: some View { HStack(spacing: 0) { Sidebar() .frame(width: 248) .background(palette.sidebar) Rectangle().fill(palette.line).frame(width: 1) detail .frame(maxWidth: .infinity, maxHeight: .infinity) .background(palette.canvas) } .background(palette.canvas) .onChange(of: themeRaw) { _, raw in AppIcon.apply(BucksleyTheme(preference: raw)) } .alert("Bucksley", isPresented: Binding(get: { model.message != nil }, set: { if !$0 { model.message = nil } })) { Button("OK") { model.message = nil } } message: { Text(model.message ?? "") } .modifier(SupportPrompt.Presenter()) } @ViewBuilder var detail: some View { switch model.selection { case .overview: OverviewScreen() case .accounts: AccountsScreen() case .investments: InvestmentsScreen() case .transactions: TransactionsScreen() case .cashFlow: CashFlowScreen() case .categories: CategoriesScreen() case .budgets: BudgetsScreen() case .recurring: RecurringScreen() case .ask: AskScreen() case .agents: AgentsScreen() case .settings: SettingsScreen() } } } struct Sidebar: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette /// Account groups the user folded away, remembered between launches. @AppStorage("sidebar.collapsedGroups") private var collapsedRaw = "" var body: some View { VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 2) { ForEach(Screen.main) { screen in NavRow(screen: screen, badge: screen == .transactions && model.reviewCount > 0 ? "\(model.reviewCount)" : nil) } } .padding(.horizontal, 10).padding(.top, 12) // The header stays put; only the accounts under it scroll. if !model.ledger.visibleAccounts.isEmpty { Text("MY ACCOUNTS") .font(.system(size: 10.5, weight: .bold)).tracking(1) .foregroundStyle(palette.muted) .accessibilityAddTraits(.isHeader) .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 16).padding(.top, 22).padding(.bottom, 6) } ScrollView { VStack(alignment: .leading, spacing: 14) { ForEach(AccountGroup.allCases, id: \.self) { group in let accounts = model.ledger.visibleAccounts.filter { $0.kind.group == group } if !accounts.isEmpty { accountGroup(group, accounts) } } } .padding(.horizontal, 16).padding(.top, 2).padding(.bottom, 8) } .frame(maxHeight: .infinity) VStack(alignment: .leading, spacing: 2) { NavRow(screen: .agents, badge: nil) NavRow(screen: .settings, badge: nil) } .padding(.horizontal, 10) HStack(spacing: 6) { Image(systemName: "lock.shield").font(.system(size: 11)) Text(syncLine).font(palette.theme == .almanac ? .system(size: 11, design: .serif).italic() : .system(size: 11)).lineLimit(2) Spacer() Button { Task { await model.syncBanks() } } label: { Image(systemName: "arrow.clockwise").rotationEffect(.degrees(model.syncing ? 360 : 0)) .animation(model.syncing ? .linear(duration: 1).repeatForever(autoreverses: false) : .default, value: model.syncing) } .buttonStyle(.plain).help("Sync banks now (⌘R)").accessibilityLabel("Sync banks now") } .foregroundStyle(palette.muted) .padding(16) } } var collapsed: Set { Set(collapsedRaw.split(separator: ",").map(String.init)) } func toggle(_ group: AccountGroup) { var set = collapsed if set.contains(group.rawValue) { set.remove(group.rawValue) } else { set.insert(group.rawValue) } collapsedRaw = set.sorted().joined(separator: ",") } func accountGroup(_ group: AccountGroup, _ accounts: [Account]) -> some View { let open = !collapsed.contains(group.rawValue) return VStack(alignment: .leading, spacing: 2) { Button { withAnimation(.snappy(duration: 0.2)) { toggle(group) } } label: { HStack(spacing: 5) { Text(group.title) .font(palette.theme == .almanac ? .system(size: 13, design: .serif).italic() : .system(size: 12, weight: .semibold)) Image(systemName: "chevron.down") .font(.system(size: 8.5, weight: .bold)) .rotationEffect(.degrees(open ? 0 : -90)) Spacer() MoneyText(model.ledger.total(group), size: 11, cents: false) } .foregroundStyle(palette.muted) .padding(.vertical, 4) .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel("\(group.title) accounts") .accessibilityValue(open ? "Expanded" : "Collapsed") .accessibilityIdentifier("sidebar.group.\(group.rawValue)") if open { ForEach(accounts) { account in SidebarAccountRow(account: account) } } } } var syncLine: String { guard let last = model.workspace.settings.lastSyncAt else { return "Read-only. Bucksley never moves money." } return "Read-only. Synced \(last.formatted(.relative(presentation: .named)))." } } struct SidebarAccountRow: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette @State private var hovering = false let account: Account var body: some View { Button { model.selection = .accounts } label: { HStack(spacing: 9) { Circle().fill(palette.color(for: account)).frame(width: 7, height: 7) Text(account.displayName).font(.system(size: 12.5)).lineLimit(1) Spacer(minLength: 6) MoneyText(account.balance, size: 12, cents: false, weight: .regular) } .padding(.horizontal, 8).padding(.vertical, 6) .background(hovering ? palette.text.opacity(palette.dark ? 0.07 : 0.05) : .clear, in: RoundedRectangle(cornerRadius: 7, style: .continuous)) .contentShape(Rectangle()) } .buttonStyle(.plain) .padding(.horizontal, -8) .onHover { hovering = $0 } .help("\(account.institution) · \(account.kind.title)") } } struct NavRow: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette @State private var hovering = false let screen: Screen let badge: String? var body: some View { let on = model.selection == screen Button { model.selection = screen } label: { HStack(spacing: 10) { let answerer = AskBucksley.answerer(AskBucksley.provider(for: model.workspace.settings)) NavIcon(symbol: screen.symbol, color: screen.colorIndex.map { palette.color($0) } ?? palette.muted, selected: on, provider: screen == .ask ? answerer : nil) Text(screen == .ask ? AskBucksley.title(for: answerer) : screen.title).font(.system(size: 13, weight: on ? .semibold : .medium)) Spacer() if let badge { Text(badge).font(.system(size: 10, weight: .bold)).padding(.horizontal, 6).padding(.vertical, 2) .foregroundStyle(on && palette.theme != .evergreen ? palette.accent : palette.accentText) .background(on && palette.theme != .evergreen ? palette.accentText : palette.accent, in: Capsule()) } } .padding(.leading, 6).padding(.trailing, 10).padding(.vertical, 5) .foregroundStyle(foreground(on)) .background(background(on), in: RoundedRectangle(cornerRadius: palette.theme == .evergreen ? 8 : 999, style: .continuous)) .contentShape(Rectangle()) } .buttonStyle(.plain) .onHover { hovering = $0 } .animation(.easeOut(duration: 0.12), value: hovering) .accessibilityAddTraits(on ? .isSelected : []) .accessibilityIdentifier("nav.\(screen.title)") } func foreground(_ on: Bool) -> Color { guard on else { return palette.text } switch palette.theme { case .afterhours: return palette.accentText; case .evergreen: return palette.accent; case .almanac: return palette.canvas } } func background(_ on: Bool) -> Color { guard on else { return hovering ? palette.text.opacity(palette.dark ? 0.07 : 0.05) : .clear } switch palette.theme { case .afterhours: return palette.accent; case .evergreen: return palette.accent.opacity(0.14); case .almanac: return palette.text } } } /// The colored tile behind each sidebar icon, tinted from the theme's own chart colors so every /// theme keeps its character. On a filled selection it turns into a quiet glass tile. struct NavIcon: View { @Environment(\.palette) private var palette let symbol: String let color: Color let selected: Bool /// Ask shows the mark of whoever answers instead of a symbol. var provider: AskProvider? = nil var body: some View { let onFill = selected && palette.theme != .evergreen let ink = onFill ? (palette.theme == .almanac ? palette.canvas : palette.accentText) : color Group { if let provider { ProviderMark(provider, size: 13, tint: onFill ? ink : (provider == .apple || provider == .claude || provider == .claudeCode ? nil : palette.text)) } else { Image(systemName: symbol).font(.system(size: 11.5, weight: .semibold)).foregroundStyle(ink) } } .frame(width: 24, height: 24) .background(onFill ? Color.white.opacity(palette.theme == .almanac ? 0.14 : 0.2) : color.opacity(palette.dark ? 0.2 : 0.14), in: RoundedRectangle(cornerRadius: palette.theme == .almanac ? 5 : 7, style: .continuous)) } } /// Every screen's frame: a title row with optional controls, then scrolling content. struct ScreenScaffold: View { @Environment(\.palette) private var palette @Environment(AppModel.self) private var model let title: String var subtitle: String? var provider: AskProvider? let controls: Controls let content: Content init(_ title: String, subtitle: String? = nil, provider: AskProvider? = nil, @ViewBuilder controls: () -> Controls = { EmptyView() }, @ViewBuilder content: () -> Content) { self.title = title; self.subtitle = subtitle; self.provider = provider; self.controls = controls(); self.content = content() } var body: some View { VStack(spacing: 0) { HStack(alignment: .center, spacing: 12) { VStack(alignment: .leading, spacing: 2) { HStack(spacing: 9) { if let provider { ProviderMark(provider, size: 20, tint: provider == .apple || provider == .claude || provider == .claudeCode ? nil : palette.text) } Text(title).font(palette.title(24)).tracking(palette.titleTracking) } if let subtitle { Text(subtitle).font(palette.theme == .almanac ? .system(size: 13, design: .serif).italic() : .system(size: 12)).foregroundStyle(palette.muted) } } Spacer() controls } .padding(.horizontal, 28).padding(.top, 22).padding(.bottom, 14) ScrollView { VStack(alignment: .leading, spacing: 0) { content } .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 28).padding(.bottom, 28) } .defaultScrollAnchor(model.tourAnchor ?? (model.tourScrolledToEnd ? .bottom : .top)) .id("\(model.tourScrolledToEnd)\(model.tourAnchor.map { "\($0.y)" } ?? "")") } } } /// Shown on screens that need data before there is any. struct ConnectFirst: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette var body: some View { Panel(padding: 24) { VStack(alignment: .leading, spacing: 12) { Text("Connect your first account").font(palette.title(18)) Text("Bucksley reads balances and transactions with your own SimpleFIN Bridge or Plaid keys, or a CSV export from another money app. Everything stays on this Mac and in your private iCloud. Bucksley never moves money.") .font(.system(size: 13)).foregroundStyle(palette.muted).fixedSize(horizontal: false, vertical: true) HStack { Button("Connect a bank") { model.selection = .settings }.buttonStyle(PrimaryButtonStyle()) Button("Import a CSV") { model.selection = .settings; model.wantsCSVImport = true }.buttonStyle(SecondaryButtonStyle()) } } } } }