(function (global) {
  const app = (global.EpicrisisApp = global.EpicrisisApp || {});
  const STORAGE_KEY = "epicrisis:factura-active-tab";

  function init() {
    const workspace = document.getElementById("factura_workspace");
    if (!workspace) return;
    app.tabs.create({
      root: workspace,
      tabSelector: "[data-factura-tab]",
      panelSelector: "[data-factura-panel]",
      tabDataKey: "facturaTab",
      panelDataKey: "facturaPanel",
      defaultTab: "canonica",
      storageKey: STORAGE_KEY,
    });
  }

  app.factura = { init };
})(globalThis);
