{"version":3,"file":"RouteGuard.cjs","names":[],"sources":["../../src/router/RouteGuard.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport { Navigate } from \"react-router\";\nimport type { RouteGuardResult } from \"./types\";\n\nexport interface RouteGuardProps {\n    /**\n     * Whether access is allowed — typically\n     * `useAuthStore((s) => s.isAuthenticated)`.\n     *\n     * `\"pending\"` is the third answer, for a permission that has not resolved\n     * yet: it holds the decision and renders {@link fallback} instead of\n     * choosing between two wrong moves — redirecting someone who does have\n     * access, or showing the screen to someone who does not.\n     */\n    when: RouteGuardResult;\n    /**\n     * Rendered while `when` is `\"pending\"`. Defaults to nothing, which is a\n     * blank screen — pass the same spinner the rest of the app uses.\n     */\n    fallback?: ReactNode;\n    /** Where to redirect when `when` is falsy (default: `\"/\"`). */\n    redirectTo?: string;\n    /** Replace history entry on redirect instead of pushing (default: true). */\n    replace?: boolean;\n    /** Protected content, usually `<Outlet />` for a guarded layout route. */\n    children: ReactNode;\n}\n\n/**\n * Declarative route guard built on React Router's `<Navigate>`. Renders its\n * children when `when` is `true`, redirects when it is `false`, and holds on\n * `\"pending\"`. Pairs naturally with `createAuthStore` for protected areas, and\n * with `useCan` for permissions that resolve over the network.\n *\n * @example\n * <RouteGuard when={useAuthStore((s) => s.isAuthenticated)} redirectTo=\"/login\">\n *     <Outlet />\n * </RouteGuard>\n *\n * @example\n * const { allowed, isLoading } = useCan({ action: \"read\", resource: \"finance\" });\n *\n * <RouteGuard when={isLoading ? \"pending\" : allowed} fallback={<Spinner />}>\n *     <Outlet />\n * </RouteGuard>\n */\nexport function RouteGuard({\n    when,\n    fallback = null,\n    redirectTo = \"/\",\n    replace = true,\n    children,\n}: RouteGuardProps) {\n    if (when === \"pending\") return <>{fallback}</>;\n    return <>{when ? children : <Navigate to={redirectTo} replace={replace} />}</>;\n}\n"],"mappings":"6DA8CA,SAAgB,EAAW,CACvB,OACA,WAAW,KACX,aAAa,IACb,UAAU,GACV,YACgB,CAEhB,OADI,IAAS,WAAkB,EAAA,EAAA,IAAA,CAAA,EAAA,SAAA,CAAA,SAAG,CAAW,CAAA,GACtC,EAAA,EAAA,IAAA,CAAA,EAAA,SAAA,CAAA,SAAG,EAAO,GAAW,EAAA,EAAA,IAAA,CAAC,EAAA,SAAD,CAAU,GAAI,EAAqB,SAAU,CAAA,CAAI,CAAA,CACjF"}