{"version":3,"file":"widget-controller-CvdYr_nc.cjs","sources":["../src/lib/widget-controller.ts"],"sourcesContent":["import type { FeedgetConfig } from \"../types\";\n\ntype Renderer = typeof import(\"./render-widget\");\ntype Handle = ReturnType<Renderer[\"renderWidget\"]>;\n\nlet renderer: Promise<Renderer> | null = null;\nconst loadRenderer = () => (renderer ??= import(\"./render-widget\"));\n\nexport class WidgetController {\n  protected config: FeedgetConfig;\n  private host: HTMLElement | null = null;\n  private handle: Handle | null = null;\n\n  constructor(config: FeedgetConfig) {\n    this.config = config;\n  }\n\n  get mounted() {\n    return this.host !== null;\n  }\n\n  protected attach(parent: HTMLElement, id: string): void {\n    if (this.host) return;\n    const host = document.createElement(\"div\");\n    host.id = id;\n    parent.appendChild(host);\n    this.host = host;\n\n    loadRenderer()\n      .then(({ renderWidget }) => {\n        if (this.host !== host) return;\n        this.handle = renderWidget(host, this.config);\n      })\n      .catch((error) => console.error(\"[Feedget] Não foi possível carregar o widget.\", error));\n  }\n\n  updateConfig(newConfig: Partial<FeedgetConfig>): void {\n    this.config = { ...this.config, ...newConfig };\n    this.handle?.render(this.config);\n  }\n\n  destroy(): void {\n    this.handle?.unmount();\n    this.handle = null;\n    this.host?.remove();\n    this.host = null;\n  }\n}\n"],"names":["renderer","loadRenderer","n","WidgetController","config","parent","id","host","renderWidget","error","newConfig"],"mappings":"aAKA,IAAIA,EAAqC,KACzC,MAAMC,EAAe,IAAOD,IAAa,QAAA,QAAA,EAAA,KAAA,IAAA,QAAO,8BAAiB,CAAA,EAAA,KAAAE,GAAAA,EAAA,YAAA,EAE1D,MAAMC,CAAiB,CAClB,OACF,KAA2B,KAC3B,OAAwB,KAEhC,YAAYC,EAAuB,CACjC,KAAK,OAASA,CAChB,CAEA,IAAI,SAAU,CACZ,OAAO,KAAK,OAAS,IACvB,CAEU,OAAOC,EAAqBC,EAAkB,CACtD,GAAI,KAAK,KAAM,OACf,MAAMC,EAAO,SAAS,cAAc,KAAK,EACzCA,EAAK,GAAKD,EACVD,EAAO,YAAYE,CAAI,EACvB,KAAK,KAAOA,EAEZN,IACG,KAAK,CAAC,CAAE,aAAAO,KAAmB,CACtB,KAAK,OAASD,IAClB,KAAK,OAASC,EAAaD,EAAM,KAAK,MAAM,EAC9C,CAAC,EACA,MAAOE,GAAU,QAAQ,MAAM,gDAAiDA,CAAK,CAAC,CAC3F,CAEA,aAAaC,EAAyC,CACpD,KAAK,OAAS,CAAE,GAAG,KAAK,OAAQ,GAAGA,CAAA,EACnC,KAAK,QAAQ,OAAO,KAAK,MAAM,CACjC,CAEA,SAAgB,CACd,KAAK,QAAQ,QAAA,EACb,KAAK,OAAS,KACd,KAAK,MAAM,OAAA,EACX,KAAK,KAAO,IACd,CACF"}