import { getGlobalApiConfig as d, buildApiUrl as s, getGlobalApiHeaders as u } from "./shared-config.esm.js";
const m = () => ({
  name: "document-manager",
  toolbar: [
    {
      label: "Import Word",
      command: "importWord",
      icon: '<svg width="24" height="24" focusable="false"><path fill-rule="evenodd" clip-rule="evenodd" d="M7 3h7.4L19 7.6V15h-2V9h-4V5H5c0-1.1.9-2 2-2Z"></path><path d="M9.5 7A1.5 1.5 0 0 1 11 8.4v7.1A1.5 1.5 0 0 1 9.6 17H2.5A1.5 1.5 0 0 1 1 15.6V8.5A1.5 1.5 0 0 1 2.4 7h7.1Zm-1 2.8-1 2.6-1-2.5v-.1a.6.6 0 0 0-1 0l-.1.1-.9 2.5-1-2.5v-.1a.6.6 0 0 0-1 .4v.1l1.5 4v.1a.6.6 0 0 0 1 0v-.1l1-2.5.9 2.5v.1a.6.6 0 0 0 1 0H8l1.6-4v-.2a.6.6 0 0 0-1.1-.4Z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M11.4 18.2a1 1 0 0 0 1.2 1.6l1.4-1V22a1 1 0 1 0 2 0v-3.1l1.4 1a1 1 0 0 0 1.2-1.7L15 15.8l-3.6 2.4Z"></path></svg>',
      type: "button"
    },
    {
      label: "Export Word",
      command: "exportWord",
      icon: '<svg width="24" height="24" focusable="false"><path d="M9.5 7A1.5 1.5 0 0 1 11 8.4v7.1A1.5 1.5 0 0 1 9.6 17H2.5A1.5 1.5 0 0 1 1 15.6V8.5A1.5 1.5 0 0 1 2.4 7h7.1Zm-1 2.8-1 2.6-1-2.5v-.1a.6.6 0 0 0-1 0l-.1.1-.9 2.5-1-2.5v-.1a.6.6 0 0 0-1 .4v.1l1.5 4v.1a.6.6 0 0 0 1 0v-.1l1-2.5.9 2.5v.1a.6.6 0 0 0 1 0H8l1.6-4v-.2a.6.6 0 0 0-1.1-.4Z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M7 3h7.4L19 7.6V17h-2V9h-4V5H7v3H5V5c0-1.1.9-2 2-2ZM15 17a1 1 0 1 0-2 0v3.1l-1.4-1a1 1 0 1 0-1.2 1.7l3.6 2.4 3.6-2.4a1 1 0 0 0-1.2-1.6l-1.4 1V17Z"></path></svg>',
      type: "button"
    },
    {
      label: "Export PDF",
      command: "exportPdf",
      icon: '<svg width="24" height="24" focusable="false"><path fill-rule="evenodd" clip-rule="evenodd" d="M7 3h7.4L19 7.6V17h-2V9h-4V5H7v3H5V5c0-1.1.9-2 2-2Z"></path><path d="M2.6 15.2v-1.9h1c.6 0 1-.2 1.4-.5.3-.3.5-.7.5-1.2s-.2-.9-.5-1.2a2 2 0 0 0-1.3-.4H1v5.2h1.6Zm.4-3h-.4v-1.1h.5l.6.1.2.5c0 .1 0 .3-.2.4l-.7.1Zm5.7 3 1-.1c.3 0 .5-.2.7-.4l.5-.8c.2-.3.2-.7.2-1.3v-1l-.5-.8c-.2-.3-.4-.5-.7-.6L8.7 10H6.3v5.2h2.4Zm-.4-1.1H8v-3h.4c.5 0 .8.2 1 .4l.2 1.1-.1 1-.3.3-.8.2Zm5.3 1.2V13h2v-1h-2v-1H16V10h-4v5.2h1.6Z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M15 17a1 1 0 1 0-2 0v3.1l-1.4-1a1 1 0 1 0-1.2 1.7l3.6 2.4 3.6-2.4a1 1 0 0 0-1.2-1.6l-1.4 1V17Z"></path></svg>',
      type: "button"
    }
  ],
  commands: {
    importWord: () => {
      const r = () => {
        const o = window.getSelection();
        if (o && o.rangeCount > 0) {
          let a = o.getRangeAt(0).startContainer;
          for (; a && a !== document.body; ) {
            if (a.nodeType === Node.ELEMENT_NODE) {
              const i = a;
              if (i.getAttribute("contenteditable") === "true")
                return i;
            }
            a = a.parentNode;
          }
        }
        const n = document.activeElement;
        if (n?.getAttribute("contenteditable") === "true")
          return n;
        const t = n?.closest('[contenteditable="true"]');
        return t || document.querySelector('[contenteditable="true"]');
      }, e = document.createElement("input");
      return e.type = "file", e.accept = ".docx", e.onchange = async (o) => {
        const n = o.target.files?.[0];
        if (n)
          try {
            const t = r();
            if (t) {
              const { importFromWord: a } = await import("./documentManager-CTqRftU8.mjs"), i = await a(n);
              t.innerHTML = i, t.dispatchEvent(new Event("input", { bubbles: !0 }));
            }
          } catch (t) {
            console.error("Import failed:", t), alert("Failed to import Word document. Please check the console for details.");
          }
      }, e.click(), !0;
    },
    exportWord: async () => {
      const r = () => {
        const e = window.getSelection();
        if (e && e.rangeCount > 0) {
          let t = e.getRangeAt(0).startContainer;
          for (; t && t !== document.body; ) {
            if (t.nodeType === Node.ELEMENT_NODE && t.getAttribute("contenteditable") === "true")
              return t;
            t = t.parentNode;
          }
        }
        const o = document.activeElement;
        return o?.getAttribute("contenteditable") === "true" ? o : o?.closest('[contenteditable="true"]') || document.querySelector('[contenteditable="true"]');
      };
      try {
        const e = r();
        if (e) {
          const o = e.innerHTML, { exportToWord: n } = await import("./documentManager-CTqRftU8.mjs");
          await n(o, "document.docx");
        }
        return !0;
      } catch (e) {
        return console.error("Export failed:", e), alert("Failed to export to Word. Please check the console for details."), !1;
      }
    },
    exportPdf: async () => {
      const r = () => {
        const e = window.getSelection();
        if (e && e.rangeCount > 0) {
          let t = e.getRangeAt(0).startContainer;
          for (; t && t !== document.body; ) {
            if (t.nodeType === Node.ELEMENT_NODE && t.getAttribute("contenteditable") === "true")
              return t;
            t = t.parentNode;
          }
        }
        const o = document.activeElement;
        return o?.getAttribute("contenteditable") === "true" ? o : o?.closest('[contenteditable="true"]') || document.querySelector('[contenteditable="true"]');
      };
      try {
        const e = r();
        if (e) {
          const o = e.innerHTML, { exportToPdf: n } = await import("./documentManager-CTqRftU8.mjs");
          await n(o, "document.pdf", e);
        } else
          console.error("PDF Export: No editor element found"), alert("No active editor found. Please click in the editor area first.");
        return !0;
      } catch (e) {
        return console.error("PDF Export: Export failed:", e), alert("Failed to export to PDF. Please check the console for details."), !1;
      }
    }
  },
  keymap: {}
}), p = {
  apiEndpoints: {
    exportWord: "/documents/export-word"
  },
  headers: {
    // Add default headers if needed (e.g., API key)
    // 'Authorization': 'Bearer YOUR_API_KEY',
    // 'X-API-Key': 'YOUR_API_KEY'
  },
  useClientSideFallback: !0
  // Enable fallback by default
};
let l = { ...p };
function f(r) {
  l = { ...l, ...r };
}
function c() {
  return { ...l };
}
function v(r) {
  const e = c(), o = d(), n = e.apiUrl || o.apiUrl;
  return s(n, e.apiEndpoints[r]);
}
function g() {
  const r = u(), o = c().headers || {};
  return { ...r, ...o };
}
export {
  m as D,
  v as a,
  g as b,
  c as g,
  f as s
};
