{"version":3,"file":"toastContext.cjs","sources":["../../../../src/components/toast/toastContext.tsx"],"sourcesContent":["import { ToastQueue } from \"@react-stately/toast\";\nimport React, { createContext, useContext, useState, type FC } from \"react\";\nimport { ToastRegion } from \"./ToastRegion.js\";\nimport type {\n    ToastContent,\n    ToastContext,\n    ToastContextProviderProps,\n    ToastOptions,\n} from \"./types.js\";\n\nconst context = createContext<ToastContext>({\n    add: () => {\n        return \"missing-provider\";\n    },\n    close: () => {},\n});\n\nexport const useToast = (): ToastContext => useContext(context);\n\nexport const ToastProvider: FC<ToastContextProviderProps> = ({\n    children,\n    maxVisibleToasts = 5,\n    placement = \"center\",\n}) => {\n    const [queue] = useState(\n        new ToastQueue<ToastContent>({\n            maxVisibleToasts,\n            hasExitAnimation: true,\n        }),\n    );\n\n    return (\n        <context.Provider\n            value={{\n                close: queue.close.bind(queue),\n                add: (toast: ToastContent, options?: ToastOptions) => {\n                    let timeout: number | undefined = 5000;\n\n                    if (typeof options?.timeout === \"number\") {\n                        timeout = options.timeout as number;\n                    } else if (\n                        options?.timeout === null ||\n                        options?.timeout === \"off\"\n                    ) {\n                        timeout = undefined;\n                    }\n\n                    return queue.add(toast, {\n                        ...options,\n                        timeout,\n                    });\n                },\n            }}\n        >\n            {children}\n            <ToastRegion queue={queue} placement={placement} />\n        </context.Provider>\n    );\n};\n"],"names":["context","createContext","add","close","children","maxVisibleToasts","placement","queue","useState","ToastQueue","hasExitAnimation","jsxs","Provider","value","bind","toast","options","timeout","jsx","ToastRegion","useContext"],"mappings":"yMAUMA,EAAUC,EAAAA,cAA4B,CACxCC,IAAK,IACM,mBAEXC,MAAO,+BAKiD,EACxDC,SAAAA,EACAC,iBAAAA,EAAmB,EACnBC,UAAAA,EAAY,aAEZ,MAAOC,GAASC,EAAAA,SACZ,IAAIC,aAAyB,CACzBJ,iBAAAA,EACAK,kBAAkB,KAI1B,OACIC,EAAAA,KAACX,EAAQY,SAAR,CACGC,MAAO,CACHV,MAAOI,EAAMJ,MAAMW,KAAKP,GACxBL,IAAK,CAACa,EAAqBC,KACvB,IAAIC,EAA8B,IAElC,MAAgC,iBAArBD,GAASC,QAChBA,EAAUD,EAAQC,SAEG,OAArBD,GAASC,SACY,QAArBD,GAASC,WAETA,OAAU,GAGPV,EAAML,IAAIa,EAAO,IACjBC,EACHC,QAAAA,MAKXb,SAAA,CAAAA,EACDc,EAAAA,IAACC,EAAAA,YAAA,CAAYZ,MAAAA,EAAcD,UAAAA,yBAtCf,IAAoBc,EAAAA,WAAWpB"}