{
  "version": 3,
  "sources": ["../../src/store/actions/toasts/toastsActions.ts"],
  "sourcesContent": ["import {\n  CustomToastType,\n  IComponentToast\n} from 'store/slices/toast/toastSlice.types';\nimport { getStore } from 'store/store';\nimport {\n  getUnixTimestamp,\n  getUnixTimestampWithAddedMilliseconds\n} from 'utils/dateTime';\n\nexport const customToastComponentDictionary: Record<\n  string,\n  IComponentToast['instantiateToastElement']\n> = {};\nexport const customToastCloseHandlersDictionary: Record<string, () => void> =\n  {};\n\nexport const addCustomToast = (\n  customToast: CustomToastType,\n  currentToastId?: string\n) => {\n  getStore().setState(\n    ({ toasts: state }) => {\n      const lastToastIndex =\n        state.customToasts.length > 0\n          ? Math.max(\n              ...state.customToasts.map((toast) =>\n                parseInt(toast.toastId.split('-').pop() ?? '0')\n              )\n            )\n          : 0;\n      const toastId = currentToastId ?? `custom-toast-${lastToastIndex + 1}`;\n\n      const existingToastIndex = state.customToasts.findIndex(\n        (toast) => toast.toastId === toastId\n      );\n\n      const newToast: CustomToastType = {\n        ...customToast,\n        toastId\n      };\n\n      const isToastFound = existingToastIndex !== -1;\n\n      if (isToastFound) {\n        state.customToasts[existingToastIndex] = newToast;\n        return;\n      }\n\n      state.customToasts.push({\n        ...newToast,\n        toastId\n      });\n    },\n    false,\n    {\n      type: 'addCustomToast',\n      // @ts-ignore\n      payload: {\n        value: { customToast, currentToastId }\n      }\n    }\n  );\n};\n\nexport const removeCustomToast = (toastId: string) => {\n  getStore().setState(\n    ({ toasts: state }) => {\n      state.customToasts = state.customToasts.filter(\n        (toast) => toast.toastId !== toastId\n      );\n    },\n    false,\n    {\n      type: 'removeCustomToast',\n      // @ts-ignore\n      payload: {\n        value: toastId\n      }\n    }\n  );\n};\n\nexport const removeAllCustomToasts = () => {\n  getStore().setState(\n    ({ toasts: state }) => {\n      state.customToasts = [];\n    },\n    false,\n    {\n      type: 'removeAllCustomToasts',\n      // @ts-ignore\n      payload: {\n        value: null\n      }\n    }\n  );\n};\n\nexport const removeAllTransactionToasts = () => {\n  getStore().setState(\n    ({ toasts: state }) => {\n      state.transactionToasts = [];\n    },\n    false,\n    {\n      type: 'removeAllTransactionToasts',\n      // @ts-ignore\n      payload: {\n        value: null\n      }\n    }\n  );\n};\n\nexport const addTransactionToast = ({\n  toastId,\n  totalDuration\n}: {\n  toastId: string;\n  totalDuration: number;\n}): string => {\n  let newToastId: string = '';\n  getStore().setState(\n    ({ toasts: state }) => {\n      const lastToastIndex =\n        state.transactionToasts.length > 0\n          ? Math.max(\n              ...state.transactionToasts.map((toast) =>\n                parseInt(toast.toastId.split('-').pop() ?? '0')\n              )\n            )\n          : 0;\n      newToastId = toastId ?? `transaction-toast-${lastToastIndex + 1}`;\n\n      state.transactionToasts.push({\n        startTime: getUnixTimestamp(),\n        endTime: getUnixTimestampWithAddedMilliseconds(totalDuration),\n        toastId: newToastId\n      });\n    },\n    false,\n    {\n      type: 'addTransactionToast',\n      // @ts-ignore\n      payload: {\n        value: { toastId, totalDuration }\n      }\n    }\n  );\n\n  return newToastId;\n};\n\nexport const removeTransactionToast = (toastId: string) => {\n  getStore().setState(\n    ({ toasts: state }) => {\n      state.transactionToasts = state.transactionToasts.filter((toast) => {\n        return toast.toastId !== toastId;\n      });\n    },\n    false,\n    {\n      type: 'removeTransactionToast',\n      // @ts-ignore\n      payload: {\n        value: toastId\n      }\n    }\n  );\n\n  delete customToastCloseHandlersDictionary[toastId];\n  delete customToastComponentDictionary[toastId];\n};\n\nexport const createCustomToast = (props: CustomToastType) => {\n  const { toasts } = getStore().getState();\n\n  const lastToastIndex =\n    toasts.customToasts.length > 0\n      ? Math.max(\n          ...toasts.customToasts.map((toast) =>\n            parseInt(toast.toastId.split('-').pop() ?? '0')\n          )\n        )\n      : 0;\n\n  const toastId = props.toastId || `custom-toast-${lastToastIndex + 1}`;\n\n  if (props.onClose) {\n    customToastCloseHandlersDictionary[toastId] = props.onClose;\n  }\n\n  if (props.instantiateToastElement) {\n    customToastComponentDictionary[toastId] = props.instantiateToastElement;\n\n    getStore().setState(\n      ({ toasts: state }) => {\n        const existingToastIndex = state.customToasts.findIndex(\n          (toast) => toast.toastId === toastId\n        );\n\n        const toast: CustomToastType = {\n          ...props,\n          instantiateToastElement: null,\n          toastId\n        };\n\n        const isToastFound = existingToastIndex !== -1;\n\n        if (isToastFound) {\n          state.customToasts[existingToastIndex] = toast;\n        } else {\n          state.customToasts.push(toast);\n        }\n      },\n      false,\n      {\n        type: 'createCustomToast',\n        // @ts-ignore\n        payload: {\n          value: props\n        }\n      }\n    );\n\n    return toastId;\n  }\n\n  addCustomToast(props, toastId);\n  return toastId;\n};\n"],
  "mappings": "2HAUO,IAAMA,EAGT,CAAC,EACQC,EACX,CAAC,EAEUC,EAAiB,CAC5BC,EACAC,IACG,CACHC,EAAS,EAAE,SACT,CAAC,CAAE,OAAQC,CAAM,IAAM,CACrB,IAAMC,EACJD,EAAM,aAAa,OAAS,EACxB,KAAK,IACH,GAAGA,EAAM,aAAa,IAAKE,GACzB,SAASA,EAAM,QAAQ,MAAM,GAAG,EAAE,IAAI,GAAK,GAAG,CAChD,CACF,EACA,EACAC,EAAUL,GAAkB,gBAAgBG,EAAiB,CAAC,GAE9DG,EAAqBJ,EAAM,aAAa,UAC3CE,GAAUA,EAAM,UAAYC,CAC/B,EAEME,EAA4B,CAChC,GAAGR,EACH,QAAAM,CACF,EAIA,GAFqBC,IAAuB,GAE1B,CAChBJ,EAAM,aAAaI,CAAkB,EAAIC,EACzC,MACF,CAEAL,EAAM,aAAa,KAAK,CACtB,GAAGK,EACH,QAAAF,CACF,CAAC,CACH,EACA,GACA,CACE,KAAM,iBAEN,QAAS,CACP,MAAO,CAAE,YAAAN,EAAa,eAAAC,CAAe,CACvC,CACF,CACF,CACF,EAEaQ,EAAqBH,GAAoB,CACpDJ,EAAS,EAAE,SACT,CAAC,CAAE,OAAQC,CAAM,IAAM,CACrBA,EAAM,aAAeA,EAAM,aAAa,OACrCE,GAAUA,EAAM,UAAYC,CAC/B,CACF,EACA,GACA,C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,CAC/C,EAEaY,EAAqBC,GAA2B,CAC3D,GAAM,CAAE,OAAAC,CAAO,EAAIlB,EAAS,EAAE,SAAS,EAEjCE,EACJgB,EAAO,aAAa,OAAS,EACzB,KAAK,IACH,GAAGA,EAAO,aAAa,IAAKf,GAC1B,SAASA,EAAM,QAAQ,MAAM,GAAG,EAAE,IAAI,GAAK,GAAG,CAChD,CACF,EACA,EAEAC,EAAUa,EAAM,SAAW,gBAAgBf,EAAiB,CAAC,GAMnE,OAJIe,EAAM,UACRrB,EAAmCQ,CAAO,EAAIa,EAAM,SAGlDA,EAAM,yBACRtB,EAA+BS,CAAO,EAAIa,EAAM,wBAEhDjB,EAAS,EAAE,SACT,CAAC,CAAE,OAAQC,CAAM,IAAM,CACrB,IAAMI,EAAqBJ,EAAM,aAAa,UAC3CE,GAAUA,EAAM,UAAYC,CAC/B,EAEMD,EAAyB,CAC7B,GAAGc,EACH,wBAAyB,KACzB,QAAAb,CACF,EAEqBC,IAAuB,GAG1CJ,EAAM,aAAaI,CAAkB,EAAIF,EAEzCF,EAAM,aAAa,KAAKE,CAAK,CAEjC,EACA,GACA,CACE,KAAM,oBAEN,QAAS,CACP,MAAOc,CACT,CACF,CACF,EAEOb,IAGTP,EAAeoB,EAAOb,CAAO,EACtBA,EACT",
  "names": ["customToastComponentDictionary", "customToastCloseHandlersDictionary", "addCustomToast", "customToast", "currentToastId", "getStore", "state", "lastToastIndex", "toast", "toastId", "existingToastIndex", "newToast", "removeCustomToast", "removeAllCustomToasts", "removeAllTransactionToasts", "addTransactionToast", "totalDuration", "newToastId", "getUnixTimestamp", "getUnixTimestampWithAddedMilliseconds", "removeTransactionToast", "createCustomToast", "props", "toasts"]
}
