{"version":3,"file":"Toast-J7hKIXMI.js","sources":["../../Client/shared/Hooks/Toast.tsx"],"sourcesContent":["import Toast from '@legacy/Components/Toast';\r\nimport * as React from 'react';\r\nimport { createRef, useState } from 'react';\r\nimport { createRoot } from 'react-dom/client';\r\n\r\nconst toastRef = createRef<Toast>(),\r\n renderPromise = new Promise<void>(resolve => {\r\n const container = document.createElement('div');\r\n document.body.appendChild(container);\r\n\r\n const root = createRoot(container);\r\n root.render(<Toast ref={toastRef} />);\r\n resolve();\r\n });\r\n\r\nexport interface ToastActions {\r\n success: (message: string, timeout?: number) => Promise<void>;\r\n warning: (message: string, timeout?: number) => Promise<void>;\r\n error: (message: string, timeout?: number) => Promise<void>;\r\n}\r\n\r\nexport const useToast = (): ToastActions => {\r\n const [storedMessage, setStoredMessage] = useState('');\r\n\r\n return {\r\n success: async (message: string, timeout?: number) => {\r\n await renderPromise;\r\n const currentRef = toastRef.current;\r\n if (!currentRef) return;\r\n onUpdate(message, message => currentRef.success(message, timeout));\r\n },\r\n\r\n warning: async (message: string, timeout?: number) => {\r\n await renderPromise;\r\n const currentRef = toastRef.current;\r\n if (!currentRef) return;\r\n onUpdate(message, message => currentRef.warning(message, timeout));\r\n },\r\n\r\n error: async (error: string | Error, timeout?: number) => {\r\n const message = error instanceof Error ? error.message : error;\r\n await renderPromise;\r\n const currentRef = toastRef.current;\r\n if (!currentRef) return;\r\n onUpdate(message, message => currentRef.error(message, timeout));\r\n },\r\n };\r\n\r\n function onUpdate(message: string, callback: (message: string) => void) {\r\n setStoredMessage(message);\r\n if (message !== storedMessage) callback(message);\r\n setTimeout(() => setStoredMessage(''), 3 * 1000);\r\n }\r\n};\r\n\r\nexport const ToastContext = React.createContext<ToastActions>({} as ToastActions);\r\n"],"names":["toastRef","createRef","renderPromise","resolve","container","createRoot","jsx","Toast","useToast","storedMessage","setStoredMessage","useState","message","timeout","currentRef","onUpdate","error","callback","ToastContext","React.createContext"],"mappings":"mIAKA,MAAMA,EAAWC,EAAiB,UAAA,EAC9BC,EAAgB,IAAI,QAAyBC,GAAA,CACnC,MAAAC,EAAY,SAAS,cAAc,KAAK,EACrC,SAAA,KAAK,YAAYA,CAAS,EAEtBC,aAAWD,CAAS,EAC5B,OAAOE,MAACC,EAAM,CAAA,IAAKP,EAAU,CAAE,EAC5BG,EAAA,CACZ,CAAC,EAQQK,EAAW,IAAoB,CACxC,KAAM,CAACC,EAAeC,CAAgB,EAAIC,EAAAA,SAAS,EAAE,EAE9C,MAAA,CACH,QAAS,MAAOC,EAAiBC,IAAqB,CAC5C,MAAAX,EACN,MAAMY,EAAad,EAAS,QACvBc,GACLC,EAASH,EAASA,GAAWE,EAAW,QAAQF,EAASC,CAAO,CAAC,CACrE,EAEA,QAAS,MAAOD,EAAiBC,IAAqB,CAC5C,MAAAX,EACN,MAAMY,EAAad,EAAS,QACvBc,GACLC,EAASH,EAASA,GAAWE,EAAW,QAAQF,EAASC,CAAO,CAAC,CACrE,EAEA,MAAO,MAAOG,EAAuBH,IAAqB,CACtD,MAAMD,EAAUI,aAAiB,MAAQA,EAAM,QAAUA,EACnD,MAAAd,EACN,MAAMY,EAAad,EAAS,QACvBc,GACLC,EAASH,EAASA,GAAWE,EAAW,MAAMF,EAASC,CAAO,CAAC,CAAA,CAEvE,EAES,SAAAE,EAASH,EAAiBK,EAAqC,CACpEP,EAAiBE,CAAO,EACpBA,IAAYH,GAAeQ,EAASL,CAAO,EAC/C,WAAW,IAAMF,EAAiB,EAAE,EAAG,EAAI,GAAI,CAAA,CAEvD,EAEaQ,EAAeC,EAAkC,cAAA,CAAkB,CAAA"}