import type { InjectionKey, Ref } from 'vue' import { computed, inject, provide } from 'vue' // Page-level provide/inject for the public form token. Sibling-endpoint // fetches (time-slots, sections) read it instead of receiving it as a // prop through FieldRenderer, which would couple every renderer to every // new sibling resource. export const PUBLIC_FORM_TOKEN_KEY: InjectionKey> = Symbol('PublicFormToken') export function providePublicFormToken(token: Ref): void { provide(PUBLIC_FORM_TOKEN_KEY, token) } export function usePublicFormToken(): Ref { const token = inject(PUBLIC_FORM_TOKEN_KEY) if (!token) throw new Error('usePublicFormToken: no token provided. Did you forget providePublicFormToken in the page?') return token } // Page-level provide/inject for the active form locale. Used by // option-bearing field renderers (FieldRadio / FieldSelect / // FieldMultiselect / FieldCheckboxList) to resolve per-option // translations[locale] over the default option label (WS-5d §17.6). // Falls back to 'nl' (Crewli's default schema locale) when no provider // is on the tree — keeps standalone component tests light. export const PUBLIC_FORM_LOCALE_KEY: InjectionKey> = Symbol('PublicFormLocale') export function providePublicFormLocale(locale: Ref): void { provide(PUBLIC_FORM_LOCALE_KEY, locale) } export function usePublicFormLocale(): Ref { return inject(PUBLIC_FORM_LOCALE_KEY, computed(() => 'nl')) }