{
  "version": 3,
  "sources": ["../../../src/managers/ToastManager/ToastUICoordinator.ts"],
  "sourcesContent": ["import { UITagsEnum } from 'constants/UITags.enum';\nimport { MvxToastList } from 'lib/sdkDappUi';\nimport { NotificationsFeedManager } from 'managers/NotificationsFeedManager/NotificationsFeedManager';\nimport type { CustomToastType } from 'store/slices/toast/toastSlice.types';\nimport { getStore } from 'store/store';\nimport { IEventBus } from 'types/manager.types';\nimport { ProviderErrorsEnum } from 'types/provider.types';\nimport { ComponentFactory } from 'utils/ComponentFactory';\nimport { ToastEventsEnum } from './types';\nimport type { ITransactionToast } from './types';\n\ntype OnCloseToastType = (toastId: string) => boolean;\ntype StoreObjectType = ReturnType<typeof getStore>;\n\nexport class ToastUICoordinator {\n  private toastsElement: MvxToastList | null = null;\n  private eventBus: IEventBus<\n    ITransactionToast[] | CustomToastType[] | null\n  > | null = null;\n  private isCreatingElement = false;\n  private eventBusUnsubscribeFunctions: (() => void)[] = [];\n  private readonly notificationsFeedManager: NotificationsFeedManager;\n  private readonly store: StoreObjectType;\n  private readonly onCloseToast: OnCloseToastType;\n\n  constructor(props: {\n    onCloseToast: OnCloseToastType;\n    store?: StoreObjectType;\n    notificationsFeedManager?: NotificationsFeedManager;\n  }) {\n    this.onCloseToast = props.onCloseToast;\n    this.store = props.store || getStore();\n    this.notificationsFeedManager =\n      props.notificationsFeedManager || NotificationsFeedManager.getInstance();\n  }\n\n  public async init() {\n    await this.subscribeToEventBusNotifications();\n  }\n\n  public showToasts() {\n    this.eventBus?.publish(ToastEventsEnum.SHOW, null);\n  }\n\n  public hideToasts() {\n    this.eventBus?.publish(ToastEventsEnum.HIDE, null);\n  }\n\n  public async publishTransactionToasts(toasts: ITransactionToast[]) {\n    if (\n      this.notificationsFeedManager.isNotificationsFeedOpen() &&\n      this.eventBus\n    ) {\n      this.eventBus.publish(\n        ToastEventsEnum.TRANSACTION_TOAST_DATA_UPDATE,\n        toasts\n      );\n      this.hideToasts();\n      return;\n    }\n\n    if (!this.eventBus) {\n      const toastsElement = await this.createToastListElement();\n      if (!toastsElement) {\n        return;\n      }\n      this.eventBus = await toastsElement.getEventBus();\n    }\n\n    this.eventBus?.publish(\n      ToastEventsEnum.TRANSACTION_TOAST_DATA_UPDATE,\n      toasts\n    );\n  }\n\n  public async publishCustomToasts(customToasts: CustomToastType[]) {\n    this.eventBus?.publish(\n      ToastEventsEnum.CUSTOM_TOAST_DATA_UPDATE,\n      customToasts\n    );\n  }\n\n  private handleOpenNotificationsFeed() {\n    this.notificationsFeedManager.openNotificationsFeed();\n  }\n\n  public destroy() {\n    this.eventBusUnsubscribeFunctions.forEach((unsubscribe) => unsubscribe());\n    this.eventBusUnsubscribeFunctions = [];\n    this.notificationsFeedManager?.destroy();\n  }\n\n  private async createToastListElement(): Promise<MvxToastList | null> {\n    if (this.toastsElement) {\n      return this.toastsElement;\n    }\n\n    if (!this.isCreatingElement) {\n      this.isCreatingElement = true;\n      this.toastsElement = await ComponentFactory.create<MvxToastList>({\n        name: UITagsEnum.TOAST_LIST\n      });\n      this.isCreatingElement = false;\n    }\n\n    return this.toastsElement;\n  }\n\n  private async subscribeToEventBusNotifications() {\n    const toastsElement = await this.createToastListElement();\n\n    if (!toastsElement) {\n      return;\n    }\n\n    this.eventBus = await toastsElement.getEventBus();\n    if (!this.eventBus) {\n      throw new Error(ProviderErrorsEnum.eventBusError);\n    }\n\n    this.eventBus.subscribe(ToastEventsEnum.CLOSE, this.onCloseToast);\n\n    this.eventBusUnsubscribeFunctions.push(() => {\n      this.eventBus?.unsubscribe(ToastEventsEnum.CLOSE, this.onCloseToast);\n    });\n\n    this.eventBus.subscribe(\n      ToastEventsEnum.OPEN_NOTIFICATIONS_FEED,\n      this.handleOpenNotificationsFeed.bind(this)\n    );\n\n    this.eventBusUnsubscribeFunctions.push(() => {\n      this.eventBus?.unsubscribe(\n        ToastEventsEnum.OPEN_NOTIFICATIONS_FEED,\n        this.handleOpenNotificationsFeed.bind(this)\n      );\n    });\n  }\n}\n"],
  "m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K,cACA,KAAK,eAGT,KAAK,oBACR,KAAK,kBAAoB,GACzB,KAAK,cAAgB,MAAM,mBAAiB,OAAqB,CAC/D,KAAM,aAAW,UACnB,CAAC,EACD,KAAK,kBAAoB,IAGpB,KAAK,cACd,CAEA,MAAc,kCAAmC,CAC/C,MAAMF,EAAgB,MAAM,KAAK,uBAAuB,EAExD,GAAKA,EAKL,IADA,KAAK,SAAW,MAAMA,EAAc,YAAY,EAC5C,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,qBAAmB,aAAa,EAGlD,KAAK,SAAS,UAAU,kBAAgB,MAAO,KAAK,YAAY,EAEhE,KAAK,6BAA6B,KAAK,IAAM,CAC3C,KAAK,UAAU,YAAY,kBAAgB,MAAO,KAAK,YAAY,CACrE,CAAC,EAED,KAAK,SAAS,UACZ,kBAAgB,wBAChB,KAAK,4BAA4B,KAAK,IAAI,CAC5C,EAEA,KAAK,6BAA6B,KAAK,IAAM,CAC3C,KAAK,UAAU,YACb,kBAAgB,wBAChB,KAAK,4BAA4B,KAAK,IAAI,CAC5C,CACF,CAAC,EACH,CACF",
  "names": ["ToastUICoordinator_exports", "__export", "ToastUICoordinator", "__toCommonJS", "import_UITags", "import_NotificationsFeedManager", "import_store", "import_provider", "import_ComponentFactory", "import_types", "props", "toasts", "toastsElement", "customToasts", "unsubscribe"]
}
