/** * edit-surface.ts — SSOT of the « fiche unique » trigger. * * An entity whose view-set carries BOTH `detail` and `form` (and does not opt * out through `editExperience`/`uiDesign.editMode: 'direct'`) gets ONE fiche: * the DetailPage carries the read-first sections that toggle to edit IN PLACE * (« transformer la page en mode édition »), and the FormPage shrinks to * create-only. The `.edit` route then points at the DetailPage (all sections * opened on arrival). * * Deterministic, zero new pagespec field: the surface derives from the * view-set + the existing edit-mode opt-out, so every existing pagespec stays * valid — `detail` without `form` keeps the read-only fiche, `form` without * `detail` keeps the legacy create+edit FormPage, and 'direct' keeps the * legacy pair untouched. * * Imported by scaffold-component AND scaffold-routes (same drift-lock pattern * as lib/pwa-meta.ts) so the page emission and the route registration can * never disagree on which component serves `/edit`. */ export type EditSurface = 'unified' | 'legacy' export function resolveEditSurface( entityViews: Iterable | undefined, editMode: 'read-first' | 'direct', ): EditSurface { const views = new Set(entityViews ?? []) return views.has('detail') && views.has('form') && editMode === 'read-first' ? 'unified' : 'legacy' }