Cotton code
661 lines · 32.1 KB · SwiftRaw
// DAYS' ROOT in the Blue pen look (assets/design/days/DECISIONS.md): the// whole app, mounted by the root in place of the fan and the board// (`RootView.hosts`), as Cotton Story and Cotton Vault are. Two places: Days// opens on today; the two-word switch at the foot goes to Sometime and back;// "+" adds; "more" at the top is settings. Every sheet stands over Days and a// swipe down closes it. As Android's `DaysSurface.kt`.#if os(iOS)import CottonKitimport SwiftUIstruct DaysRoot: View {    /// Cotton Days' own build.    static var applies: Bool { FlavourManifest.current?.flavour == "days" }    @State private var model: DaysModel    @State private var adding: DaysAdding    @Environment(\.cottonSync) private var sync    @Environment(\.scenePhase) private var phase    /// The app went to the background since it was last in front.    @State private var away = false    @Environment(\.openURL) private var openURL    /// Google's consent page, held while it is up.    @State private var googleSignIn = DaysGoogleSignIn()    @Environment(\.nativeKeptFlow) private var nativeFlow    @Environment(\.rekeyThisDevice) private var rekey    @Environment(\.cottonNotifications) private var notifications    /// Leave to notify, asked by the core at the moment an item first earns a reminder.    @State private var leave: DaysLeaveAsking    init(core: any CottonCalling) {        let leave = DaysLeaveAsking()        _leave = State(initialValue: leave)        let book = CoreDaysBook(core: core, onLeave: { asked in Task { @MainActor in leave.asking = asked } })        _model = State(initialValue: DaysModel(book: book, core: core))        _adding = State(initialValue: DaysAdding(core: core))    }    /// A model made elsewhere (a look, a test).    init(model: DaysModel) {        _leave = State(initialValue: DaysLeaveAsking())        _model = State(initialValue: model)        _adding = State(initialValue: DaysAdding(core: model.core))    }    var body: some View {        VStack(spacing: 0) {            top            // Where sync stands, in one quiet line (SyncSeenLine); a tap opens Settings on Sync.            SyncSeenLine(font: PenType.small, color: Pen.quiet) {                SyncSeenOpens.ask()                withAnimation(.easeOut(duration: 0.2)) { model.settingsOpen = true }            }            .padding(.horizontal, Pen.side)            .frame(maxWidth: .infinity, alignment: .leading)            // Both places stand, the one not chosen hidden, so each keeps its            // place when the other is chosen (DECISIONS: switching between            // Days and Sometime keeps each one's place). Making the list again            // on every switch opened it on today each time.            ZStack {                DaysListView(model: model, acts: acts, onConnect: model.google?.connect == nil ? nil : { model.askToConnect() })                    .standing(model.view == nil && model.place == .days)                DaysSometimeView(model: model, acts: acts)                    .standing(model.view == nil && model.place == .sometime)                // A view chosen on Show stands in place of the days.                if model.view != nil { DaysViewList(model: model) }            }            .frame(maxWidth: .infinity, maxHeight: .infinity)        }        .background(Pen.sheet.ignoresSafeArea())        // Look (shared/DECISIONS.md "Look"): every screen in the paper, ink, face and size chosen.        .lookStanding(LookModel.standing("days"))        .task { await LookModel.standing("days").read(model.core) }        .safeAreaInset(edge: .bottom, spacing: 0) { foot }        .overlay {            if model.settingsOpen {                DaysSettingsPage(model: model)                    .transition(.move(edge: .trailing))            }        }        .overlay {            if model.finding {                DaysFindPage(model: model)                    .transition(.opacity)            }        }        .animation(.easeOut(duration: 0.18), value: model.finding)        // Dictation's reason before the phone is asked, or Open Settings after it refused; Not now beside either        // (voice control.*, store pass, 24 Nov 2026).        .overlay {            if let dictation = adding.dictation, let ask = dictation.ask {                let words = dictation.askWords(ask)                PenNoticeCard(words: words.line, notNow: words.notNow, go: words.go, tag: "voice-ask",                              onGo: { Task { await dictation.goOn(ask) } },                              onDismiss: { dictation.notNow() })                    .transition(.opacity)            }        }        // Leave to notify (DECISIONS "Alerts"): why first, in the core's words, then iOS asks on Continue; Not now        // spends the moment too. Never at launch: only after an add, a change or a move gave an item its first alert.        .overlay {            if let asked = leave.asking {                PenNoticeCard(title: asked.title, words: asked.body, notNow: asked.notNow, go: asked.go, tag: "days-leave",                              onGo: {                                  leave.asking = nil                                  Task { await notifications?.answerAsk(allow: true) }                              },                              onDismiss: {                                  leave.asking = nil                                  Task { await notifications?.answerAsk(allow: false) }                              })                    .transition(.opacity)            }        }        .animation(.easeOut(duration: 0.18), value: leave.asking)        // Disconnect asks first, with its one yes; a tap outside is the way out.        .overlay {            if let disconnect = model.disconnecting {                PenNoticeCard(words: disconnect.asks, go: disconnect.yes, tag: "days-google-disconnect",                              onGo: {                                  model.disconnecting = nil                                  Task { await model.disconnectGoogle(disconnect.account) }                              },                              onDismiss: { model.disconnecting = nil })                    .transition(.opacity)            }        }        .animation(.easeOut(duration: 0.18), value: model.noticing)        .animation(.easeOut(duration: 0.18), value: model.disconnecting)        // Google Calendar as the core says it: asked on every change (and so when Days opens).        // What waits for Google or for someone on Cotton goes after a sync, at most once a minute (§16, §17).        .task(id: sync?.revision) {            await model.readGoogle()            await model.sendAway(unlessWithin: 60)        }        // A row landed on from search is marked a moment, then let be.        .task(id: model.marked) {            guard model.marked != nil else { return }            try? await Task.sleep(for: .seconds(1.6))            model.marked = nil        }        .lookPanel(item: $model.sheet, style: Pen.panel, tall: true) { sheet in            switch sheet {            case .jump(let month, let pick):                DaysJumpSheet(model: model, start: month) { day in                    model.sheet = nil                    if let pick { pick(day) } else { Task { await model.jump(day) } }                }            case .change(let row): DaysChangeSheet(model: model, row: row)            case .when(let now, let set): DaysWhenSheet(model: model, now: now) { pick in                model.sheet = nil                set(pick)            }            case .groups: DaysGroupsSheet(model: model)            }        }        // The notice before Google's page (GOOGLE.md §4): Not now asks nothing; Continue to Google runs the act.        // Over the change sheet too: Connect from a sheet Google refused keeps the sheet and what was typed (§16).        .overlay {            if let connect = model.noticing {                PenNoticeCard(title: connect.notice.title, words: connect.notice.body, notNow: connect.notice.notNow,                              go: connect.notice.go, tag: "days-google",                              onGo: { model.noticing = nil; run(connect) },                              onDismiss: { model.noticing = nil })                    .transition(.opacity)            }        }        .task(id: model.said) {            guard model.said != nil else { return }            try? await Task.sleep(for: .seconds(5))            model.said = nil            model.undo = nil            model.actWords = nil        }        .task {            PenFonts.register()            #if COTTON_DEV            await DaysLook.prepare(model)            #endif            await model.read()            // The first content is read: the splash goes now, never at the            // launch's ceiling (launch-fast, 20 Nov 2026).            FanLaunch.firstContent()            // Settings draws whole on its first frame from the list last read; a phone with none yet reads it now.            Task { await SettingsHome.warm(model.core) }            #if COTTON_DEV            DaysLook.open(model, adding: adding)            #endif        }        // The app's one keyboard rule (Chrome/KeyboardDismissal.swift): a        // drag down or a tap outside a field puts the keyboard away, on Days,        // Sometime and every panel. Days wore none, so the keyboard stood        // over the list until the adding bar was closed (DaysKeyboardTests).        .cottonScreenFrame()        // Another device or Claude wrote: read again.        .onChange(of: sync?.foreignRevision) { _, _ in Task { await model.read() } }        // Back from the background (it comes back through inactive): the        // list is opened again, tidied. A pull of the shade is not away.        .onChange(of: phase) { _, now in            if now == .background { away = true }            if now == .active && away {                away = false                Task { await model.tidy() }            }            // Back from Google's page (or anywhere): Google is asked again.            // Coming to the front, what waits goes (§16, §17).            if now == .active {                Task {                    await model.readGoogle()                    await model.sendAway()                }            }        }    }    private var acts: DaysRowActs {        let model = model        return DaysRowActs(            tick: { model.tick($0) },            open: { row in if row.recordId != nil || row.whose == .birthday { model.sheet = .change(row) } })    }    /// The filter by group at the top left of Days and Sometime ("All" or the    /// group's name), "more" at the right of Days: settings.    private var top: some View {        HStack {            Button { model.sheet = .groups } label: {                HStack(spacing: 4) {                    Text(model.filterWords).lineLimit(1)                    Text(verbatim: "▾").font(PenType.mono(10, relativeTo: .caption2))                }                .font(PenType.small)                .foregroundStyle(model.group == nil && model.view == nil ? Pen.quiet : Pen.pen)                .padding(.horizontal, 12)                .frame(minHeight: 44)                .contentShape(Rectangle())            }            .buttonStyle(PenPress())            .accessibilityLabel(DaysWords.line("a11y.filter", ["name": model.filterWords]))            Spacer()            // Search, beside "more" (DECISIONS, 21 Nov 2026).            Button { model.finding = true } label: {                PenMagnifier()                    .frame(width: 17, height: 17)                    .foregroundStyle(Pen.quiet)                    .frame(width: 44, height: 44)                    .contentShape(Rectangle())            }            .buttonStyle(PenPress())            .accessibilityLabel(DaysWords.line("a11y.search"))            if model.place == .days {                Button { withAnimation(.easeOut(duration: 0.2)) { model.settingsOpen = true } } label: {                    Text(DaysWords.line("nav.more"))                        .font(PenType.small)                        .foregroundStyle(Pen.quiet)                        .padding(.horizontal, 12)                        .frame(minHeight: 44)                        .contentShape(Rectangle())                }                .buttonStyle(PenPress())                .accessibilityLabel(DaysWords.line("a11y.more"))            }        }        .frame(minHeight: 44)        .padding(.horizontal, Pen.side - 12)    }    /// The foot: what was just said, then the two-word switch with "+" at its right; the adding bar over both.    private var foot: some View {        VStack(spacing: 0) {            if let said = model.said {                HStack(spacing: 8) {                    Text(said).font(PenType.small).foregroundStyle(Pen.quiet)                        .frame(maxWidth: .infinity, alignment: .leading)                    if let undo = model.undo {                        Button {                            model.said = nil                            model.undo = nil                            model.actWords = nil                            Task { await undo() }                        } label: {                            Text(model.actWords ?? DaysWords.line("row.undo")).font(PenType.small).foregroundStyle(Pen.pen)                                .padding(.horizontal, 8).frame(minHeight: 44).contentShape(Rectangle())                        }                        .buttonStyle(PenPress())                    }                }                .padding(.horizontal, Pen.side)                .accessibilityElement(children: .contain)                .accessibilityAddTraits(.updatesFrequently)            }            if model.adding {                DaysAddBar(model: model, adding: adding)            } else {                switcher            }        }        .animation(.easeOut(duration: 0.2), value: model.todayShown)        .background(Pen.sheet.ignoresSafeArea(edges: .bottom))    }    /// `.nav` and `.fab`: "Days  Sometime", the one standing in ink, and the pen "+" at the right.    private var switcher: some View {        ZStack {            HStack(spacing: 26) {                ForEach(DaysPlace.allCases, id: \.self) { place in                    let on = model.place == place                    Button {                        // "Days" tapped while Days stands: back to today.                        if place == .days && model.place == .days { model.backToToday() } else { model.open(place) }                    } label: {                        Text(DaysWords.line(place == .days ? "nav.days" : "nav.sometime"))                            .font(on ? PenType.navOn : PenType.nav)                            .foregroundStyle(on ? Pen.ink : Pen.faint)                            .frame(minHeight: 44)                            .contentShape(Rectangle())                    }                    .buttonStyle(PenPress())                    .accessibilityAddTraits(on ? .isSelected : [])                    .accessibilityShowsLargeContentViewer()                }            }            // A switch held at the largest size below the accessibility sizes,            // as the system's own tab bars are (a long press shows it large):            // at the largest text "Sometime" ran under the "+" (launch-ios walk,            // 22 Nov 2026).            .dynamicTypeSize(...DaysKnobs.switchLargest)            HStack {                // Back to today, mirroring the "+": only while today is off screen.                if model.place == .days && model.known && !model.todayShown {                    PenToday(number: String(model.clock.calendar.dayOfMonth(model.today))) { model.backToToday() }                        .transition(.opacity)                }                Spacer()                PenPlus { model.adding = true }            }        }        .padding(.horizontal, 18)        .padding(.top, 6)        .padding(.bottom, 8)    }    /// Continue to Google: the Calendar tool's own act (`tools.act`), its consent page opened in the system's    /// sign-in sheet, which brings Google's answer back to Days (`DaysGoogleSignIn`); Safari where it cannot.    private func run(_ connect: DaysGoogle.Connect) {        let act = CardAction(id: connect.id, label: connect.label, kind: "tool", tool: connect.tool)        guard let core = model.core else { return }        Task {            await model.attempt {                switch try await DeckActs.ran(act, core: core) {                case .opens(let page):                    switch await googleSignIn.open(page) {                    case nil: openURL(page)                    case .refused(let words): model.tell(words); await model.readGoogle()                    case .connected, .closed: await model.readGoogle()                    }                case .platform(let effect): await RecordPlatformEffects.perform(effect, nativeFlow: nativeFlow, rekey: rekey)                case .said(let words), .receipt(let words, _): model.tell(words)                case .document(_, let said): if let said { model.tell(said) }                case .nothing: break                }            }        }    }}/// SETTINGS, behind "more" at the top of Days (not drawn in pen.html: drawn/// here in its language, QUESTIONS.md, as Android's `Settings.kt`). The/// groups as Sometime draws them: an uppercase quiet heading with its dotted/// rule, plain rows and capsules under. Account shows the person's name with/// the number small beneath, from the core's account answer.extension View {    /// One of the two places, standing chosen or hidden (and then out of    /// reach of touch and of the screen reader), never made again.    func standing(_ chosen: Bool) -> some View {        opacity(chosen ? 1 : 0)            // The chosen one in front: the hidden one, drawn over it, stood            // in the way of every touch and of the screen reader's reach.            .zIndex(chosen ? 1 : 0)            .allowsHitTesting(chosen)            // Hidden, its rows are no elements at all: hiding alone left            // them readable under the chosen one.            .accessibilityElement(children: chosen ? .contain : .ignore)            .accessibilityHidden(!chosen)    }}struct DaysSettingsPage: View {    @Bindable var model: DaysModel    /// The list and the page standing (SettingsGrouped.swift; shared/DECISIONS.md "Organised as Comms' You"):    /// the card, Days' own rows (Google calendars, Week starts on), Sync and Your Claude, Privacy, Notifications    /// (Alerts, and the phone's own settings) and Storage, then Help and feedback and About.    @State private var home = SettingsHome()    @Environment(\.cottonSync) private var sync    var body: some View {        VStack(alignment: .leading, spacing: 0) {            Button { home.back { withAnimation(.easeOut(duration: 0.2)) { model.settingsOpen = false } } } label: {                Text("‹ " + DaysWords.line("settings.close"))                    .font(PenType.small).foregroundStyle(Pen.quiet)                    .frame(minHeight: 44).contentShape(Rectangle())            }            .buttonStyle(PenPress())            .accessibilityLabel(DaysWords.line("settings.close"))            .accessibilityIdentifier("days-settings-back")            .padding(.horizontal, Pen.side)            ScrollView {                VStack(alignment: .leading, spacing: 0) {                    Text(home.title(own: ownTitle) ?? DaysWords.line("settings.title"))                        .font(PenType.month).foregroundStyle(Pen.ink)                        .fixedSize(horizontal: false, vertical: true)                        .padding(.top, 6).padding(.bottom, 10)                        .accessibilityAddTraits(.isHeader)                    page                }                .padding(.horizontal, Pen.side)                .padding(.bottom, 28)                .accessibilityElement(children: .contain)                .accessibilityIdentifier("settings-page-\(home.place?.id ?? "top")")            }            .scrollIndicators(.hidden)            .id(home.place)        }        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)        .background(Pen.sheet.ignoresSafeArea())        .task(id: sync?.revision) { await home.read(model.core) }    }    @ViewBuilder    private var page: some View {        switch home.place {        case nil:            SettingsHomeList(home: home, look: .days, own: own) {                SettingsYouCard(home: home, core: model.core, look: .days) { model.tell($0) }            }        case .profile?:            SettingsProfileHead(home: home, look: .days)            SettingsProfileFoot(home: home, core: model.core, look: .days, said: { model.tell($0) }) {                model.settingsOpen = false                model.backToToday()            }        case .own("look")?:            DaysLookPage(model: model)        case .own("calendars")?:            // Which Google account is connected, how its events are coming, Connect or Disconnect (CONTRACT §13).            DaysGoogleGroup(model: model, home: home)        case .own("week")?:            Text(DaysWords.line("settings.week_line")).font(PenType.small).foregroundStyle(Pen.quiet)                .fixedSize(horizontal: false, vertical: true)                .padding(.bottom, 10)            PenFlow(spacing: 8, lineSpacing: 8) {                PenChip(words: DaysWords.line("settings.monday"), on: model.settings.weekStart == 1) { model.settings.weekStart = 1 }                PenChip(words: DaysWords.line("settings.sunday"), on: model.settings.weekStart == 7) { model.settings.weekStart = 7 }            }        case .own("export")?:            DaysExportPage(model: model)        case .own?:            EmptyView()        case .notifications?:            // What Days tells, Alerts (how long before an event), then the phone's own settings with On or Off.            Text(DaysWords.line("settings.notifications_line")).font(PenType.small).foregroundStyle(Pen.quiet)                .fixedSize(horizontal: false, vertical: true)            PenGroupHeading(name: DaysWords.line("settings.alerts"))            Text(DaysWords.line("settings.alerts_line")).font(PenType.small).foregroundStyle(Pen.quiet)                .fixedSize(horizontal: false, vertical: true)                .padding(.top, 8).padding(.bottom, 10)            PenFlow(spacing: 8, lineSpacing: 8) {                ForEach([5, 10, 30, 60], id: \.self) { n in                    PenChip(words: DaysWords.line("change.alert_before", ["n": String(n)]), on: model.settings.alert == n) { model.settings.alert = n }                        .accessibilityIdentifier("days-alert-\(n)")                }            }            Spacer().frame(height: 18)            SettingsPhoneNotifications(home: home, look: .days)        case let shared?:            SettingsSharedPage(place: shared, home: home, core: model.core, look: .days, said: { model.tell($0) }) {                Task { await home.read(model.core) }            }        }    }    /// Days' own rows, each saying how it stands.    private var own: [SettingsOwnRow] {        let google = model.google?.accounts.map(\.email).joined(separator: ", ")        let look = LookModel.standing("days").answer        return [            SettingsOwnRow(id: "look", label: look?.word("title") ?? "", line: look?.line),            SettingsOwnRow(id: "calendars", label: DaysWords.line("settings.calendars"),                           line: google.flatMap { $0.isEmpty ? nil : $0 } ?? DaysWords.line("settings.calendars_none")),            SettingsOwnRow(id: "week", label: DaysWords.line("settings.week"),                           line: DaysWords.line(model.settings.weekStart == 7 ? "settings.sunday" : "settings.monday")),            // Export (CONTRACT.md §19): everything, or one group's to-dos, as a calendar file to share.            SettingsOwnRow(id: "export", label: DaysWords.line("export.title"), line: DaysWords.line("export.hint")),        ]    }    private func ownTitle(_ id: String) -> String? {        // Export's page says what it makes ("Export as a calendar file"), as Android's.        if id == "export" { return DaysWords.line("export.sheet") }        return own.first { $0.id == id }?.label    }}@MainActorextension SettingsLook {    /// The shared settings parts in Days' pen: its dotted group headings,    /// mono words, capsule buttons and chips.    static var days: SettingsLook {        SettingsLook(            ink: Pen.ink, quiet: Pen.quiet, rule: Pen.rule.opacity(0.5), ground: Pen.sheet,            body: PenType.words, small: PenType.small,            heading: { AnyView(PenGroupHeading(name: $0)) },            act: { words, id, enabled, tap in                AnyView(PenButton(words: words, tap: tap).disabled(!enabled).opacity(enabled ? 1 : 0.4).accessibilityIdentifier(id))            },            choice: { words, on, id, enabled, tap in                AnyView(PenChip(words: words, on: on, tap: tap).disabled(!enabled).accessibilityIdentifier(id))            },            // Days has one accent and no red: its danger is said in ink.            danger: Pen.ink,            title: PenType.month        )    }}#if COTTON_DEV/// A look on a simulator opens a screen by name: `-days-open/// sometime|adding|when|jump|change|todo|google|settings|groups|first|past|ahead|filtered`.@MainActorenum DaysLook {    static var asked: String? { UserDefaults.standard.string(forKey: "days-open") }    /// The made-up days and the words a look types into Add are a bundled file    /// (`Resources/Fixtures/days-dev-seed.json`), so no English a person reads    /// is a Swift literal (as Vault's and Story's seeds).    private struct Invented: Decodable {        struct Made: Decodable { let words: String; let day: Int?; let time: String?; let mark: String? }        struct Grouped: Decodable { let name: String; let of: [String] }        let made: [Made]        let adding: String        /// Made-up to-do groups (two of one name, to show them as one).        let groups: [Grouped]?    }    private static let invented: Invented? = fixture("days-dev-seed")    /// `-days-crowd YES`: the crowd for the long-list checks    /// (`days-crowd.json`, sixty-four invented to-dos on today and sixty-four    /// in Sometime), written after the seed's own rows.    static var crowd: Bool { UserDefaults.standard.bool(forKey: "days-crowd") }    private struct Crowd: Decodable { let made: [Invented.Made] }    private static let crowded: Crowd? = fixture("days-crowd")    private static func fixture<T: Decodable>(_ name: String) -> T? {        guard let url = Bundle.module.url(forResource: name, withExtension: "json", subdirectory: "Fixtures"),              let data = try? Data(contentsOf: url) else { return nil }        return try? JSONDecoder().decode(T.self, from: data)    }    /// Before the first read of a look (not "first", which wants the empty    /// day): made-up days written through the core's own `days.add` into    /// this dev build's local database, once, when today holds nothing.    /// Never the owner's data: a look runs on a fresh simulator, signed out.    static func prepare(_ model: DaysModel) async {        // A look starts from All unless it is the filtered one (the choice is otherwise remembered).        if (asked != nil || crowd) && asked != "filtered" { model.group = nil; model.view = nil }        guard asked != nil || crowd, asked != "first" else { return }        let cal = model.clock.calendar        let t = model.today        guard let span = try? await model.book.span(from: t, to: t),              span.days.allSatisfy({ if case .day(let d) = $0 { d.rows.isEmpty } else { true } }) else { return }        guard let invented = invented else { return }        let made: [(String, String??, String?, String?)] = (invented.made + (crowd ? crowded?.made ?? [] : [])).map { row in            (row.words, .some(row.day.map { cal.adding($0, to: t) }), row.time, row.mark)        }        var ids: [String: String] = [:]        // Invented rows are no one's act: written through the book with no ear for leave to notify, so the card        // comes only at a person's first alert, never at a development build's launch.        var book: any DaysBook = model.book        if var core = book as? CoreDaysBook { core.onLeave = nil; book = core }        for (words, day, time, mark) in made {            let added = try? await book.add(words, where: day == .some(nil) ? "sometime" : "days", dayInView: t,                                                  day: day, time: time, mark: mark)            if let added, added.table == "todo" { ids[words] = added.id }        }        guard let core = model.core else { return }        for group in invented.groups ?? [] {            _ = try? await core.callJSON("groups.create", JSONValue.days(["table": "todo", "name": group.name, "records": group.of.compactMap { ids[$0] }]))        }    }    static func open(_ model: DaysModel, adding: DaysAdding) {        guard let open = asked else { return }        let today = model.days.compactMap { if case .day(let d) = $0, d.today { d } else { nil } }.first        switch open {        case "sometime": model.place = .sometime        case "adding":            model.adding = true            adding.words = invented?.adding ?? ""        case "jump": model.sheet = .jump(month: String(model.today.prefix(7)), pick: nil)        case "change": if let row = today?.rows.first(where: { $0.whose == .yours && $0.kind == .event }) { model.sheet = .change(row) }        case "todo": if let row = today?.rows.first(where: { $0.kind == .todo }) { model.sheet = .change(row) }        case "google": if let row = today?.rows.first(where: { $0.whose == .google }) { model.sheet = .change(row) }        case "settings": model.settingsOpen = true        case "groups": model.sheet = .groups        case "filtered": if let last = model.groupChoices?.groups.last { model.filter(last) }        case "when":            model.adding = true            adding.words = invented?.adding ?? ""            model.sheet = .when(DaysPillPick(day: model.clock.calendar.adding(6, to: model.today), time: "19:00")) { [adding] in adding.picked = $0 }        case "past": model.jumpTo = model.clock.calendar.adding(-1, to: model.today)        case "ahead": Task { await model.jump(model.clock.calendar.adding(12, to: model.today)) }        default: break        }    }}#endif/// Days' sizes that are rules, not looks.enum DaysKnobs {    /// The largest text the Days · Sometime switch is drawn at: the largest    /// below the accessibility sizes, so it never runs under the "+".    static let switchLargest = DynamicTypeSize.xxxLarge    /// The least a day header's weekday or month is drawn at, as a share of    /// its size, so each stays one whole word.    static let dayWordLeast: CGFloat = 0.5    /// How far above the screen's foot the shell's line stands: where Days' own line stands, over the switch.    static let toastAboveFoot: CGFloat = 66}/// The shell's passing line (an approval, a sync failure, a sealed key) in Days' own toast (`AppToast`): the foot's/// line, in the pen's small type and quiet ink on the sheet, standing where Days' own line stands above the switch,/// with Undo in the pen when the line carries one.struct DaysToast: View {    let toast: CottonToast    let onUndo: () -> Void    let onDismiss: () -> Void    var body: some View {        HStack(spacing: 8) {            Text(toast.message).font(PenType.small).foregroundStyle(Pen.quiet)                .lineLimit(AppToastView.lineLimit(toast.tone))                .fixedSize(horizontal: false, vertical: true)                .frame(maxWidth: .infinity, alignment: .leading)            if toast.undo != nil {                Button(action: onUndo) {                    Text(DaysWords.line("row.undo")).font(PenType.small).foregroundStyle(Pen.pen)                        .padding(.horizontal, 8).frame(minHeight: 44).contentShape(Rectangle())                }                .buttonStyle(PenPress())            }        }        .frame(minHeight: 44)        .padding(.horizontal, Pen.side)        .background(Pen.sheet)        .onTapGesture(perform: onDismiss)        .padding(.bottom, DaysKnobs.toastAboveFoot)        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)    }}#endif