{
  "version": 3,
  "sources": ["../../src/managers/internal/UIBaseManager/UIBaseManager.ts"],
  "sourcesContent": ["import { UITagsEnum } from 'constants/UITags.enum';\nimport { IEventBus } from 'lib/sdkDappUi';\nimport { ProviderErrorsEnum } from 'types/provider.types';\nimport {\n  ComponentFactory,\n  CreateEventBusUIElementType\n} from 'utils/ComponentFactory';\n\nexport abstract class UIBaseManager<\n  TElement extends CreateEventBusUIElementType,\n  TData extends Record<string, any> | null,\n  TEventEnum extends string\n> {\n  protected eventBus: IEventBus | null = null;\n  protected uiElement: TElement | null = null;\n  protected isCreatingElement = false;\n  protected anchor?: HTMLElement;\n  protected uiTag: UITagsEnum;\n  protected uiDataUpdateEvent: TEventEnum;\n  protected eventHandlers: Map<TEventEnum, Function[]> = new Map();\n  protected unsubscribeFunctions: Map<TEventEnum, (() => void)[]> = new Map();\n  protected abstract initialData: TData;\n  protected data: TData;\n\n  constructor({\n    uiDataUpdateEvent,\n    uiTag\n  }: {\n    uiTag: UITagsEnum;\n    uiDataUpdateEvent: TEventEnum;\n  }) {\n    this.uiDataUpdateEvent = uiDataUpdateEvent;\n    this.uiTag = uiTag;\n    this.data = this.getInitialData();\n  }\n\n  public async init(anchor?: HTMLElement) {\n    this.anchor = anchor;\n    await this.createUIElement(anchor);\n    await this.setupEventListeners();\n  }\n\n  public updateData(newData: Partial<TData>) {\n    this.data = { ...this.data, ...newData };\n    this.notifyDataUpdate();\n  }\n\n  public subscribeToEventBus(event: TEventEnum, callback: Function) {\n    if (!this.eventBus) {\n      throw new Error(ProviderErrorsEnum.eventBusError);\n    }\n\n    const unsubscribe = this.eventBus?.subscribe(event, callback);\n    if (unsubscribe) {\n      const existing = this.unsubscribeFunctions.get(event) || [];\n      existing.push(unsubscribe);\n      this.unsubscribeFunctions.set(event, existing);\n\n      // Store handler programmatic access (e.g. for testing)\n      const existingHandlers = this.eventHandlers.get(event) || [];\n      existingHandlers.push(callback);\n      this.eventHandlers.set(event, existingHandlers);\n    }\n  }\n\n  public notifyDataUpdate() {\n    this.eventBus?.publish(this.uiDataUpdateEvent, this.data);\n  }\n\n  public clearEventHandlers(\n    events: TEventEnum[] = Array.from(this.unsubscribeFunctions.keys())\n  ) {\n    events.forEach((event) => {\n      const unsubList = this.unsubscribeFunctions.get(event) || [];\n      unsubList.forEach((unsubscribe) => unsubscribe());\n      this.unsubscribeFunctions.delete(event);\n      this.eventHandlers.delete(event);\n    });\n  }\n\n  public destroy() {\n    this.unsubscribeFunctions.forEach((unsubList) =>\n      unsubList.forEach((unsubscribe) => unsubscribe())\n    );\n    this.unsubscribeFunctions.clear();\n    this.eventHandlers.clear();\n    this.eventBus = null;\n    this.uiElement?.remove?.();\n    this.uiElement = null;\n  }\n\n  protected getInitialData(): TData {\n    return this.initialData;\n  }\n\n  public getEventHandlers(event: TEventEnum): Function[] {\n    return this.eventHandlers.get(event) || [];\n  }\n\n  protected resetData() {\n    this.data = this.getInitialData();\n  }\n\n  protected abstract setupEventListeners(): Promise<void>;\n\n  private async createUIElement(\n    anchor: HTMLElement | undefined = this.anchor\n  ): Promise<TElement | null> {\n    if (this.isCreatingElement || this.uiElement) {\n      return this.uiElement;\n    }\n\n    this.isCreatingElement = true;\n\n    this.uiElement = await ComponentFactory.create<TElement>({\n      name: this.uiTag,\n      anchor\n    });\n\n    this.isCreatingElement = false;\n\n    if (!this.uiElement) {\n      throw new Error(`Failed to create ${this.uiTag} element`);\n    }\n\n    if (!this.eventBus) {\n      this.eventBus = await this.uiElement.getEventBus();\n    }\n\n    if (!this.eventBus) {\n      throw new Error(ProviderErrorsEnum.eventBusError);\n    }\n\n    return this.uiElement;\n  }\n}\n"],
  "mappings": "oCAQO,IAAeA,EAAf,KAIL,CAYA,YAAY,CACV,kBAAAC,EACA,MAAAC,CACF,EAGG,CAjBH,KAAU,SAA6B,KACvC,KAAU,UAA6B,KACvC,KAAU,kBAAoB,GAI9B,KAAU,cAA6C,IAAI,IAC3D,KAAU,qBAAwD,IAAI,IAWpE,KAAK,kBAAoBD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,OAAO,KAAK,WACd,CAEO,iBAAiBF,EAA+B,CACrD,OAAO,KAAK,cAAc,IAAIA,CAAK,GAAK,CAAC,CAC3C,CAEU,WAAY,CACpB,KAAK,KAAO,KAAK,eAAe,CAClC,CAIA,MAAc,gBACZF,EAAkC,KAAK,OACb,CAC1B,GAAI,KAAK,mBAAqB,KAAK,UACjC,OAAO,KAAK,UAYd,GATA,KAAK,kBAAoB,GAEzB,KAAK,UAAY,MAAMS,EAAiB,OAAiB,CACvD,KAAM,KAAK,MACX,OAAAT,CACF,CAAC,EAED,KAAK,kBAAoB,GAErB,CAAC,KAAK,UACR,MAAM,IAAI,MAAM,oBAAoB,KAAK,KAAK,UAAU,EAO1D,GAJK,KAAK,WACR,KAAK,SAAW,MAAM,KAAK,UAAU,YAAY,GAG/C,CAAC,KAAK,SACR,MAAM,IAAI,mCAAsC,EAGlD,OAAO,KAAK,SACd,CACF",
  "names": ["UIBaseManager", "uiDataUpdateEvent", "uiTag", "anchor", "newData", "event", "callback", "unsubscribe", "existing", "existingHandlers", "events", "unsubList", "ComponentFactory"]
}
