// Keys a long list of things the owner keeps reads, each drawn once for any// table that names it (Photos was the first: the library's "all · photos ·// videos", its months counted "40 photos · 2 videos" with "No date" last, the// Select that deletes several pictures after one question, the menu's// Albums, Duplicates and People to confirm with their counts and the red "3// to review", and an album the owner said "not this" to never listed)://// * `filter` — a row of typed words over the list, one per value of one// column, narrowing the list through its `where`;// * `count_words` — how a count of records is said, by one column's value;// * `months` — `by_month` drawn however short the list, the undated last// under their own heading;// * `hidden` — records never listed;// * `select` and `deletion` — the list's Select, and the words Delete asks// with (the page's too), the size it frees, and whether it can be undone;// * `links` — other lists the list's menu opens, each with its count.//// The reading lives here, pure, so the words and the order are settled by// tests; `RecordListSurface` only draws them.importCottonKitimportCottonValuesimportFoundation/// A row of typed words narrowing a list by one column's value.publictypealiasListFilter = DefinitionListFilterextensionDefinitionListFilter {publicinit(column: String, all: String, words: [String: String], order: [String]? = nil, empty: [String: EmptyWords] = [:], tabs: Bool = true) {self.init(_generated: (), column: column)self.tabs = tabsself.all = allself.words = wordsself.order = orderself.empty = empty }}/// How a count of records is said: each value of `column` with its own/// units ("1 photo", "2 videos"), joined; a value with no units is counted/// as the table's plural.publictypealiasCountWords = DefinitionCountWordsextensionDefinitionCountWords {publicinit(column: String, units: [String: ColumnUnits], order: [String]? = nil) {self.init(_generated: (), column: column, units: units)self.order = order }}/// When `by_month` splits the list: over how many records (absent: a dozen,/// and only over more than one month), and the heading over the undated.publictypealiasListMonthsLayout = DefinitionListMonthsextensionDefinitionListMonths {publicinit(over: Int? = nil, undated: String? = nil) {self.init(_generated: ())self.over = overself.undated = undated }}/// The list's Select: the menu offers it, ticks the records, and the trash/// deletes them after one question (`deletion`).publictypealiasListSelect = DefinitionListSelectextensionDefinitionListSelect {publicinit(verb: DefinitionSelectVerb = .delete) {self.init(_generated: ())self.verb = verb }}/// The words Delete asks with: the sentence under the question for one/// record and for several, the column whose bytes it frees, whether the/// receipt can take it back, and the two buttons.publictypealiasDeletionWords = DefinitionDeletionWordsextensionDefinitionDeletionWords {publicinit( one: String? = nil, other: String? = nil, size: String? = nil, undo: Bool = true, confirm: String = "Delete", cancel: String? = nil, label: String? = nil, asks: Bool = true, bin: Bool = false ) {self.init(_generated: ())self.one = oneself.other = otherself.size = sizeself.undo = undoself.confirm = confirmself.cancel = cancelself.label = labelself.asks = asksself.bin = bin }}/// A line of a list's menu that opens an app screen, uncounted — the Tools/// screen's Settings (Spec 9.1).publictypealiasMenuLine = DefinitionMenuLineextensionDefinitionMenuLine {publicinit(label: String, path: String) { self.init(_generated: (), label: label, path: path) }}/// Another list the list opens ("Albums · 2 suggested"): the table it counts,/// narrowed by `where` (a value, or an array of values meaning any of them)./// With a `path` (an app route) it is a line of the list's menu. With none it/// is a LIST LINK: drawn on the list itself — alone under the list's records/// when it `lead`s, else in the row of links after its sections — and it opens/// the table's own list narrowed by `where` (`FilteredListOpening`). A table/// this build has no definition for, or a count of none where `hides_empty`,/// is not offered./// Where a list's row of link tiles stands: after its first `after` records.publictypealiasLinkTiles = DefinitionLinkTilesextensionDefinitionLinkTiles {publicinit(after: Int) { self.init(_generated: (), after: after) }}publictypealiasListLink = DefinitionListLinkextensionDefinitionListLink {publicinit( label: String, table: String, where filter: [String: RecordValue] = [:], words: String? = nil, path: String? = nil, lead: Bool = false, above: Bool = false, review: Bool = false, hidesEmpty: Bool = false ) {self.init(_generated: (), label: label, table: table)self.where = filterself.words = wordsself.path = pathself.lead = leadself.above = aboveself.review = reviewself.hidesEmpty = hidesEmpty }publicvar isListLink: Bool { path == nil }/// The link with its count, as the core says it: in the definition's/// units when it has them, else `lists.link.count` ("Senders · 12"). @MainActorpublicfunc line(count: Int?) -> String {guardlet count, count > 0else { return label }iflet units { returnCountLines.shared.units(units, n: count) ?? label }iflet words {returnCountLines.shared.line("lists", "link.count_words", n: count, fills: ["label": label, "words": words]) ?? label }returnCountLines.shared.line("lists", "link.count", n: count, fills: ["label": label]) ?? label }publicstaticfunc shows(count: Int?, takesAdd: Bool) -> Bool {guardlet count else { returnfalse }return count > 0 || takesAdd }}extensionTableDefinition {/// Whether the table's list takes an add of its own — its bar writes a/// record there, or it has a "+" — so a link to it is offered even while/// it holds none (R12).publicvar takesAdd: Bool { listTakesCapture || create != nil }/// The values the filter row offers, in order, each with its word.publicvar filterValues: [(value: String, word: String)] {guardlet filter else { return [] }let order = filter.order ?? column(filter.column)?.choices ?? filter.words.keys.sorted()return order.compactMap { value in filter.words[value].map { (value, $0) } } }/// Whether a record is never listed (`hidden`).publicfunc isHidden(_ record: TableRecord) -> Bool {guardlet hidden, let value = record[hidden.column].text else { returnfalse }return hidden.values.contains(value) }/// What this table's delete act is called — in the page's menu, a slip's/// long press, Select and the question: its `deletion.label` ("Remove"),/// else "Delete".publicvar deleteWord: String { deletion?.label ?? "Delete" }/// What the act did, said after it: "deleted" for Delete, "removed" for/// any other word.publicvar deletedWord: String { deleteWord == "Delete" ? "deleted" : "removed" }/// What the list's Select says after deleting: "3 deleted", or, when some/// were refused, "1 of 4 could not be deleted — still selected, so you/// can try again."publicstaticfunc selectOutcome(deleted: Int, failed: Int, verb: String = ShellLines.line("definitions", "select.deleted")) -> String {guard failed > 0else { returnShellLines.line("definitions", "select.outcome", ["n": String(deleted), "verb": verb]) }let total = deleted + failedreturnShellLines.line("definitions", "select.outcome_failed", ["failed": String(failed), "total": String(total), "verb": verb]) }}