{"version":3,"file":"useDrawer.js","names":[],"sources":["esm/headless/useDrawer.js"],"sourcesContent":["\"use client\";\nimport {\n  DrawerActions\n} from \"@react-navigation/routers\";\nimport {\n  createContext,\n  useContext,\n  useMemo\n} from \"react\";\nimport { getPathFromState } from \"../fork/getPathFromState\";\nimport { getResolvedLinking } from \"../router/linkingConfig\";\nimport { jsx } from \"react/jsx-runtime\";\nconst DrawerContext = createContext(null);\nfunction DrawerStateProvider({\n  state,\n  descriptors,\n  navigation,\n  children\n}) {\n  const linking = getResolvedLinking();\n  const value = useMemo(() => {\n    const screens = state.routes.map((route, index) => {\n      const descriptor = descriptors[route.key];\n      const options = descriptor.options;\n      const href = (linking?.getPathFromState ?? getPathFromState)(\n        { ...state, index },\n        linking?.config\n      );\n      return {\n        key: route.key,\n        name: route.name,\n        params: route.params ?? {},\n        href,\n        isFocused: index === state.index,\n        keepMounted: options.keepMounted === true,\n        options,\n        element: descriptor.render()\n      };\n    });\n    return {\n      screens,\n      focused: screens[state.index],\n      isOpen: state.history.some((entry) => entry.type === \"drawer\"),\n      open: () => navigation.dispatch(DrawerActions.openDrawer()),\n      close: () => navigation.dispatch(DrawerActions.closeDrawer()),\n      toggle: () => navigation.dispatch(DrawerActions.toggleDrawer())\n    };\n  }, [descriptors, linking, navigation, state]);\n  return /* @__PURE__ */ jsx(DrawerContext.Provider, { value, children });\n}\nfunction useDrawer() {\n  const value = useContext(DrawerContext);\n  if (!value) {\n    throw new Error(\"useDrawer must be used inside a Drawer navigator\");\n  }\n  return value;\n}\nexport {\n  DrawerStateProvider,\n  useDrawer\n};\n//# sourceMappingURL=useDrawer.js.map\n"],"mappings":";;;;;;;;;AAYA,MAAM,gBAAgB,cAAc,IAAI;AACxC,SAAS,oBAAoB,EAC3B,OACA,aACA,YACA,YACC;CACD,MAAM,UAAU,mBAAmB;CACnC,MAAM,QAAQ,cAAc;EAC1B,MAAM,UAAU,MAAM,OAAO,KAAK,OAAO,UAAU;GACjD,MAAM,aAAa,YAAY,MAAM;GACrC,MAAM,UAAU,WAAW;GAC3B,MAAM,QAAQ,SAAS,oBAAoB,iBAAgB,CACzD;IAAE,GAAG;IAAO;GAAM,GAClB,SAAS,MACX;GACA,OAAO;IACL,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,QAAQ,MAAM,UAAU,CAAC;IACzB;IACA,WAAW,UAAU,MAAM;IAC3B,aAAa,QAAQ,gBAAgB;IACrC;IACA,SAAS,WAAW,OAAO;GAC7B;EACF,CAAC;EACD,OAAO;GACL;GACA,SAAS,QAAQ,MAAM;GACvB,QAAQ,MAAM,QAAQ,MAAM,UAAU,MAAM,SAAS,QAAQ;GAC7D,YAAY,WAAW,SAAS,cAAc,WAAW,CAAC;GAC1D,aAAa,WAAW,SAAS,cAAc,YAAY,CAAC;GAC5D,cAAc,WAAW,SAAS,cAAc,aAAa,CAAC;EAChE;CACF,GAAG;EAAC;EAAa;EAAS;EAAY;CAAK,CAAC;CAC5C,OAAuB,oBAAI,cAAc,UAAU;EAAE;EAAO;CAAS,CAAC;AACxE;AACA,SAAS,YAAY;CACnB,MAAM,QAAQ,WAAW,aAAa;CACtC,IAAI,CAAC,OAAO;EACV,MAAM,IAAI,MAAM,kDAAkD;CACpE;CACA,OAAO;AACT"}