const h = () => {
  const d = window.getSelection();
  if (d && d.rangeCount > 0) {
    let e = d.getRangeAt(0).startContainer;
    for (; e && e !== document.body; ) {
      if (e.nodeType === Node.ELEMENT_NODE) {
        const a = e;
        if (a.getAttribute("contenteditable") === "true")
          return a;
      }
      e = e.parentNode;
    }
  }
  const r = document.activeElement;
  if (r) {
    if (r.getAttribute("contenteditable") === "true")
      return r;
    const e = r.closest('[contenteditable="true"]');
    if (e) return e;
  }
  return document.querySelector('[contenteditable="true"]');
}, z = [
  { value: "javascript", label: "JavaScript" },
  { value: "typescript", label: "TypeScript" },
  { value: "python", label: "Python" },
  { value: "java", label: "Java" },
  { value: "csharp", label: "C#" },
  { value: "cpp", label: "C++" },
  { value: "c", label: "C" },
  { value: "php", label: "PHP" },
  { value: "ruby", label: "Ruby" },
  { value: "go", label: "Go" },
  { value: "rust", label: "Rust" },
  { value: "swift", label: "Swift" },
  { value: "kotlin", label: "Kotlin" },
  { value: "html", label: "HTML" },
  { value: "css", label: "CSS" },
  { value: "scss", label: "SCSS" },
  { value: "json", label: "JSON" },
  { value: "xml", label: "XML" },
  { value: "yaml", label: "YAML" },
  { value: "markdown", label: "Markdown" },
  { value: "sql", label: "SQL" },
  { value: "bash", label: "Bash" },
  { value: "shell", label: "Shell" },
  { value: "plaintext", label: "Plain Text" }
], k = /* @__PURE__ */ new Map();
function w(d, r, e, a) {
  const p = !!r, o = a || "javascript", x = e || "", l = document.createElement("div");
  l.className = "rte-code-sample-overlay", l.style.cssText = `
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 160ms ease-out;
  `;
  const i = document.createElement("div");
  i.className = "rte-code-sample-dialog", i.style.cssText = `
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 200ms cubic-bezier(0.2, 0.9, 0.25, 1);
  `;
  const s = document.createElement("div");
  s.style.cssText = `
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  `, s.innerHTML = `
    <h2 style="margin: 0; font-size: 18px; font-weight: 600; color: #333;">
      ${p ? "Edit Code Sample" : "Insert Code Sample"}
    </h2>
    <button class="rte-code-close-btn" style="background: none; border: none; font-size: 28px; color: #999; cursor: pointer; padding: 0; width: 32px; height: 32px;">×</button>
  `;
  const t = document.createElement("div");
  t.style.cssText = `
    flex: 1;
    overflow-y: auto;
    padding: 20px;
  `;
  const u = document.createElement("div");
  u.style.marginBottom = "20px", u.innerHTML = `
    <label style="display: block; margin-bottom: 8px; font-weight: 500; color: #333; font-size: 14px;">Language</label>
    <select class="rte-code-language" style="
      width: 100%;
      padding: 10px 12px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-size: 14px;
      background-color: #fff;
      cursor: pointer;
    ">
      ${z.map((n) => `
        <option value="${n.value}" ${n.value === o ? "selected" : ""}>
          ${n.label}
        </option>
      `).join("")}
    </select>
  `;
  const b = document.createElement("div");
  b.style.marginBottom = "20px", b.innerHTML = `
    <label style="display: block; margin-bottom: 8px; font-weight: 500; color: #333; font-size: 14px;">Code</label>
    <textarea class="rte-code-textarea" spellcheck="false" placeholder="Paste or type your code here..." style="
      width: 100%;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: 4px;
      font-family: 'Courier New', Courier, monospace;
      font-size: 13px;
      line-height: 1.5;
      resize: vertical;
      min-height: 250px;
      max-height: 400px;
      background-color: #f9f9f9;
      color: #333;
      box-sizing: border-box;
    ">${x}</textarea>
    <div class="rte-code-error" style="color: #dc2626; font-size: 12px; margin-top: 6px; display: none;"></div>
  `;
  const c = document.createElement("div");
  c.style.cssText = "color: #666; font-size: 12px; margin-top: 10px;", c.innerHTML = "💡 Tip: Press Ctrl+Enter (or Cmd+Enter on Mac) to save, or Escape to cancel", t.appendChild(u), t.appendChild(b), t.appendChild(c);
  const m = document.createElement("div");
  m.style.cssText = `
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
  `, m.innerHTML = `
    <button class="rte-code-cancel-btn" style="
      padding: 10px 16px;
      border: none;
      border-radius: 4px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      background: #e5e7eb;
      color: #333;
    ">Cancel</button>
    <button class="rte-code-save-btn" style="
      padding: 10px 16px;
      border: none;
      border-radius: 4px;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      background: #2563eb;
      color: #fff;
    ">${p ? "Update Code Sample" : "Insert Code Sample"}</button>
  `, i.appendChild(s), i.appendChild(t), i.appendChild(m), l.appendChild(i);
  const y = u.querySelector(".rte-code-language"), g = b.querySelector(".rte-code-textarea"), v = b.querySelector(".rte-code-error"), E = s.querySelector(".rte-code-close-btn"), S = m.querySelector(".rte-code-cancel-btn"), T = m.querySelector(".rte-code-save-btn"), f = () => {
    l.remove();
  }, C = () => {
    const n = g.value.trim();
    if (!n) {
      v.textContent = "⚠ Code cannot be empty", v.style.display = "block";
      return;
    }
    const L = y.value;
    d(n, L), f();
  };
  if (E.onclick = f, S.onclick = f, T.onclick = C, g.addEventListener("keydown", (n) => {
    (n.ctrlKey || n.metaKey) && n.key === "Enter" && (n.preventDefault(), C()), n.key === "Escape" && f();
  }), g.addEventListener("input", () => {
    v.style.display = "none";
  }), l.addEventListener("click", (n) => {
    n.target === l && f();
  }), !document.getElementById("rte-code-sample-animations")) {
    const n = document.createElement("style");
    n.id = "rte-code-sample-animations", n.textContent = `
      @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
      }
      @keyframes slideUp {
        from { transform: translateY(20px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
      }
    `, document.head.appendChild(n);
  }
  return document.body.appendChild(l), setTimeout(() => g.focus(), 100), l;
}
function M() {
  if (!h()) return;
  let r = null;
  const e = window.getSelection();
  e && e.rangeCount > 0 && (r = e.getRangeAt(0).cloneRange()), w((a, p) => {
    const o = window.getSelection();
    if (r && (o == null || o.removeAllRanges(), o == null || o.addRange(r)), !o || o.rangeCount === 0) return;
    const x = h();
    if (!x) return;
    const l = o.anchorNode;
    if (!l || !x.contains(l)) return;
    const i = o.getRangeAt(0), s = `code-block-${Date.now()}`, t = document.createElement("pre");
    t.className = "rte-code-block", t.id = s, t.setAttribute("data-type", "code-block"), t.setAttribute("data-lang", p), t.setAttribute("data-code-id", s), t.setAttribute("contenteditable", "false"), t.style.cssText = `
      display: block;
      position: relative;
      background: #f5f5f5;
      border: 1px solid #e0e0e0;
      border-radius: 6px;
      padding: 12px;
      margin: 12px 0;
      overflow-x: auto;
      font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
      font-size: 13px;
      line-height: 1.5;
      color: #333;
      user-select: text;
      cursor: default;
    `;
    const u = document.createElement("code");
    u.className = `language-${p}`, u.style.cssText = `
      font-family: inherit;
      font-size: inherit;
      line-height: inherit;
      color: inherit;
      white-space: pre;
      word-break: normal;
      display: block;
    `, u.textContent = a;
    const b = document.createElement("span");
    b.style.cssText = `
      position: absolute;
      top: 0;
      right: 0;
      background: #333;
      color: #fff;
      padding: 2px 8px;
      font-size: 11px;
      font-weight: bold;
      border-radius: 0 6px 0 4px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      pointer-events: none;
    `, b.textContent = p;
    const c = document.createElement("button");
    c.className = "rte-code-copy", c.textContent = "Copy", c.style.cssText = `
      position: absolute;
      top: 8px;
      left: 8px;
      background: #fff;
      border: 1px solid #d0d0d0;
      border-radius: 3px;
      padding: 4px 8px;
      font-size: 11px;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.2s ease;
    `, c.onclick = (y) => {
      y.stopPropagation(), navigator.clipboard.writeText(a).then(() => {
        c.textContent = "✓ Copied!", setTimeout(() => {
          c.textContent = "Copy";
        }, 2e3);
      });
    }, t.appendChild(b), t.appendChild(c), t.appendChild(u), t.addEventListener("mouseenter", () => {
      c.style.opacity = "1";
    }), t.addEventListener("mouseleave", () => {
      c.style.opacity = "0";
    }), t.addEventListener("dblclick", () => {
      A(s);
    }), k.set(s, {
      id: s,
      language: p,
      code: a
    }), i.insertNode(t);
    const m = document.createRange();
    m.setStartAfter(t), m.collapse(!0), o.removeAllRanges(), o.addRange(m);
  });
}
function A(d) {
  const r = h();
  if (!r) return;
  const e = r.querySelector(`#${d}`);
  if (!e) return;
  const a = k.get(d);
  a && w(
    (p, o) => {
      const x = e.querySelector("code");
      x && (x.textContent = p, x.className = `language-${o}`);
      const l = e.querySelector("span");
      l && (l.textContent = o), e.setAttribute("data-lang", o), a.language = o, a.code = p;
      const i = e.querySelector(".rte-code-copy");
      i && (i.onclick = (s) => {
        s.stopPropagation(), navigator.clipboard.writeText(p).then(() => {
          i.textContent = "✓ Copied!", setTimeout(() => {
            i.textContent = "Copy";
          }, 2e3);
        });
      });
    },
    d,
    a.code,
    a.language
  );
}
const N = () => ({
  name: "codeSample",
  toolbar: [
    {
      label: "Code Block",
      command: "insertCodeBlock",
      icon: '<svg width="18px" height="18px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7 8L3 11.6923L7 16M17 8L21 11.6923L17 16M14 4L10 20" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
      shortcut: "Mod-Shift-C"
    }
  ],
  commands: {
    insertCodeBlock: (...d) => (M(), !0)
  }
});
export {
  N as CodeSamplePlugin
};
//# sourceMappingURL=CodeSamplePlugin.native-DMbEdO9j.mjs.map
