const E = {
  USER: {
    name: "User",
    tags: [
      { key: "first_name", label: "First Name", category: "User", preview: "John" },
      { key: "last_name", label: "Last Name", category: "User", preview: "Doe" },
      { key: "email", label: "Email", category: "User", preview: "john@example.com" },
      { key: "phone", label: "Phone", category: "User", preview: "+1-555-1234" },
      { key: "full_name", label: "Full Name", category: "User", preview: "John Doe" },
      { key: "username", label: "Username", category: "User", preview: "johndoe" }
    ]
  },
  COMPANY: {
    name: "Company",
    tags: [
      { key: "company_name", label: "Company Name", category: "Company", preview: "Acme Corp" },
      { key: "company_address", label: "Company Address", category: "Company", preview: "123 Main St" },
      { key: "company_phone", label: "Company Phone", category: "Company", preview: "+1-555-0000" },
      { key: "company_email", label: "Company Email", category: "Company", preview: "info@acme.com" }
    ]
  },
  DATE: {
    name: "Date",
    tags: [
      { key: "today", label: "Today", category: "Date", preview: (/* @__PURE__ */ new Date()).toLocaleDateString() },
      { key: "tomorrow", label: "Tomorrow", category: "Date", preview: new Date(Date.now() + 864e5).toLocaleDateString() },
      { key: "next_week", label: "Next Week", category: "Date", preview: new Date(Date.now() + 6048e5).toLocaleDateString() }
    ]
  },
  CUSTOM: {
    name: "Custom",
    tags: []
  }
};
let L = null, r = null;
function T(c) {
  const s = L;
  if (!s) return;
  const l = window.getSelection();
  if (!l) return;
  l.removeAllRanges(), l.addRange(s);
  const C = `merge-tag-${c.key}-${Date.now()}`, t = document.createElement("span");
  t.className = "rte-merge-tag", t.id = C, t.setAttribute("contenteditable", "false"), t.setAttribute("data-key", c.key), t.setAttribute("data-category", c.category), t.setAttribute("aria-label", `Merge tag: ${c.label}`), t.textContent = `{{ ${c.label} }}`, t.style.cssText = "background-color: #e3f2fd; border: 1px solid #bbdefb; border-radius: 3px; padding: 2px 6px; margin: 0 2px; display: inline-block; white-space: nowrap; font-weight: 500; color: #1976d2; cursor: pointer; user-select: none;";
  try {
    s.deleteContents(), s.insertNode(t), s.setStartAfter(t), s.setEndAfter(t), l.removeAllRanges(), l.addRange(s);
    const i = t.closest('[contenteditable="true"]');
    i && i.dispatchEvent(new Event("input", { bubbles: !0 }));
  } catch (i) {
    console.error("Failed to insert merge tag:", i);
  }
}
function R() {
  var A;
  const c = window.getSelection();
  c && c.rangeCount > 0 && (L = c.getRangeAt(0).cloneRange());
  let s = "USER", l = "", C = E.USER.tags;
  r = C[0] || null;
  const t = document.createElement("div");
  t.className = "rte-dialog-overlay", t.style.cssText = "position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 10000;";
  const i = document.createElement("div");
  i.className = "rte-dialog rte-merge-tag-dialog", i.style.cssText = "background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); width: 500px; max-width: 90vw; max-height: 600px; overflow: hidden; display: flex; flex-direction: column;";
  const f = document.createElement("div");
  f.className = "rte-dialog-header", f.style.cssText = "padding: 16px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center;", f.innerHTML = `
    <h2 style="margin: 0; font-size: 18px; font-weight: 600;">Insert Merge Tag</h2>
    <button class="rte-dialog-close" style="background: none; border: none; font-size: 24px; cursor: pointer; color: #999; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;" aria-label="Close">✕</button>
  `;
  const y = document.createElement("div");
  y.className = "rte-dialog-body", y.style.cssText = "padding: 16px; overflow-y: auto; flex: 1;";
  const d = document.createElement("input");
  d.type = "text", d.className = "rte-input", d.placeholder = "Search merge tags...", d.setAttribute("aria-label", "Search merge tags"), d.style.cssText = "width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; box-sizing: border-box; margin-bottom: 12px;", y.appendChild(d);
  const v = document.createElement("div");
  v.className = "rte-tabs", v.style.cssText = "display: flex; gap: 8px; margin-bottom: 12px; border-bottom: 2px solid #eee;";
  const N = Object.entries(E).map(([a, e]) => ({ key: a, name: e.name }));
  N.forEach((a) => {
    const e = document.createElement("button");
    e.className = "rte-tab", e.textContent = a.name, e.setAttribute("aria-label", `${a.name} category`), e.style.cssText = "padding: 8px 12px; background: none; border: none; cursor: pointer; border-bottom: 3px solid transparent; color: #666; font-weight: 500; transition: all 0.2s;", a.key === s && (e.classList.add("active"), e.style.color = "#1976d2", e.style.borderBottomColor = "#1976d2"), e.addEventListener("click", () => {
      s = a.key, l = "", d.value = "", M(), k();
    }), e.addEventListener("mouseenter", () => {
      e.style.color = "#333";
    }), e.addEventListener("mouseleave", () => {
      e.classList.contains("active") || (e.style.color = "#666");
    }), v.appendChild(e);
  }), y.appendChild(v);
  const u = document.createElement("div");
  u.className = "rte-merge-tag-list", u.style.cssText = "border: 1px solid #ddd; border-radius: 4px; max-height: 300px; overflow-y: auto; margin-bottom: 12px;", y.appendChild(u);
  const x = document.createElement("div");
  x.className = "rte-merge-tag-preview", x.style.cssText = "padding: 8px; background-color: #f5f5f5; border-radius: 4px; font-family: monospace; font-size: 12px;", y.appendChild(x);
  function M() {
    v.querySelectorAll(".rte-tab").forEach((e, o) => {
      N[o].key === s ? (e.classList.add("active"), e.style.color = "#1976d2", e.style.borderBottomColor = "#1976d2") : (e.classList.remove("active"), e.style.color = "#666", e.style.borderBottomColor = "transparent");
    });
  }
  function k() {
    const a = E[s];
    let e = a ? a.tags : [];
    if (l.trim() && (e = e.filter(
      (o) => o.label.toLowerCase().includes(l.toLowerCase()) || o.key.toLowerCase().includes(l.toLowerCase())
    )), C = e, r = e[0] || null, u.innerHTML = "", e.length === 0) {
      const o = document.createElement("div");
      o.className = "rte-empty-state", o.textContent = "No merge tags found", o.style.cssText = "padding: 24px; text-align: center; color: #999;", u.appendChild(o);
    } else
      e.forEach((o, S) => {
        const n = document.createElement("div");
        n.className = "rte-merge-tag-item", n.setAttribute("data-tag-key", o.key), n.style.cssText = "padding: 8px 12px; border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background-color 0.2s;", S === 0 && (n.classList.add("selected"), n.style.backgroundColor = "#f5f5f5");
        const w = document.createElement("div");
        if (w.className = "tag-label", w.textContent = o.label, w.style.cssText = "font-weight: 600; color: #333;", n.appendChild(w), o.preview) {
          const g = document.createElement("div");
          g.className = "tag-preview", g.textContent = o.preview, g.style.cssText = "font-size: 12px; color: #999; margin-top: 2px;", n.appendChild(g);
        }
        if (o.description) {
          const g = document.createElement("div");
          g.className = "tag-description", g.textContent = o.description, g.style.cssText = "font-size: 12px; color: #aaa; margin-top: 2px;", n.appendChild(g);
        }
        n.addEventListener("click", () => {
          r = o, U(), D();
        }), n.addEventListener("dblclick", () => {
          T(o), b();
        }), n.addEventListener("mouseenter", () => {
          n.style.backgroundColor = "#f5f5f5";
        }), n.addEventListener("mouseleave", () => {
          n.classList.contains("selected") || (n.style.backgroundColor = "");
        }), u.appendChild(n);
      });
    D();
  }
  function U() {
    u.querySelectorAll(".rte-merge-tag-item").forEach((e) => {
      e.getAttribute("data-tag-key") === (r == null ? void 0 : r.key) ? (e.classList.add("selected"), e.style.backgroundColor = "#f5f5f5") : (e.classList.remove("selected"), e.style.backgroundColor = "");
    });
  }
  function D() {
    r ? (x.innerHTML = `<strong>Preview:</strong> {{ ${r.label} }}`, x.style.display = "block") : x.style.display = "none";
  }
  d.addEventListener("input", (a) => {
    l = a.target.value, k();
  }), d.addEventListener("keydown", (a) => {
    a.key === "Enter" && r ? (T(r), b()) : a.key === "Escape" && b();
  });
  const h = document.createElement("div");
  h.className = "rte-dialog-footer", h.style.cssText = "padding: 12px 16px; border-top: 1px solid #eee; display: flex; gap: 8px; justify-content: flex-end;";
  const p = document.createElement("button");
  p.className = "rte-button-secondary", p.textContent = "Cancel", p.style.cssText = "padding: 8px 16px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; cursor: pointer; background-color: #f5f5f5; color: #333; transition: all 0.2s;", p.addEventListener("click", b), p.addEventListener("mouseenter", () => {
    p.style.backgroundColor = "#eeeeee";
  }), p.addEventListener("mouseleave", () => {
    p.style.backgroundColor = "#f5f5f5";
  });
  const m = document.createElement("button");
  m.className = "rte-button-primary", m.textContent = "Insert", m.style.cssText = "padding: 8px 16px; border: none; border-radius: 4px; font-size: 14px; cursor: pointer; background-color: #1976d2; color: white; transition: all 0.2s;", m.addEventListener("click", () => {
    r && (T(r), b());
  }), m.addEventListener("mouseenter", () => {
    m.style.backgroundColor = "#1565c0";
  }), m.addEventListener("mouseleave", () => {
    m.style.backgroundColor = "#1976d2";
  }), h.appendChild(p), h.appendChild(m), i.appendChild(f), i.appendChild(y), i.appendChild(h), t.appendChild(i);
  function b() {
    t.remove(), L = null, r = null;
  }
  (A = f.querySelector(".rte-dialog-close")) == null || A.addEventListener("click", b), t.addEventListener("click", (a) => {
    a.target === t && b();
  }), document.body.appendChild(t), k(), setTimeout(() => d.focus(), 100);
}
const z = () => ({
  name: "mergeTag",
  toolbar: [
    {
      label: "Merge Tag",
      command: "insertMergeTag",
      icon: "{{ }}"
    }
  ],
  commands: {
    insertMergeTag: () => (R(), !0)
  }
});
export {
  z as MergeTagPlugin
};
//# sourceMappingURL=MergeTagPlugin.native-CrxyThyn.mjs.map
