import type { ReactNode } from 'react'; /** * Unique handle assigned to each registered guard. Returned from `register` * so callers can `unregister` themselves on unmount or when the guard * condition no longer applies. */ export type GuardId = string; export interface GuardRegistration { /** * When `true`, navigation through the guard-aware layer will be intercepted * and the confirmation modal will be shown. */ isBlocked: () => boolean; /** * Called once the user confirms navigation. Use this to reset form state * (e.g. restore a snapshot) before navigation proceeds. */ onConfirm: () => void; /** * Optional summary of this guard's unsaved changes, rendered inside the * confirmation modal while the guard is blocking. */ renderDetails?: () => ReactNode; } export interface UnsavedChangesGuardContextValue { register: (registration: GuardRegistration) => GuardId; unregister: (id: GuardId) => void; /** * Runs `proceed` immediately when no guards are blocking. Otherwise opens * the confirmation modal and runs `proceed` only when the user confirms. */ requestNavigation: (proceed: () => void) => void; } export interface UnsavedChangesGuardProps { children: ReactNode; } export interface PendingNavigation { proceed: () => void; /** Blocking guards' change summaries, captured when the navigation was intercepted. */ changeSummary: ReactNode; }