{
  "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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,wBAAAC,EAAA,sBAAAC,EAAA,uCAAAC,EAAA,mCAAAC,EAAA,0BAAAC,EAAA,+BAAAC,EAAA,sBAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAX,GAIA,IAAAY,EAAyB,uBACzBC,EAGO,0BAEA,MAAMP,EAGT,CAAC,EACQD,EACX,CAAC,EAEUH,EAAiB,CAC5BY,EACAC,IACG,IACH,YAAS,EAAE,SACT,CAAC,CAAE,OAAQC,CAAM,IAAM,CACrB,MAAMC,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,EAAUJ,GAAkB,gBAAgBE,EAAiB,CAAC,GAE9DG,EAAqBJ,EAAM,aAAa,UAC3CE,GAAUA,EAAM,UAAYC,CAC/B,EAEME,EAA4B,CAChC,GAAGP,EACH,QAAAK,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,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AAQH,CAAM,IAAM,CACrBA,EAAM,kBAAoBA,EAAM,kBAAkB,OAAQE,GACjDA,EAAM,UAAYC,CAC1B,CACH,EACA,GACA,CACE,KAAM,yBAEN,QAAS,CACP,MAAOA,CACT,CACF,CACF,EAEA,OAAOd,EAAmCc,CAAO,EACjD,OAAOb,EAA+Ba,CAAO,CAC/C,EAEaf,EAAqBoB,GAA2B,CAC3D,KAAM,CAAE,OAAAC,CAAO,KAAI,YAAS,EAAE,SAAS,EAEjCR,EACJQ,EAAO,aAAa,OAAS,EACzB,KAAK,IACH,GAAGA,EAAO,aAAa,IAAKP,GAC1B,SAASA,EAAM,QAAQ,MAAM,GAAG,EAAE,IAAI,GAAK,GAAG,CAChD,CACF,EACA,EAEAC,EAAUK,EAAM,SAAW,gBAAgBP,EAAiB,CAAC,GAMnE,OAJIO,EAAM,UACRnB,EAAmCc,CAAO,EAAIK,EAAM,SAGlDA,EAAM,yBACRlB,EAA+Ba,CAAO,EAAIK,EAAM,2BAEhD,YAAS,EAAE,SACT,CAAC,CAAE,OAAQR,CAAM,IAAM,CACrB,MAAMI,EAAqBJ,EAAM,aAAa,UAC3CE,GAAUA,EAAM,UAAYC,CAC/B,EAEMD,EAAyB,CAC7B,GAAGM,EACH,wBAAyB,KACzB,QAAAL,CACF,EAEqBC,IAAuB,GAG1CJ,EAAM,aAAaI,CAAkB,EAAIF,EAEzCF,EAAM,aAAa,KAAKE,CAAK,CAEjC,EACA,GACA,CACE,KAAM,oBAEN,QAAS,CACP,MAAOM,CACT,CACF,CACF,EAEOL,IAGTjB,EAAesB,EAAOL,CAAO,EACtBA,EACT",
  "names": ["toastsActions_exports", "__export", "addCustomToast", "addTransactionToast", "createCustomToast", "customToastCloseHandlersDictionary", "customToastComponentDictionary", "removeAllCustomToasts", "removeAllTransactionToasts", "removeCustomToast", "removeTransactionToast", "__toCommonJS", "import_store", "import_dateTime", "customToast", "currentToastId", "state", "lastToastIndex", "toast", "toastId", "existingToastIndex", "newToast", "totalDuration", "newToastId", "props", "toasts"]
}
