// DAYS' EXPORT ON IPHONE (days CONTRACT.md §19 "Export"; owner, 23 Nov 2026, promised on the website for launch). // Settings → Export: the core writes the person's events and to-dos as an .ics (`days.export`: everything, or one // group's to-dos); the phone offers it and hands the file to the share sheet, as Words' export does. Nothing is // decided here; a refusal is said in the core's words at the page's foot. #if os(iOS) import CottonKit import SwiftUI struct DaysExportPage: View { @Bindable var model: DaysModel @State private var working = false @State private var refused: String? var body: some View { VStack(alignment: .leading, spacing: 8) { Text(DaysWords.line("export.hint")).font(PenType.small).foregroundStyle(Pen.quiet) .fixedSize(horizontal: false, vertical: true) .padding(.bottom, 10) PenButton(words: DaysWords.line("export.all"), go: true) { export(nil) } .accessibilityIdentifier("days-export-all") Text(DaysWords.line("export.all_line")).font(PenType.small).foregroundStyle(Pen.quiet) let groups = model.groupChoices?.groups ?? [] if !groups.isEmpty { ForEach(groups) { group in PenButton(words: group.name) { export(group.id) } .accessibilityIdentifier("days-export-\(group.id)") } .padding(.top, 10) Text(DaysWords.line("export.group_line")).font(PenType.small).foregroundStyle(Pen.quiet) } if let refused { Text(refused).font(PenType.small).foregroundStyle(Pen.ink) .fixedSize(horizontal: false, vertical: true) .padding(.top, 14) .accessibilityIdentifier("days-export-refused") } } .opacity(working ? 0.5 : 1) .accessibilityElement(children: .contain) .accessibilityIdentifier("settings-page-export") .task { if model.groupChoices == nil { model.groupChoices = try? await model.book.groups() } } } /// Everything (`group` nil) or one group's to-dos, written by the core in the phone's zone, to the share sheet. private func export(_ group: String?) { guard !working, let core = model.core else { return } working = true refused = nil Task { defer { working = false } var ask: [String: JSONValue] = ["timezone": .string(TimeZone.current.identifier)] if let group { ask["group"] = .string(group) } do { let made = try await core.callJSON("days.export", JSONValue.object(ask)) guard let path = made["path"]?.string else { return } ShareSheet.present(URL(fileURLWithPath: path)) } catch { refused = ActionRefused.words(for: error) } } } } #endif