// Search finds the device and database pages (UI direction, Cotton note// 0a22168c §3): a page whose name, or one of whose columns' names, holds the// typed words joins Find's places rail beside the tools, and picking it opens// that page — "notif" finds This phone's Notifications, "colour" the// database's Cap colour.//// The words are the pages' OWN, read from their definitions (`device.json`'s// columns on this device's row, `database.json`'s), so there is no second// list of settings to keep in step with what the pages draw.importCottonKitimportFoundationenumPageFind {staticlet keyPrefix = "page-"staticlet icon = "settings-2"/// One place: the words it is found by and the page it opens.structPlace: Equatable, Sendable {let key: Stringlet label: Stringlet route: Route }/// The device page's and the database page's places, each page first by/// its own name, then its columns by theirs.staticfunc places(_ definitions: TableDefinitions) -> [Place] {var places = [Place(key: "device", label: HostNoun.titleCase, route: .device)]iflet device = definitions["device"] { places += device.columns .filter { $0.shownWhen?.values == ["this device"] } .compactMap { column in column.name.map { Place(key: "device-\(column.key)", label: $0, route: .device) } } } places.append(Place(key: "database", label: ShellLines.line("search", "place.database"), route: .database))iflet database = definitions["database"] { places += database.columns.compactMap { column in column.name.map { Place(key: "database-\(column.key)", label: $0, route: .database) } } }return places }/// The places whose label holds `needle` (already lower-cased), as chips.staticfunc chips(matching needle: String, in places: [Place]) -> [SearchPlaceChip] { places.filter { $0.label.lowercased().contains(needle) }.map { place inSearchPlaceChip( key: keyPrefix + place.key, label: place.label, icon: icon, tool: FindTool(key: keyPrefix + place.key, name: place.label, icon: icon, path: place.route.path)) } }}