const u = /* @__PURE__ */ new Map();
let x = !1, d = null, C = /* @__PURE__ */ new Set(), v = {}, h = null, p = "";
const w = "User";
let y = null;
function R() {
  return Array.from(u.values());
}
function S(e, o, t = !1) {
  if (t) {
    const b = `comment-${Date.now()}`, B = {
      id: b,
      anchorId: "",
      selectedText: "",
      author: e,
      text: o,
      createdAt: (/* @__PURE__ */ new Date()).toISOString(),
      resolved: !1,
      replies: []
    };
    return u.set(b, B), s(), b;
  }
  const n = window.getSelection();
  if (!n || n.rangeCount === 0) return "";
  const c = h || n.getRangeAt(0), g = c.toString();
  if (!g) return "";
  const a = `comment-${Date.now()}`, f = `comment-anchor-${Date.now()}`, l = document.createElement("span");
  l.id = f, l.className = "rte-comment-anchor", l.setAttribute("data-comment-id", a), l.style.cssText = `
    background-color: #ffeb3b;
    border-bottom: 2px solid #fbc02d;
    cursor: pointer;
    position: relative;
  `, l.title = "Click to view comment";
  const r = c.cloneRange(), i = r.extractContents();
  l.appendChild(i), r.insertNode(l);
  const m = {
    id: a,
    anchorId: f,
    selectedText: g,
    author: e,
    text: o,
    createdAt: (/* @__PURE__ */ new Date()).toISOString(),
    resolved: !1,
    replies: []
  };
  return u.set(a, m), l.onclick = () => {
    x = !0, k();
  }, s(), h = null, n.removeAllRanges(), a;
}
function z(e, o) {
  const t = u.get(e);
  if (t) {
    if (t.resolved = !0, t.resolvedAt = (/* @__PURE__ */ new Date()).toISOString(), t.resolvedBy = o, t.anchorId) {
      const n = document.getElementById(t.anchorId);
      n && (n.style.backgroundColor = "#e0e0e0", n.style.borderBottom = "2px solid #bdbdbd", n.style.opacity = "0.6");
    }
    s();
  }
}
function L(e) {
  const o = u.get(e);
  if (o) {
    if (o.resolved = !1, o.resolvedAt = void 0, o.resolvedBy = void 0, o.anchorId) {
      const t = document.getElementById(o.anchorId);
      t && (t.style.backgroundColor = "#ffeb3b", t.style.borderBottom = "2px solid #fbc02d", t.style.opacity = "1");
    }
    s();
  }
}
function N(e) {
  const o = u.get(e);
  if (o) {
    if (o.anchorId) {
      const t = document.getElementById(o.anchorId);
      if (t) {
        const n = t.parentNode;
        for (; t.firstChild; )
          n == null || n.insertBefore(t.firstChild, t);
        t.remove();
      }
    }
    u.delete(e), s();
  }
}
function T(e, o, t) {
  const n = u.get(e);
  if (!n) return;
  const c = {
    id: `reply-${Date.now()}`,
    author: o,
    text: t,
    createdAt: (/* @__PURE__ */ new Date()).toISOString()
  };
  n.replies.push(c), s();
}
function E(e, o) {
  const t = u.get(e);
  if (!t || !t.anchorId) return;
  const n = document.getElementById(t.anchorId);
  n && (o ? (n.classList.add("highlighted"), n.style.outline = "2px solid #0066cc", n.style.outlineOffset = "2px") : (n.classList.remove("highlighted"), n.style.outline = "none"));
}
function k() {
  if (d) {
    d.style.display = x ? "block" : "none", x ? (s(), I()) : A();
    return;
  }
  const e = document.createElement("div");
  e.className = "rte-comments-panel", d = e, document.body.appendChild(e), s(), I(), V();
}
function I() {
  y || (y = () => {
    const e = window.getSelection();
    e && e.rangeCount > 0 && !e.isCollapsed && (h = e.getRangeAt(0).cloneRange());
  }, document.addEventListener("selectionchange", y));
}
function A() {
  y && (document.removeEventListener("selectionchange", y), y = null), h = null;
}
function s() {
  if (!d) return;
  const e = R();
  d.innerHTML = `
    <div class="comments-header" style="display: flex; justify-content: space-between; align-items: center;">
      <h3 style="margin: 0;">Comments (${e.length})</h3>
      <button class="rte-comments-close" aria-label="Close comments panel">✕</button>
    </div>

    <div class="comment-add-box">
      <textarea class="new-comment-textarea" placeholder="Add a new comment..." rows="2"></textarea>
      <button class="rte-button-small add-comment-btn">Add Comment</button>
    </div>

    ${e.length === 0 ? '<div class="comments-empty">No comments yet</div>' : '<div class="comments-list"></div>'}
  `;
  const o = d.querySelector(".rte-comments-close");
  o && o.addEventListener("click", () => {
    x = !1, d && (d.style.display = "none"), A();
  });
  const t = d.querySelector(".new-comment-textarea"), n = d.querySelector(".add-comment-btn");
  if (t && n && (t.value = p, t.oninput = () => {
    p = t.value, n.disabled = !p.trim(), n.style.opacity = p.trim() ? "1" : "0.5";
  }, n.disabled = !p.trim(), n.style.opacity = p.trim() ? "1" : "0.5", n.onclick = () => {
    if (!p.trim()) {
      alert("Comment cannot be empty"), t.focus();
      return;
    }
    h ? S(w, p.trim()) : S(w, p.trim(), !0), p = "", t.value = "", s();
  }), e.length > 0) {
    const c = d.querySelector(".comments-list");
    c && e.forEach((g) => {
      const a = D(g);
      c.appendChild(a);
    });
  }
}
function D(e) {
  const o = C.has(e.id), t = document.createElement("div");
  t.className = `comment-item${e.resolved ? " resolved" : ""}`;
  const n = document.createElement("div");
  n.className = "comment-header", n.innerHTML = `
    <div class="comment-meta">
      <strong>${e.author}</strong>
      <span class="comment-date">${new Date(e.createdAt).toLocaleDateString()}</span>
    </div>
    <button class="comment-expand" aria-label="Toggle comment">${o ? "▼" : "▶"}</button>
  `;
  const c = n.querySelector(".comment-expand");
  c && c.addEventListener("click", () => {
    C.has(e.id) ? C.delete(e.id) : C.add(e.id), s();
  }), t.appendChild(n);
  const g = document.createElement("div");
  if (g.className = "comment-text", g.textContent = e.text, t.appendChild(g), e.selectedText) {
    const a = document.createElement("div");
    a.className = "comment-selection", a.textContent = `"${e.selectedText}"`, t.appendChild(a);
  }
  if (o) {
    const a = document.createElement("div");
    if (a.className = "comment-expanded", e.replies.length > 0) {
      const r = document.createElement("div");
      r.className = "comment-replies", e.replies.forEach((i) => {
        const m = document.createElement("div");
        m.className = "comment-reply", m.innerHTML = `
          <div class="reply-header">
            <strong>${i.author}</strong>
            <span class="reply-date">${new Date(i.createdAt).toLocaleDateString()}</span>
          </div>
          <div class="reply-text">${i.text}</div>
        `, r.appendChild(m);
      }), a.appendChild(r);
    }
    if (!e.resolved) {
      const r = document.createElement("div");
      r.className = "comment-reply-input";
      const i = document.createElement("textarea");
      i.placeholder = "Add a reply...", i.rows = 2, i.value = v[e.id] || "", i.oninput = () => {
        v[e.id] = i.value;
      };
      const m = document.createElement("button");
      m.className = "rte-button-small", m.textContent = "Reply", m.onclick = () => {
        var b;
        (b = v[e.id]) != null && b.trim() && (T(e.id, w, v[e.id]), v[e.id] = "", s());
      }, r.appendChild(i), r.appendChild(m), a.appendChild(r);
    }
    const f = document.createElement("div");
    if (f.className = "comment-actions", e.resolved) {
      const r = document.createElement("button");
      r.className = "action-button reopen", r.textContent = "↻ Reopen", r.onclick = () => L(e.id), f.appendChild(r);
    } else {
      const r = document.createElement("button");
      r.className = "action-button resolve", r.textContent = "✓ Resolve", r.onclick = () => z(e.id, w), f.appendChild(r);
    }
    const l = document.createElement("button");
    l.className = "action-button delete", l.textContent = "🗑 Delete", l.onclick = () => {
      confirm("Delete this comment?") && N(e.id);
    }, f.appendChild(l), a.appendChild(f), t.appendChild(a);
  }
  return t.onmouseenter = () => E(e.id, !0), t.onmouseleave = () => E(e.id, !1), t;
}
function V() {
  if (document.getElementById("rte-comments-panel-styles")) return;
  const e = document.createElement("style");
  e.id = "rte-comments-panel-styles", e.textContent = `
    .rte-comments-close:hover {
      color: #d32f2f;
    }
    .rte-comments-panel {
      position: fixed;
      right: 0;
      top: 0;
      width: 350px;
      height: 100%;
      background: white;
      border-left: 1px solid #ddd;
      box-shadow: -2px 0 4px rgba(0,0,0,0.1);
      overflow-y: auto;
      z-index: 1000;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      display: flex;
      flex-direction: column;
    }
    .comments-header {
      padding: 16px;
      border-bottom: 1px solid #eee;
      background-color: #fafafa;
    }
    .comments-header h3 {
      margin: 0;
      font-size: 14px;
      font-weight: 600;
    }
    .rte-comments-close {
      background: none;
      border: none;
      font-size: 22px;
      cursor: pointer;
      color: #888;
      margin-left: 8px;
      padding: 0;
    }
    .comment-add-box {
      padding: 12px;
      border-bottom: 1px solid #eee;
      background: #fafafa;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }
    .new-comment-textarea {
      font-size: 13px;
      padding: 8px;
      border-radius: 3px;
      border: 1px solid #ddd;
      resize: vertical;
      font-family: inherit;
    }
    .comments-empty {
      padding: 16px;
      text-align: center;
      color: #999;
      font-size: 13px;
    }
    .comments-list {
      padding: 12px;
    }
    .comment-item {
      padding: 12px;
      margin-bottom: 12px;
      border: 1px solid #eee;
      border-radius: 4px;
      background-color: white;
      transition: all 0.2s;
    }
    .comment-item:hover {
      border-color: #ddd;
      box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    .comment-item.resolved {
      opacity: 0.6;
      background-color: #f5f5f5;
    }
    .comment-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
    }
    .comment-meta {
      display: flex;
      flex-direction: column;
      gap: 2px;
    }
    .comment-meta strong {
      font-size: 13px;
      color: #333;
    }
    .comment-date {
      font-size: 11px;
      color: #999;
    }
    .comment-expand {
      background: none;
      border: none;
      cursor: pointer;
      color: #666;
      font-size: 12px;
      padding: 0;
    }
    .comment-text {
      font-size: 13px;
      line-height: 1.4;
      color: #333;
      margin-bottom: 8px;
    }
    .comment-selection {
      font-size: 12px;
      color: #666;
      font-style: italic;
      background-color: #f9f9f9;
      padding: 6px;
      border-radius: 3px;
      margin-bottom: 8px;
    }
    .comment-expanded {
      margin-top: 12px;
      padding-top: 12px;
      border-top: 1px solid #eee;
    }
    .comment-replies {
      margin-bottom: 12px;
    }
    .comment-reply {
      padding: 8px;
      background-color: #fafafa;
      border-radius: 3px;
      margin-bottom: 8px;
      font-size: 12px;
    }
    .reply-header {
      display: flex;
      gap: 8px;
      margin-bottom: 4px;
    }
    .reply-header strong {
      font-size: 12px;
      color: #333;
    }
    .reply-date {
      font-size: 11px;
      color: #999;
    }
    .reply-text {
      font-size: 12px;
      color: #666;
      line-height: 1.3;
    }
    .comment-reply-input {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-bottom: 12px;
    }
    .comment-reply-input textarea {
      font-size: 12px;
      padding: 6px;
      border: 1px solid #ddd;
      border-radius: 3px;
      font-family: inherit;
      resize: vertical;
    }
    .rte-button-small {
      font-size: 12px;
      padding: 4px 8px;
      background-color: #1976d2;
      color: white;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      align-self: flex-end;
    }
    .rte-button-small:hover {
      background-color: #1565c0;
    }
    .rte-button-small:disabled {
      opacity: 0.5;
      pointer-events: none;
    }
    .comment-actions {
      display: flex;
      gap: 6px;
      justify-content: flex-end;
    }
    .action-button {
      font-size: 12px;
      padding: 4px 8px;
      background-color: #f5f5f5;
      border: 1px solid #ddd;
      border-radius: 3px;
      cursor: pointer;
      transition: all 0.2s;
    }
    .action-button:hover {
      background-color: #eeeeee;
    }
    .action-button.resolve {
      color: #2e7d32;
    }
    .action-button.delete {
      color: #c62828;
    }
    .rte-comment-anchor {
      position: relative;
    }
    .rte-comment-anchor.highlighted {
      background-color: #ffeb3b !important;
      border-radius: 3px;
    }
  `, document.head.appendChild(e);
}
const H = () => ({
  name: "comments",
  toolbar: [
    {
      label: "Add Comment",
      command: "addComment",
      type: "button",
      icon: '<svg fill="#000000" width="24px" height="24px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><defs><style>.cls-1{fill:none;}</style></defs><title>add-comment</title><path d="M17.74,30,16,29l4-7h6a2,2,0,0,0,2-2V8a2,2,0,0,0-2-2H6A2,2,0,0,0,4,8V20a2,2,0,0,0,2,2h9v2H6a4,4,0,0,1-4-4V8A4,4,0,0,1,6,4H26a4,4,0,0,1,4,4V20a4,4,0,0,1-4,4H21.16Z" transform="translate(0 0)"></path><polygon points="17 9 15 9 15 13 11 13 11 15 15 15 15 19 17 19 17 15 21 15 21 13 17 13 17 9"></polygon><rect id="_Transparent_Rectangle_" data-name="&lt;Transparent Rectangle&gt;" class="cls-1" width="32" height="32"></rect></g></svg>'
    },
    {
      label: "Show / Hide Comments",
      command: "toggleComments",
      type: "button",
      icon: '<svg width="24px" height="24px" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M16 1H4V11H8L10 13L12 11H16V1Z" fill="#000000"></path> <path d="M2 5V13H7.17157L8.70711 14.5355L7.29289 15.9497L6.34315 15H0V5H2Z" fill="#000000"></path> </g></svg>'
    }
  ],
  commands: {
    addComment: () => {
      const e = window.getSelection();
      return e && e.rangeCount > 0 && !e.isCollapsed ? h = e.getRangeAt(0).cloneRange() : h = null, x = !0, k(), !0;
    },
    toggleComments: () => (x = !x, k(), !0)
  },
  keymap: {}
});
export {
  H as CommentsPlugin,
  S as addCommentCommand,
  N as deleteComment,
  R as getAllComments,
  E as highlightComment,
  L as reopenComment,
  T as replyToComment,
  z as resolveComment
};
//# sourceMappingURL=CommentsPlugin.native-2zQV8Ia4.mjs.map
