// ONE DOOR TO A RECORD (door row 13). Every place that opens a record, or a // blank one to write, comes through here: a conversation opens its chat (its // photos and files alone when asked for them), every other record opens its // table's deck at its card, and a blank one opens that deck on its blank card // — or the camera, where the record is all one photo (`ShotCreate`). The deck // of cards is the whole UI (owner, 23 Oct 2026): every shipped table carries // a card (package 467cdb694), a kind with no face of its own is drawn plain // (`PlainFace`), and a table the owner made with no card at all stands on the // plain card too (`DeckCard.plain`). There is no old record page. import CottonKit import CottonValues import SwiftUI struct RecordOpening: View { enum Opens { /// A record, by id, with the row already read when there is one. case record(String, TableRecord?) /// A record not yet written, holding these values. case blank([String: RecordValue]) } /// Where an opening lands. enum Lands: Equatable { /// The thread's own chat (`ConversationRoute`), narrowed to its /// photos and files when `media`. case conversation(media: Bool) /// The table's deck, at the record's card or on its blank card. case deck /// The camera at once: a blank whose record is all one photo /// (`TableDefinition.onePhoto`) is the shot, never a card to type on. case camera(column: String) } let definition: TableDefinition let opens: Opens /// The deck a record opens in stays inside these values. var within: [String: RecordValue] = [:] var anchor: String? = nil var mediaOnly = false var body: some View { switch (opens, Self.lands(definition, opens: opens, mediaOnly: mediaOnly)) { case (.record(let id, _), .conversation(let media)): ConversationRoute(table: definition.id, id: id, anchor: anchor, mediaOnly: media) case (.record(let id, _), _): DeckSurface(definition: definition, filter: within, view: nil, opensAt: id, lands: true) case (.blank(let preset), .camera(let key)): if let column = definition.column(key) { ShotCreate(definition: definition, column: column, preset: preset) } case (.blank(let preset), _): // The blank stands on the view the core names (`lands`). The // create's dated column is the new record's start, never what the // deck reads: a stored instant never equals a bare day, and the // record made would stand on a deck that hides it. let dated = definition.create?.dated DeckSurface(definition: definition, filter: preset.filter { $0.key != dated }, view: nil, composesOnArrival: true, blank: preset, lands: true) } } /// Where `opens` lands for `definition`: a thread's chat, a one-photo /// blank's camera, else its deck — never anywhere else. static func lands(_ definition: TableDefinition, opens: Opens, mediaOnly: Bool = false) -> Lands { switch opens { case .record where definition.drawsConversation: return .conversation(media: mediaOnly) case .blank(let preset): let blank = TableRecord(id: "", values: definition.newDefaults.merging(preset) { _, given in given }) if let photo = definition.onePhoto(of: blank) { return .camera(column: photo.key) } return .deck case .record: return .deck } } }