// // SettingsPaneView.swift // Museion // // #17 (S1.1): Settings — the Museion Home path, repoint-only (ADR-0004). // #135 (Profiles S2): reworked to the #130 prototype's variant C verdict — // a Settings sidebar + detail column (System Settings shape): destinations // Content · Pass 1 · Pass 2 · Chat · Provider Keys. Content keeps the #17 // Home control unchanged; the surface and keys pages live in // SettingsPagesView.swift over the in-memory SettingsModel (persistence is // S3's job — the write-path protocol is the seam). // import AppKit import SwiftUI /// Settings pane — sidebar + detail per prototype variant C. struct SettingsPaneView: View { @Binding var home: URL @State private var page: SettingsPage = .content /// #135: in-memory model, pane-local until S3 lifts persistence in. @State private var model = SettingsModel() var body: some View { VStack(spacing: 0) { PaneHeader(title: "Settings") if let error = model.lastWriteError { Text(error) .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(.orange) .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 14) .padding(.vertical, 4) } HStack(spacing: 0) { sidebar Rectangle() .fill(DesignTokens.border) .frame(width: 1) detail } } .background(DesignTokens.background) } // MARK: Sidebar (prototype `.vC .side`) private var sidebar: some View { VStack(alignment: .leading, spacing: 2) { ForEach(SettingsPage.allCases) { candidate in SettingsSidebarButton( page: candidate, selection: $page, ) } Spacer(minLength: 0) } .padding(.horizontal, 8) .padding(.vertical, 14) .frame(width: DesignTokens.settingsSidebarWidth) } // MARK: Detail (prototype `.vC .detail`) private var detail: some View { ScrollView { switch page { case .content: ContentSettingsPage(home: $home) case .pass1: SurfaceSettingsPage(model: model, surface: .pass1) case .pass2: SurfaceSettingsPage(model: model, surface: .pass2) case .chat: SurfaceSettingsPage(model: model, surface: .chat) case .keys: ProviderKeysPage(model: model) } } .frame(maxWidth: .infinity, maxHeight: .infinity) } } /// The sidebar's destinations (#135): the #17 Content control, one page per /// LLM surface (Sessions rides Chat — #126), and the provider keys. enum SettingsPage: String, CaseIterable, Identifiable, Hashable { case content case pass1 case pass2 case chat case keys var id: String { rawValue } var label: String { switch self { case .content: "Content" case .pass1: "Pass 1" case .pass2: "Pass 2" case .chat: "Chat" case .keys: "Provider Keys" } } /// The prototype's trailing mono annotation: pass chips + the Sessions /// note on Chat (the chat row notes "Sessions rides this engine"). var annotation: String? { switch self { case .pass1: "P1" case .pass2: "P2" case .chat: "· Sessions" default: nil } } } /// One sidebar row (prototype `.vC .side-button`): quiet label, trailing /// mono annotation, surface card + inset accent bar when current. private struct SettingsSidebarButton: View { let page: SettingsPage @Binding var selection: SettingsPage @State private var hover = false var body: some View { let selected = selection == page Button { selection = page } label: { HStack(spacing: 8) { Text(page.label) .foregroundStyle(DesignTokens.foreground) Spacer(minLength: 0) if let annotation = page.annotation { Text(annotation) .font(.system(size: 10, design: DesignTokens.mono)) .foregroundStyle(DesignTokens.muted) } } .padding(.horizontal, 10) .padding(.vertical, 7) .frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) } .buttonStyle(.plain) .background { if selected || hover { RoundedRectangle(cornerRadius: 8) .fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06)) } } .overlay(alignment: .leading) { // `.side-button.current` inset accent bar. if selected { RoundedRectangle(cornerRadius: 1) .fill(DesignTokens.accent) .frame(width: 2) .padding(.vertical, 4) } } .onHover { hover = $0 } .accessibilityLabel(page.label) .accessibilityAddTraits(selected ? [.isSelected] : []) } } /// The Content page: the existing #17 Home control, repoint-only, in the /// variant C form (quiet label, mono path, Choose…). private struct ContentSettingsPage: View { @Binding var home: URL var body: some View { VStack(alignment: .leading, spacing: 4) { Text("Content") .font(.system(size: 16, weight: .semibold, design: DesignTokens.serif)) Text("Where the corpus lives.") .font(.system(size: 12)) .foregroundStyle(DesignTokens.muted) VStack(alignment: .leading, spacing: 14) { VStack(alignment: .leading, spacing: 4) { SettingsFieldLabel("Museion Home") HStack(spacing: 8) { Text(home.path(percentEncoded: false)) .font(.system(size: 12, design: DesignTokens.mono)) .lineLimit(1) .truncationMode(.middle) .textSelection(.enabled) Spacer(minLength: 12) Button("Choose…") { chooseHome() } .buttonStyle(.bordered) } } Text("Repoint-only: Museion never moves content.") .font(.system(size: 11.5)) .foregroundStyle(DesignTokens.muted) } .padding(.top, 12) } .frame(maxWidth: DesignTokens.settingsFormWidth, alignment: .leading) .padding(.horizontal, 26) .padding(.top, 18) .padding(.bottom, 48) } private func chooseHome() { let panel = NSOpenPanel() panel.canChooseDirectories = true panel.canChooseFiles = false panel.canCreateDirectories = true panel.message = "Choose the folder holding your posts. Museion never moves content." if panel.runModal() == .OK, let url = panel.url { home = url } } }