import { UseAuthResult } from './useAuth.js'; import { AuthUser } from '../types/auth.js'; /** * Discriminated status for a scheduling-admin gate. * * - `loading`: auth probe in flight, or /admin/me has not yet resolved. * - `signed_out`: visitor is unauthenticated. * - `not_admin_no_one_claimed`: signed in, but `scheduling_admin_user` is * empty — the consumer should offer a "Claim ownership" CTA. * - `not_admin`: signed in, an admin already exists. Consumer should show * "ask the owner" copy. * - `admin`: signed-in user IS in `scheduling_admin_user` — consumer mounts * the full admin UI. */ type SchedulingAdminGateStatus = 'loading' | 'signed_out' | 'not_admin_no_one_claimed' | 'not_admin' | 'admin'; interface UseSchedulingAdminGateOptions { /** Override the API base path. Default: auto-detect via resolveSchedulingBasePath(). */ apiBase?: string; /** * Reuse an externally-mounted useAuth result. When omitted, the gate calls * useAuth() internally. Pass an explicit value when the consumer's parent * island already mounts useAuth and wants to share state (avoids a second * /session probe + the two hooks getting out of sync). */ auth?: UseAuthResult; /** * If true, skip the initial /admin/me fetch on mount. The consumer drives * via .refresh(). */ skipInitialLoad?: boolean; } interface UseSchedulingAdminGateResult { basePath: string; status: SchedulingAdminGateStatus; /** Convenience: true when status === 'admin'. */ isAdmin: boolean; /** Signed-in user when known. Null otherwise. */ user: AuthUser | null; /** * Total rows in `scheduling_admin_user`. Null until /admin/me has resolved. * Useful when the consumer wants to differentiate "first-run claim" from * "claim a second seat" — the latter doesn't exist in MVP, but the field * is exposed for future-compat. */ totalAdmins: number | null; /** Last /admin/me or /admin/claim error. Cleared on the next successful op. */ error: string | null; /** True while a claim() call is in flight. */ claiming: boolean; /** Re-fetch /admin/me. Useful after a fresh sign-in. */ refresh: () => Promise; /** * POST /admin/claim — server promotes the signed-in user to scheduling * admin when no row exists yet. Refreshes status on success. On failure, * the error is surfaced via `error` and `status` remains the same. */ claim: () => Promise; } declare function useSchedulingAdminGate(opts?: UseSchedulingAdminGateOptions): UseSchedulingAdminGateResult; export { type SchedulingAdminGateStatus, type UseSchedulingAdminGateOptions, type UseSchedulingAdminGateResult, useSchedulingAdminGate };