{"version":3,"file":"AppNavigationContext-VTp01fOg.mjs","names":[],"sources":["../src/shell/AppNavigationContext.tsx"],"sourcesContent":["import { createContext, type ReactNode, use, useMemo } from \"react\";\nimport type { NavigationItem } from \"../types/navigation\";\n\nexport interface AppNavigationContextValue {\n  /** Current active slug (e.g. \"contacts/123\") */\n  currentSlug: string;\n  /**\n   * In-memory referrer. Cleared on popstate and page reload — breadcrumbs\n   * after browser back/forward fall back to the structural parent.\n   */\n  previousSlug: string | null;\n  /** Resolved navigation items (post role-filter, same as what the shell renders) */\n  navItems: NavigationItem[];\n  /** Base path for subpath deployments (e.g. \"/portal\"). Default: \"/\" */\n  basePath: string;\n  /** Navigate to a slug programmatically */\n  navigate: (slug: string) => void;\n  /** Build a full href for a slug (for use in <a> tags) */\n  buildHref: (slug: string) => string;\n}\n\nconst AppNavigationContext = createContext<AppNavigationContextValue | null>(\n  null,\n);\n\nexport interface AppNavigationProviderProps {\n  currentSlug: string;\n  previousSlug: string | null;\n  navItems: NavigationItem[];\n  basePath: string;\n  navigate: (slug: string) => void;\n  children: ReactNode;\n}\n\nexport function AppNavigationProvider({\n  currentSlug,\n  previousSlug,\n  navItems,\n  basePath,\n  navigate,\n  children,\n}: AppNavigationProviderProps): React.JSX.Element {\n  const buildHref = useMemo(() => {\n    return (slug: string) => {\n      if (basePath === \"/\") return `/${slug}`;\n      return `${basePath}/${slug}`;\n    };\n  }, [basePath]);\n\n  const value = useMemo(\n    () => ({\n      currentSlug,\n      previousSlug,\n      navItems,\n      basePath,\n      navigate,\n      buildHref,\n    }),\n    [currentSlug, previousSlug, navItems, basePath, navigate, buildHref],\n  );\n\n  return (\n    <AppNavigationContext.Provider value={value}>\n      {children}\n    </AppNavigationContext.Provider>\n  );\n}\n\nexport function useOptionalAppNavigation(): AppNavigationContextValue | null {\n  return use(AppNavigationContext);\n}\n\nexport function useAppNavigation(): AppNavigationContextValue {\n  const ctx = useOptionalAppNavigation();\n  if (!ctx) {\n    throw new Error(\n      \"useAppNavigation must be used within an <AppShell> or <AppNavigationProvider>\",\n    );\n  }\n  return ctx;\n}\n"],"mappings":";;;AAqBA,MAAM,uBAAuB,cAC3B,KACD;AAWD,SAAgB,sBAAsB,EACpC,aACA,cACA,UACA,UACA,UACA,YACgD;CAChD,MAAM,YAAY,cAAc;AAC9B,UAAQ,SAAiB;AACvB,OAAI,aAAa,IAAK,QAAO,IAAI;AACjC,UAAO,GAAG,SAAS,GAAG;;IAEvB,CAAC,SAAS,CAAC;CAEd,MAAM,QAAQ,eACL;EACL;EACA;EACA;EACA;EACA;EACA;EACD,GACD;EAAC;EAAa;EAAc;EAAU;EAAU;EAAU;EAAU,CACrE;AAED,QACE,oBAAC,qBAAqB,UAAtB;EAAsC;EACnC;EAC6B,CAAA;;AAIpC,SAAgB,2BAA6D;AAC3E,QAAO,IAAI,qBAAqB;;AAGlC,SAAgB,mBAA8C;CAC5D,MAAM,MAAM,0BAA0B;AACtC,KAAI,CAAC,IACH,OAAM,IAAI,MACR,gFACD;AAEH,QAAO"}