{
  "version": 3,
  "sources": ["../src/index.ts", "../src/context/Provider.tsx", "../src/context/context.ts", "../src/context/reducer.ts", "../src/event/event.ts"],
  "sourcesContent": ["export * from './context';\nexport * from './event';\n", "import {\n  type FC,\n  Fragment,\n  type PropsWithChildren,\n  useCallback,\n  useReducer,\n  useState,\n} from 'react';\n\nimport { generateID } from '@quotalab/headless-hooks';\n\nimport {\n  OverlayContextProvider,\n  type OverlayContextValue,\n  type OverlayControllerProps,\n  useOverlayContext,\n} from './context';\nimport { type OverlayReducerState, overlayReducer } from './reducer';\nimport { useOverlayEvent } from '../event/event';\n\nexport function OverlayProvider({ children }: PropsWithChildren<unknown>) {\n  const [overlayState, overlayDispatch] = useReducer(overlayReducer, {\n    overlayList: [],\n    current: null,\n  } satisfies OverlayReducerState);\n\n  const open: OverlayContextValue['open'] = useCallback((controller) => {\n    const overlayId = generateID('quotalab-overlay');\n    overlayDispatch({\n      type: 'OPEN',\n      overlay: {\n        id: overlayId,\n        children: <ContentOverlayController overlayId={overlayId} controller={controller} />,\n      },\n    });\n\n    return overlayId;\n  }, []);\n  const close: OverlayContextValue['close'] = useCallback((id: string) => {\n    overlayDispatch({ type: 'CLOSE', overlayId: id });\n  }, []);\n  const closeAll: OverlayContextValue['closeAll'] = useCallback(() => {\n    overlayDispatch({ type: 'CLOSE_ALL' });\n  }, []);\n\n  useOverlayEvent({ open, close, closeAll });\n\n  const contextValue: OverlayContextValue = {\n    overlayList: overlayState.overlayList,\n    open,\n    close,\n    closeAll,\n  };\n\n  return (\n    <OverlayContextProvider value={contextValue}>\n      {children}\n      {overlayState.overlayList.map((item) => {\n        return <Fragment key={item.id}>{item.children}</Fragment>;\n      })}\n    </OverlayContextProvider>\n  );\n}\n\ntype ContentOverlayControllerProps = {\n  overlayId: string;\n  controller: FC<OverlayControllerProps>;\n};\n\nfunction ContentOverlayController({\n  controller: Controller,\n  overlayId,\n}: ContentOverlayControllerProps) {\n  const [isOpen, setOpen] = useState(true);\n  const { close } = useOverlayContext();\n\n  return (\n    <Controller\n      overlayId={overlayId}\n      isOpen={isOpen}\n      onClose={() => {\n        setOpen(false);\n        setTimeout(() => close(overlayId), 100);\n      }}\n    />\n  );\n}\n", "import { type FC, type ReactNode } from 'react';\n\nimport { createSafeContext } from '@quotalab/headless-hooks';\n\nexport type OverlayProps = { overlayId: string };\n\nexport type OverlayItem = { id: string; children: ReactNode };\n\nexport type OverlayControllerProps = OverlayProps & {\n  isOpen: boolean;\n  onClose: () => void;\n};\n\nexport type OverlayContextValue = {\n  overlayList: OverlayItem[];\n  open: (value: FC<OverlayControllerProps>) => string;\n  close: (id: string) => void;\n  closeAll: () => void;\n};\n\nexport const [OverlayContextProvider, useOverlayContext] = createSafeContext<OverlayContextValue>(\n  '@quotalab/overlay/OverlayContext'\n);\n", "import { type OverlayItem } from './context';\n\nexport type OverlayReducerState = {\n  overlayList: OverlayItem[];\n  current: OverlayItem | null;\n};\n\nexport type OverlayReducerAction =\n  | { type: 'OPEN'; overlay: OverlayItem }\n  | { type: 'CLOSE'; overlayId: string }\n  | { type: 'CLOSE_ALL' };\n\nexport function overlayReducer(\n  state: OverlayReducerState,\n  action: OverlayReducerAction\n): OverlayReducerState {\n  switch (action.type) {\n    case 'OPEN': {\n      return {\n        current: action.overlay,\n        overlayList: [...state.overlayList, action.overlay],\n      };\n    }\n    case 'CLOSE': {\n      const remainingOverlays = state.overlayList.filter((item) => item.id !== action.overlayId);\n      if (state.overlayList.length === remainingOverlays.length) return state;\n\n      return {\n        current: remainingOverlays[remainingOverlays.length - 1] || state.current,\n        overlayList: remainingOverlays,\n      };\n    }\n    case 'CLOSE_ALL': {\n      if (state.overlayList.length === 0) return state;\n\n      return {\n        current: state.current,\n        overlayList: [],\n      };\n    }\n  }\n}\n", "import { createCustomEvent } from '@quotalab/headless-hooks';\n\nimport { type OverlayContextValue } from '../context/context';\n\ntype OverlayEvent = Omit<OverlayContextValue, 'overlayList'>;\n\nexport const [useOverlayEvent, createEvent] = createCustomEvent<OverlayEvent>('quotalab-overlay');\n\nconst open = createEvent('open');\nconst close = createEvent('close');\nconst closeAll = createEvent('closeAll');\n\nexport const overlays = { open, close, closeAll };\n"],
  "mappings": ";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,aAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAL,GCAA,IAAAM,EAOO,iBAEPC,EAA2B,oCCP3B,IAAAC,EAAkC,oCAkBrB,CAACC,EAAwBC,CAAiB,KAAI,qBACzD,kCACF,ECVO,SAASC,EACdC,EACAC,EACqB,CACrB,OAAQA,EAAO,KAAM,CACnB,IAAK,OACH,MAAO,CACL,QAASA,EAAO,QAChB,YAAa,CAAC,GAAGD,EAAM,YAAaC,EAAO,OAAO,CACpD,EAEF,IAAK,QAAS,CACZ,IAAMC,EAAoBF,EAAM,YAAY,OAAQG,GAASA,EAAK,KAAOF,EAAO,SAAS,EACzF,OAAID,EAAM,YAAY,SAAWE,EAAkB,OAAeF,EAE3D,CACL,QAASE,EAAkBA,EAAkB,OAAS,CAAC,GAAKF,EAAM,QAClE,YAAaE,CACf,CACF,CACA,IAAK,YACH,OAAIF,EAAM,YAAY,SAAW,EAAUA,EAEpC,CACL,QAASA,EAAM,QACf,YAAa,CAAC,CAChB,CAEJ,CACF,CCzCA,IAAAI,EAAkC,oCAMrB,CAACC,EAAiBC,CAAW,KAAI,qBAAgC,kBAAkB,EAE1FC,EAAOD,EAAY,MAAM,EACzBE,EAAQF,EAAY,OAAO,EAC3BG,EAAWH,EAAY,UAAU,EAE1BI,EAAW,CAAE,KAAAH,EAAM,MAAAC,EAAO,SAAAC,CAAS,EHoB9B,IAAAE,EAAA,6BAZX,SAASC,EAAgB,CAAE,SAAAC,CAAS,EAA+B,CACxE,GAAM,CAACC,EAAcC,CAAe,KAAI,cAAWC,EAAgB,CACjE,YAAa,CAAC,EACd,QAAS,IACX,CAA+B,EAEzBC,KAAoC,eAAaC,GAAe,CACpE,IAAMC,KAAY,cAAW,kBAAkB,EAC/C,OAAAJ,EAAgB,CACd,KAAM,OACN,QAAS,CACP,GAAII,EACJ,YAAU,OAACC,EAAA,CAAyB,UAAWD,EAAW,WAAYD,EAAY,CACpF,CACF,CAAC,EAEMC,CACT,EAAG,CAAC,CAAC,EACCE,KAAsC,eAAaC,GAAe,CACtEP,EAAgB,CAAE,KAAM,QAAS,UAAWO,CAAG,CAAC,CAClD,EAAG,CAAC,CAAC,EACCC,KAA4C,eAAY,IAAM,CAClER,EAAgB,CAAE,KAAM,WAAY,CAAC,CACvC,EAAG,CAAC,CAAC,EAELS,EAAgB,CAAE,KAAAP,EAAM,MAAAI,EAAO,SAAAE,CAAS,CAAC,EAEzC,IAAME,EAAoC,CACxC,YAAaX,EAAa,YAC1B,KAAAG,EACA,MAAAI,EACA,SAAAE,CACF,EAEA,SACE,QAACG,EAAA,CAAuB,MAAOD,EAC5B,UAAAZ,EACAC,EAAa,YAAY,IAAKa,MACtB,OAAC,YAAwB,SAAAA,EAAK,UAAfA,EAAK,EAAmB,CAC/C,GACH,CAEJ,CAOA,SAASP,EAAyB,CAChC,WAAYQ,EACZ,UAAAT,CACF,EAAkC,CAChC,GAAM,CAACU,EAAQC,CAAO,KAAI,YAAS,EAAI,EACjC,CAAE,MAAAT,CAAM,EAAIU,EAAkB,EAEpC,SACE,OAACH,EAAA,CACC,UAAWT,EACX,OAAQU,EACR,QAAS,IAAM,CACbC,EAAQ,EAAK,EACb,WAAW,IAAMT,EAAMF,CAAS,EAAG,GAAG,CACxC,EACF,CAEJ",
  "names": ["src_exports", "__export", "OverlayProvider", "overlays", "useOverlayContext", "__toCommonJS", "import_react", "import_headless_hooks", "import_headless_hooks", "OverlayContextProvider", "useOverlayContext", "overlayReducer", "state", "action", "remainingOverlays", "item", "import_headless_hooks", "useOverlayEvent", "createEvent", "open", "close", "closeAll", "overlays", "import_jsx_runtime", "OverlayProvider", "children", "overlayState", "overlayDispatch", "overlayReducer", "open", "controller", "overlayId", "ContentOverlayController", "close", "id", "closeAll", "useOverlayEvent", "contextValue", "OverlayContextProvider", "item", "Controller", "isOpen", "setOpen", "useOverlayContext"]
}
