const w = ".rte-content, .editora-content", F = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", et = "__editoraCommandEditorRoot", ot = "rte-approval-workflow-styles", d = "rte-approval-panel", h = "approval", k = "approvalWorkflow", g = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', ft = {
  panelTitle: "Approval Workflow",
  panelAriaLabel: "Approval workflow panel",
  statusLabel: "Status",
  statusDraftText: "Draft",
  statusReviewText: "In Review",
  statusApprovedText: "Approved",
  requestReviewText: "Request Review",
  approveText: "Approve",
  reopenDraftText: "Reopen Draft",
  addCommentText: "Add Comment",
  actorLabel: "Actor",
  actorPlaceholder: "Reviewer name",
  commentLabel: "Comment",
  commentPlaceholder: "Add review note or sign-off context",
  closeText: "Close",
  commentsHeading: "Comments",
  signoffsHeading: "Sign-offs",
  noCommentsText: "No comments yet.",
  noSignoffsText: "No sign-offs yet.",
  summaryPrefix: "Workflow",
  lockedSuffix: "Locked",
  shortcutText: "Shortcuts: Ctrl/Cmd+Alt+Shift+A/R/P/D",
  approveCommentRequiredText: "Approval comment is required."
}, mt = {
  draft: "statusDraftText",
  review: "statusReviewText",
  approved: "statusApprovedText"
}, s = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new WeakMap(), H = /* @__PURE__ */ new Set();
let _ = 0, bt = 0, rt = 0, at = 0, R = null, v = null, T = null, L = null, S = null;
function p(t) {
  return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function gt(t) {
  return t.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function lt(t) {
  return t === "review" || t === "approved" ? t : "draft";
}
function z(t = {}) {
  return {
    defaultStatus: lt(t.defaultStatus),
    lockOnApproval: t.lockOnApproval !== !1,
    maxHistoryEntries: Math.max(10, Math.min(500, Number(t.maxHistoryEntries ?? 120))),
    requireCommentOnApprove: !!t.requireCommentOnApprove,
    defaultActor: (t.defaultActor || "system").trim() || "system",
    labels: {
      ...ft,
      ...t.labels || {}
    },
    normalizeText: t.normalizeText || gt
  };
}
function Y(t) {
  return t.closest(F) || t;
}
function K(t) {
  if (!t) return null;
  if (t.matches(w)) return t;
  const e = t.querySelector(w);
  return e instanceof HTMLElement ? e : null;
}
function vt() {
  if (typeof window > "u") return null;
  const t = window[et];
  if (!(t instanceof HTMLElement)) return null;
  window[et] = null;
  const e = K(t);
  if (e) return e;
  const o = t.closest(F);
  if (o) {
    const n = K(o);
    if (n) return n;
  }
  return null;
}
function ht(t) {
  const e = t.closest("[data-editora-editor]");
  if (e && K(e) === t)
    return e;
  let o = t;
  for (; o; ) {
    if (o.matches(F) && (o === t || K(o) === t))
      return o;
    o = o.parentElement;
  }
  return Y(t);
}
function W(t) {
  return t ? (t.getAttribute("data-theme") || t.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : t.classList.contains("dark") || t.classList.contains("editora-theme-dark") || t.classList.contains("rte-theme-dark") : !1;
}
function xt(t) {
  const e = Y(t);
  if (W(e)) return !0;
  const o = e.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return W(o) ? !0 : W(document.documentElement) || W(document.body);
}
function B(t, e) {
  t.classList.remove("rte-approval-theme-dark"), xt(e) && t.classList.add("rte-approval-theme-dark");
}
function it(t) {
  return t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null;
}
function x(t, e = !0) {
  if (D(), t?.contentElement instanceof HTMLElement) return t.contentElement;
  if (t?.editorElement instanceof HTMLElement) {
    const a = t.editorElement;
    if (a.matches(w)) return a;
    const l = a.querySelector(w);
    if (l instanceof HTMLElement) return l;
  }
  const o = vt();
  if (o) return o;
  const n = window.getSelection();
  if (n && n.rangeCount > 0) {
    const l = it(n.getRangeAt(0).startContainer)?.closest(w);
    if (l) return l;
  }
  const r = document.activeElement;
  if (r) {
    if (r.matches(w)) return r;
    const a = r.closest(w);
    if (a) return a;
  }
  return v && v.isConnected ? v : (v && !v.isConnected && (v = null), e ? document.querySelector(w) : null);
}
function D() {
  Array.from(H).forEach((e) => {
    e.isConnected || (y.get(e)?.remove(), y.delete(e), O.delete(e), s.delete(e), I.delete(e), H.delete(e), v === e && (v = null));
  });
}
function wt(t) {
  return t ? !!(t.closest(`.${d}`) || t.closest(w) || t.closest(F)) : !1;
}
function yt() {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return !1;
  const e = t.getRangeAt(0).startContainer;
  return !!it(e)?.closest(w);
}
function C(t, e, o) {
  const n = ht(t);
  Array.from(
    n.querySelectorAll(
      `.rte-toolbar-button[data-command="${e}"], .editora-toolbar-button[data-command="${e}"]`
    )
  ).forEach((a) => {
    a.classList.toggle("active", o), a.setAttribute("aria-pressed", o ? "true" : "false"), a.setAttribute("data-active", o ? "true" : "false");
  });
}
function st(t, e, o) {
  e !== null ? t.setAttribute("contenteditable", e) : t.setAttribute("contenteditable", "true"), o !== null ? t.setAttribute("data-readonly", o) : t.removeAttribute("data-readonly");
}
function X(t) {
  t.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function J(t, e) {
  if (e === t.innerHTML) return;
  const o = window.execEditorCommand || window.executeEditorCommand;
  if (typeof o == "function")
    try {
      o("recordDomTransaction", t, e, t.innerHTML);
    } catch {
    }
}
function Q() {
  return rt += 1, `approval-comment-${Date.now().toString(36)}-${rt.toString(36)}`;
}
function kt() {
  return at += 1, `approval-signoff-${Date.now().toString(36)}-${at.toString(36)}`;
}
function ct(t) {
  return {
    status: t.status,
    locked: t.locked,
    comments: t.comments.map((e) => ({ ...e })),
    signoffs: t.signoffs.map((e) => ({ ...e })),
    updatedAt: t.updatedAt
  };
}
function At(t, e) {
  const o = mt[t];
  return e.labels[o] || t;
}
function pt(t, e, o) {
  if (t.setAttribute("data-approval-status", e.status), t.setAttribute("data-approval-locked", e.locked ? "true" : "false"), t.classList.toggle("rte-approval-locked-editor", e.locked), C(t, "toggleApprovalWorkflowPanel", tt(t)), C(t, "requestApprovalReview", e.status === "review"), C(t, "approveDocument", e.status === "approved"), C(t, "reopenDraft", e.status === "draft"), e.status === "approved" && o.lockOnApproval) {
    e.locked || (e.preApprovalContentEditable = t.getAttribute("contenteditable"), e.preApprovalReadonly = t.getAttribute("data-readonly")), t.setAttribute("contenteditable", "false"), t.setAttribute("data-readonly", "true"), e.locked = !0;
    return;
  }
  e.locked = !1, st(
    t,
    e.preApprovalContentEditable ?? e.originalContentEditable,
    e.preApprovalReadonly ?? e.originalReadonly
  ), e.preApprovalContentEditable = null, e.preApprovalReadonly = null;
}
function f(t, e) {
  let o = I.get(t);
  return o || (o = {
    status: e.defaultStatus,
    locked: !1,
    comments: [],
    signoffs: [],
    updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
    originalContentEditable: t.getAttribute("contenteditable"),
    originalReadonly: t.getAttribute("data-readonly"),
    preApprovalContentEditable: null,
    preApprovalReadonly: null
  }, I.set(t, o), H.add(t), pt(t, o, e), o);
}
function j(t, e) {
  return t.length <= e ? t : t.slice(t.length - e);
}
function M(t, e) {
  const o = t.querySelector(".rte-approval-live");
  o && (o.textContent = e);
}
function St(t, e) {
  const o = ct(e);
  t.__approvalWorkflowState = o, t.dispatchEvent(
    new CustomEvent("editora:approval-state-changed", {
      bubbles: !0,
      detail: {
        state: o
      }
    })
  );
}
function q(t) {
  const e = y.get(t);
  if (!e) return;
  const o = s.get(t) || R;
  if (!o) return;
  const n = f(t, o), r = e.querySelector(".rte-approval-summary"), a = e.querySelector('[data-action="request-review"]'), l = e.querySelector('[data-action="approve"]'), c = e.querySelector('[data-action="reopen-draft"]'), u = e.querySelector(".rte-approval-comments-list"), m = e.querySelector(".rte-approval-signoffs-list");
  if (r) {
    const i = At(n.status, o);
    r.textContent = `${o.labels.summaryPrefix}: ${i} | Comments: ${n.comments.length} | Sign-offs: ${n.signoffs.length}${n.locked ? ` | ${o.labels.lockedSuffix}` : ""}`;
  }
  a && (a.disabled = n.status !== "draft"), l && (l.disabled = n.status === "approved"), c && (c.disabled = n.status === "draft"), u && (n.comments.length === 0 ? u.innerHTML = `<li class="rte-approval-empty">${p(o.labels.noCommentsText)}</li>` : u.innerHTML = n.comments.slice().reverse().map(
    (i) => `
            <li class="rte-approval-item rte-approval-item-${i.kind}" role="listitem">
              <div class="rte-approval-item-head">
                <span class="rte-approval-item-author">${p(i.author)}</span>
                <time class="rte-approval-item-time" datetime="${p(i.createdAt)}">${p(
      new Date(i.createdAt).toLocaleString()
    )}</time>
              </div>
              <p class="rte-approval-item-message">${p(i.message)}</p>
            </li>
          `
  ).join("")), m && (n.signoffs.length === 0 ? m.innerHTML = `<li class="rte-approval-empty">${p(o.labels.noSignoffsText)}</li>` : m.innerHTML = n.signoffs.slice().reverse().map(
    (i) => `
            <li class="rte-approval-item" role="listitem">
              <div class="rte-approval-item-head">
                <span class="rte-approval-item-author">${p(i.author)}</span>
                <time class="rte-approval-item-time" datetime="${p(i.createdAt)}">${p(
      new Date(i.createdAt).toLocaleString()
    )}</time>
              </div>
              <p class="rte-approval-item-message">${p(i.comment || "Approved")}</p>
            </li>
          `
  ).join(""));
}
function G(t, e, o) {
  e.updatedAt = (/* @__PURE__ */ new Date()).toISOString(), pt(t, e, o), q(t), St(t, e);
}
function nt(t, e, o, n) {
  t.comments.push({
    id: Q(),
    author: o || e.defaultActor,
    message: n,
    kind: "system",
    createdAt: (/* @__PURE__ */ new Date()).toISOString()
  }), t.comments = j(t.comments, e.maxHistoryEntries);
}
function $(t, e, o, n) {
  const r = f(t, o);
  if (r.status === e) return !1;
  const a = t.innerHTML;
  return r.status = e, e === "review" ? nt(r, o, n, "Review requested.") : e === "draft" && nt(r, o, n, "Returned to draft."), G(t, r, o), X(t), J(t, a), !0;
}
function dt(t, e, o, n) {
  const r = n.normalizeText(e);
  if (!r) return !1;
  const a = n.normalizeText(o) || n.defaultActor, l = f(t, n), c = t.innerHTML;
  return l.comments.push({
    id: Q(),
    author: a,
    message: r,
    kind: "comment",
    createdAt: (/* @__PURE__ */ new Date()).toISOString()
  }), l.comments = j(l.comments, n.maxHistoryEntries), G(t, l, n), X(t), J(t, c), !0;
}
function Z(t, e, o, n) {
  const r = e.normalizeText(o) || e.defaultActor, a = e.normalizeText(n);
  if (e.requireCommentOnApprove && !a) return !1;
  const l = f(t, e), c = t.innerHTML;
  return l.status = "approved", l.signoffs.push({
    id: kt(),
    author: r,
    comment: a || void 0,
    createdAt: (/* @__PURE__ */ new Date()).toISOString()
  }), l.signoffs = j(l.signoffs, e.maxHistoryEntries), a && (l.comments.push({
    id: Q(),
    author: r,
    message: a,
    kind: "system",
    createdAt: (/* @__PURE__ */ new Date()).toISOString()
  }), l.comments = j(l.comments, e.maxHistoryEntries)), G(t, l, e), X(t), J(t, c), !0;
}
function N(t, e) {
  return t.querySelector(`[data-field="${e}"]`);
}
function Et(t) {
  const e = N(t, "actor")?.value || "", o = N(t, "comment")?.value || "";
  return { actor: e, comment: o };
}
function U(t, e) {
  if (!e.classList.contains("show")) return;
  const n = Y(t).getBoundingClientRect(), r = Math.min(window.innerWidth - 20, 420), a = Math.max(10, window.innerWidth - r - 10), l = Math.min(Math.max(10, n.right - r), a), c = Math.max(10, Math.min(window.innerHeight - 10 - 280, n.top + 12));
  e.style.width = `${r}px`, e.style.left = `${l}px`, e.style.top = `${c}px`, e.style.maxHeight = `${Math.max(280, window.innerHeight - 24)}px`;
}
function $t(t) {
  const e = y.get(t);
  if (e) return e;
  const o = s.get(t) || R || z(), n = `rte-approval-panel-${bt++}`, r = document.createElement("section");
  return r.className = d, r.id = n, r.setAttribute("role", "dialog"), r.setAttribute("aria-modal", "false"), r.setAttribute("aria-label", o.labels.panelAriaLabel), r.setAttribute("tabindex", "-1"), r.innerHTML = `
    <header class="rte-approval-header">
      <h2 class="rte-approval-title">${p(o.labels.panelTitle)}</h2>
      <button type="button" class="rte-approval-icon-btn" data-action="close" aria-label="${p(
    o.labels.closeText
  )}">✕</button>
    </header>
    <div class="rte-approval-body">
      <p class="rte-approval-summary" aria-live="polite"></p>

      <div class="rte-approval-controls" role="toolbar" aria-label="Approval actions">
        <button type="button" class="rte-approval-btn" data-action="request-review">${p(
    o.labels.requestReviewText
  )}</button>
        <button type="button" class="rte-approval-btn rte-approval-btn-primary" data-action="approve">${p(
    o.labels.approveText
  )}</button>
        <button type="button" class="rte-approval-btn" data-action="reopen-draft">${p(
    o.labels.reopenDraftText
  )}</button>
      </div>

      <div class="rte-approval-form">
        <label class="rte-approval-label">
          ${p(o.labels.actorLabel)}
          <input type="text" data-field="actor" class="rte-approval-field" autocomplete="off" placeholder="${p(
    o.labels.actorPlaceholder
  )}" />
        </label>
        <label class="rte-approval-label">
          ${p(o.labels.commentLabel)}
          <textarea data-field="comment" class="rte-approval-field" rows="2" placeholder="${p(
    o.labels.commentPlaceholder
  )}"></textarea>
        </label>
        <button type="button" class="rte-approval-btn" data-action="add-comment">${p(
    o.labels.addCommentText
  )}</button>
      </div>

      <section class="rte-approval-section" aria-label="${p(o.labels.commentsHeading)}">
        <h3 class="rte-approval-section-title">${p(o.labels.commentsHeading)}</h3>
        <ul class="rte-approval-comments-list" role="list"></ul>
      </section>

      <section class="rte-approval-section" aria-label="${p(o.labels.signoffsHeading)}">
        <h3 class="rte-approval-section-title">${p(o.labels.signoffsHeading)}</h3>
        <ul class="rte-approval-signoffs-list" role="list"></ul>
      </section>

      <p class="rte-approval-shortcut">${p(o.labels.shortcutText)}</p>
      <span class="rte-approval-live" aria-live="polite"></span>
    </div>
  `, r.addEventListener("click", (a) => {
    const l = a.target;
    if (!l) return;
    const c = l.closest("[data-action]");
    if (!c) return;
    const u = c.getAttribute("data-action") || "", m = s.get(t) || R || o;
    if (s.set(t, m), f(t, m), u === "close") {
      P(t, !0);
      return;
    }
    const i = Et(r);
    if (u === "request-review") {
      $(t, "review", m, i.actor || m.defaultActor) && M(r, "Status changed to review.");
      return;
    }
    if (u === "reopen-draft") {
      $(t, "draft", m, i.actor || m.defaultActor) && M(r, "Status changed to draft.");
      return;
    }
    if (u === "approve") {
      const b = Z(t, m, i.actor, i.comment);
      if (!b && m.requireCommentOnApprove) {
        M(r, m.labels.approveCommentRequiredText);
        return;
      }
      if (b) {
        const E = N(r, "comment");
        E && (E.value = ""), M(r, "Document approved and signed off.");
      }
      return;
    }
    if (u === "add-comment") {
      if (!dt(t, i.comment, i.actor, m)) return;
      const E = N(r, "comment");
      E && (E.value = ""), M(r, "Comment added.");
      return;
    }
  }), r.addEventListener("keydown", (a) => {
    a.key === "Escape" && (a.preventDefault(), P(t, !0));
  }), B(r, t), document.body.appendChild(r), y.set(t, r), O.set(t, !1), q(t), r;
}
function tt(t) {
  return O.get(t) === !0;
}
function A(t) {
  D();
  const e = $t(t);
  y.forEach((o, n) => {
    n !== t && P(n, !1);
  }), e.classList.add("show"), O.set(t, !0), C(t, "toggleApprovalWorkflowPanel", !0), B(e, t), U(t, e), q(t);
}
function P(t, e = !1) {
  const o = y.get(t);
  o && (o.classList.remove("show"), O.set(t, !1), C(t, "toggleApprovalWorkflowPanel", !1), e && t.focus({ preventScroll: !0 }));
}
function ut(t, e) {
  const o = tt(t);
  return (typeof e == "boolean" ? e : !o) ? A(t) : P(t), !0;
}
function V(t) {
  return typeof t.key == "string" ? t.key.toLowerCase() : "";
}
function Ct(t) {
  const e = V(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && e === "a";
}
function Tt(t) {
  const e = V(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && e === "r";
}
function Lt(t) {
  const e = V(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && e === "p";
}
function Rt(t) {
  const e = V(t);
  return (t.metaKey || t.ctrlKey) && t.altKey && t.shiftKey && e === "d";
}
function Mt(t) {
  R = t, T || (T = (e) => {
    D();
    const n = e.target?.closest(w);
    if (!n) return;
    v = n;
    const r = s.get(n) || t;
    s.set(n, r), f(n, r);
    const a = y.get(n);
    a && (B(a, n), U(n, a));
  }, document.addEventListener("focusin", T, !0)), L || (L = (e) => {
    if (e.defaultPrevented) return;
    const o = Ct(e), n = Tt(e), r = Lt(e), a = Rt(e), l = e.key === "Escape";
    if (!l && !o && !n && !r && !a)
      return;
    D();
    const c = e.target, u = !!c?.closest(`.${d} input, .${d} textarea, .${d} select`);
    if (!wt(c) && !yt())
      return;
    const i = x(void 0, !1);
    if (!i) return;
    const b = s.get(i) || R || t;
    s.set(i, b);
    const E = f(i, b);
    if (v = i, l && tt(i)) {
      e.preventDefault(), P(i, !0);
      return;
    }
    if (!u) {
      if (o) {
        e.preventDefault(), e.stopPropagation(), ut(i);
        return;
      }
      if (n) {
        e.preventDefault(), e.stopPropagation(), $(i, "review", b, b.defaultActor) && A(i);
        return;
      }
      if (r) {
        e.preventDefault(), e.stopPropagation(), Z(i, b, b.defaultActor, "Approved via keyboard shortcut.") && A(i);
        return;
      }
      a && (e.preventDefault(), e.stopPropagation(), E.status !== "draft" && $(i, "draft", b, b.defaultActor) && A(i));
    }
  }, document.addEventListener("keydown", L, !0)), S || (S = () => {
    D(), y.forEach((e, o) => {
      !o.isConnected || !e.isConnected || (B(e, o), U(o, e));
    });
  }, window.addEventListener("scroll", S, !0), window.addEventListener("resize", S));
}
function Dt(t) {
  const e = I.get(t);
  e && (t.classList.remove("rte-approval-locked-editor"), t.removeAttribute("data-approval-status"), t.removeAttribute("data-approval-locked"), st(
    t,
    e.preApprovalContentEditable ?? e.originalContentEditable,
    e.preApprovalReadonly ?? e.originalReadonly
  ));
}
function Ht() {
  T && (document.removeEventListener("focusin", T, !0), T = null), L && (document.removeEventListener("keydown", L, !0), L = null), S && (window.removeEventListener("scroll", S, !0), window.removeEventListener("resize", S), S = null), y.forEach((t) => t.remove()), y.clear(), H.forEach((t) => Dt(t)), H.clear(), R = null, v = null;
}
function qt() {
  if (typeof document > "u" || document.getElementById(ot)) return;
  const t = document.createElement("style");
  t.id = ot, t.textContent = `
    .rte-toolbar-group-items.${h},
    .editora-toolbar-group-items.${h},
    .rte-toolbar-group-items.${k},
    .editora-toolbar-group-items.${k} {
      display: flex;
      border: 1px solid #ccc;
      border-radius: 3px;
      background: #fff;
    }

    .rte-toolbar-group-items.${h} .rte-toolbar-button,
    .editora-toolbar-group-items.${h} .editora-toolbar-button,
    .rte-toolbar-group-items.${k} .rte-toolbar-button,
    .editora-toolbar-group-items.${k} .editora-toolbar-button {
      border: none;
      border-radius: 0;
      border-right: 1px solid #ccc;
    }

    .rte-toolbar-button[data-command="toggleApprovalWorkflowPanel"].active,
    .editora-toolbar-button[data-command="toggleApprovalWorkflowPanel"].active,
    .rte-toolbar-button[data-command="reopenDraft"].active,
    .editora-toolbar-button[data-command="reopenDraft"].active {
      background-color: #ccc;
    }

    ${g} .rte-toolbar-button[data-command="toggleApprovalWorkflowPanel"].active,
    ${g} .editora-toolbar-button[data-command="toggleApprovalWorkflowPanel"].active,
    ${g} .rte-toolbar-button[data-command="reopenDraft"].active,
    ${g} .editora-toolbar-button[data-command="reopenDraft"].active {
      background: linear-gradient(180deg, #5eaaf6 0%, #4a95de 100%);
    }

    .rte-toolbar-group-items.${h} .rte-toolbar-item:last-child .rte-toolbar-button,
    .editora-toolbar-group-items.${h} .editora-toolbar-item:last-child .editora-toolbar-button,
    .rte-toolbar-group-items.${k} .rte-toolbar-item:last-child .rte-toolbar-button,
    .editora-toolbar-group-items.${k} .editora-toolbar-item:last-child .editora-toolbar-button {
      border-right: none;
    }

    ${g} .rte-toolbar-group-items.${h},
    ${g} .editora-toolbar-group-items.${h},
    ${g} .rte-toolbar-group-items.${k},
    ${g} .editora-toolbar-group-items.${k},
    .${d}.rte-approval-theme-dark {
      border-color: #566275;
    }
    ${g} .rte-toolbar-group-items.${h} .rte-toolbar-button svg,
    ${g} .editora-toolbar-group-items.${h} .editora-toolbar-button svg,
    ${g} .rte-toolbar-group-items.${k} .rte-toolbar-button svg,
    ${g} .editora-toolbar-group-items.${k} .editora-toolbar-button svg
    {
      fill: none;
    }

    ${g} .rte-toolbar-group-items.${h} .rte-toolbar-button,
    ${g} .editora-toolbar-group-items.${h} .editora-toolbar-button
    {
      border-color: #566275;
    }

    .rte-approval-locked-editor {
      background-image: repeating-linear-gradient(
        -45deg,
        rgba(30, 64, 175, 0.04),
        rgba(30, 64, 175, 0.04) 8px,
        rgba(30, 64, 175, 0.08) 8px,
        rgba(30, 64, 175, 0.08) 16px
      );
    }

    .${d} {
      position: fixed;
      z-index: 1500;
      right: 16px;
      top: 16px;
      width: min(420px, calc(100vw - 20px));
      max-height: calc(100vh - 24px);
      display: none;
      flex-direction: column;
      border-radius: 12px;
      border: 1px solid #d1d5db;
      background: #ffffff;
      color: #0f172a;
      box-shadow: 0 18px 38px rgba(15, 23, 42, 0.16);
      overflow: hidden;
    }

    .${d}.show {
      display: flex;
    }

    .${d}.rte-approval-theme-dark {
      background: #0f172a;
      color: #e2e8f0;
      border-color: #334155;
      box-shadow: 0 20px 40px rgba(2, 6, 23, 0.5);
    }

    .rte-approval-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 12px;
      border-bottom: 1px solid #e2e8f0;
      background: #f8fafc;
    }

    .${d}.rte-approval-theme-dark .rte-approval-header {
      border-bottom-color: #334155;
      background: #111827;
    }

    .rte-approval-title {
      margin: 0;
      font-size: 14px;
      font-weight: 700;
    }

    .rte-approval-icon-btn {
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: #0f172a;
      border-radius: 6px;
      cursor: pointer;
      min-width: 34px;
      min-height: 34px;
      width: 34px;
      height: 34px;
      padding: 0;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      line-height: 1;
      font-weight: 600;
    }

    .rte-approval-icon-btn:hover,
    .rte-approval-icon-btn:focus-visible {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

    .${d}.rte-approval-theme-dark .rte-approval-icon-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    .${d}.rte-approval-theme-dark .rte-approval-icon-btn:hover,
    .${d}.rte-approval-theme-dark .rte-approval-icon-btn:focus-visible {
      border-color: #60a5fa;
      box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.24);
    }

    .rte-approval-body {
      display: flex;
      flex-direction: column;
      gap: 10px;
      padding: 12px;
      overflow: auto;
    }

    .rte-approval-summary {
      margin: 0;
      font-size: 12px;
      color: #475569;
    }

    .${d}.rte-approval-theme-dark .rte-approval-summary {
      color: #94a3b8;
    }

    .rte-approval-controls {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }

    .rte-approval-btn {
      border: 1px solid #cbd5e1;
      background: #f8fafc;
      color: inherit;
      border-radius: 8px;
      padding: 6px 10px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
    }

    .rte-approval-btn:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .rte-approval-btn:hover:not(:disabled),
    .rte-approval-btn:focus-visible:not(:disabled) {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
    }

    .rte-approval-btn-primary {
      background: #1d4ed8;
      border-color: #1d4ed8;
      color: #ffffff;
    }

    .rte-approval-btn-primary:hover:not(:disabled),
    .rte-approval-btn-primary:focus-visible:not(:disabled) {
      background: #1e40af;
      border-color: #1e40af;
    }

    .${d}.rte-approval-theme-dark .rte-approval-btn {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .${d}.rte-approval-theme-dark .rte-approval-btn-primary {
      border-color: #2563eb;
      background: #2563eb;
      color: #ffffff;
    }

    .rte-approval-form {
      display: grid;
      grid-template-columns: 1fr;
      gap: 8px;
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 8px;
    }

    .${d}.rte-approval-theme-dark .rte-approval-form {
      border-color: #334155;
    }

    .rte-approval-label {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: 12px;
      font-weight: 600;
    }

    .rte-approval-field {
      width: 100%;
      box-sizing: border-box;
      min-height: 30px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: #ffffff;
      color: inherit;
      font-size: 13px;
      padding: 6px 8px;
    }

    .rte-approval-field:focus-visible {
      outline: none;
      border-color: #1d4ed8;
      box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.2);
    }

    .${d}.rte-approval-theme-dark .rte-approval-field {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .rte-approval-section {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      padding: 8px;
    }

    .${d}.rte-approval-theme-dark .rte-approval-section {
      border-color: #334155;
    }

    .rte-approval-section-title {
      margin: 0 0 8px;
      font-size: 12px;
      font-weight: 700;
    }

    .rte-approval-comments-list,
    .rte-approval-signoffs-list {
      margin: 0;
      padding: 0;
      list-style: none;
      display: flex;
      flex-direction: column;
      gap: 6px;
      max-height: 150px;
      overflow: auto;
    }

    .rte-approval-item {
      border: 1px solid #dbeafe;
      background: #eff6ff;
      border-radius: 8px;
      padding: 6px;
    }

    .rte-approval-item-comment {
      border-color: #e2e8f0;
      background: #f8fafc;
    }

    .${d}.rte-approval-theme-dark .rte-approval-item {
      border-color: #334155;
      background: #111827;
    }

    .rte-approval-item-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 4px;
    }

    .rte-approval-item-author {
      font-size: 12px;
      font-weight: 700;
    }

    .rte-approval-item-time {
      font-size: 11px;
      color: #64748b;
    }

    .${d}.rte-approval-theme-dark .rte-approval-item-time {
      color: #94a3b8;
    }

    .rte-approval-item-message {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      white-space: pre-wrap;
    }

    .rte-approval-empty {
      border: 1px dashed #cbd5e1;
      border-radius: 8px;
      padding: 8px;
      font-size: 12px;
      color: #64748b;
    }

    .${d}.rte-approval-theme-dark .rte-approval-empty {
      border-color: #334155;
      color: #94a3b8;
    }

    .rte-approval-shortcut {
      margin: 0;
      font-size: 11px;
      color: #64748b;
    }

    .${d}.rte-approval-theme-dark .rte-approval-shortcut {
      color: #94a3b8;
    }

    .rte-approval-live {
      position: absolute;
      width: 1px;
      height: 1px;
      margin: -1px;
      padding: 0;
      overflow: hidden;
      clip: rect(0 0 0 0);
      border: 0;
    }

    @media (max-width: 768px) {
      .${d} {
        left: 10px !important;
        right: 10px;
        top: 10px !important;
        width: auto !important;
        max-height: calc(100vh - 20px);
      }
    }
  `, document.head.appendChild(t);
}
const Pt = (t = {}) => {
  const e = z(t);
  return qt(), {
    name: "approvalWorkflow",
    toolbar: [
      {
        id: "approvalWorkflowGroup",
        label: "Approval",
        type: "group",
        command: "approvalWorkflow",
        items: [
          {
            id: "approvalWorkflow",
            label: "Approval Workflow",
            command: "toggleApprovalWorkflowPanel",
            shortcut: "Mod-Alt-Shift-a",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="4" y="5" width="16" height="14" rx="2.5" stroke="currentColor" stroke-width="1.7"/><path d="M8 10h8M8 14h5" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="m16.5 16 1.8 1.8 3.2-3.2" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          },
          {
            id: "approvalRequestReview",
            label: "Request Review",
            command: "requestApprovalReview",
            shortcut: "Mod-Alt-Shift-r",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><circle cx="11" cy="11" r="6.5" stroke="currentColor" stroke-width="1.7"/><path d="M11 8v3l2 2" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M17.5 17.5 20 20" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>'
          },
          {
            id: "approvalApprove",
            label: "Approve",
            command: "approveDocument",
            shortcut: "Mod-Alt-Shift-p",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M5 12.5 9.5 17 19 7.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/><rect x="3.8" y="3.8" width="16.4" height="16.4" rx="3" stroke="currentColor" stroke-width="1.4"/></svg>'
          },
          {
            id: "approvalReopen",
            label: "Reopen Draft",
            command: "reopenDraft",
            shortcut: "Mod-Alt-Shift-d",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M8 8H4v4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M5 12a7 7 0 1 0 2-4.95" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>'
          }
        ]
      }
    ],
    commands: {
      approvalWorkflow: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        return s.set(r, a), f(r, a), v = r, A(r), q(r), !0;
      },
      toggleApprovalWorkflowPanel: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        return s.set(r, a), f(r, a), v = r, ut(r, typeof o == "boolean" ? o : void 0);
      },
      requestApprovalReview: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        s.set(r, a), f(r, a);
        const l = $(r, "review", a, a.defaultActor);
        return A(r), l;
      },
      approveDocument: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        s.set(r, a), f(r, a);
        const l = typeof o == "object" && o ? String(o.author || "") : a.defaultActor, c = typeof o == "object" && o ? String(o.comment || "") : typeof o == "string" ? o : "", u = Z(r, a, l, c);
        return u && A(r), u;
      },
      reopenDraft: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        s.set(r, a), f(r, a);
        const l = $(r, "draft", a, a.defaultActor);
        return l && A(r), l;
      },
      addApprovalComment: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        s.set(r, a), f(r, a);
        const l = typeof o == "object" && o ? String(o.author || "") : a.defaultActor, c = typeof o == "object" && o ? String(o.message || "") : typeof o == "string" ? o : "", u = dt(r, c, l, a);
        return u && A(r), u;
      },
      setApprovalStatus: (o, n) => {
        const r = x(n);
        if (!r || !o) return !1;
        const a = lt(o), l = s.get(r) || e;
        s.set(r, l), f(r, l);
        const c = $(r, a, l, l.defaultActor);
        return c && A(r), c;
      },
      setApprovalWorkflowOptions: (o, n) => {
        const r = x(n);
        if (!r || !o || typeof o != "object") return !1;
        const a = s.get(r) || e, l = z({
          ...a,
          ...o,
          labels: {
            ...a.labels,
            ...o.labels || {}
          },
          normalizeText: o.normalizeText || a.normalizeText
        });
        s.set(r, l);
        const c = f(r, l);
        return G(r, c, l), !0;
      },
      getApprovalWorkflowState: (o, n) => {
        const r = x(n);
        if (!r) return !1;
        const a = s.get(r) || e;
        s.set(r, a);
        const l = f(r, a), c = ct(l);
        if (typeof o == "function")
          try {
            o(c);
          } catch {
          }
        return r.__approvalWorkflowState = c, r.dispatchEvent(
          new CustomEvent("editora:approval-state", {
            bubbles: !0,
            detail: {
              state: c
            }
          })
        ), !0;
      }
    },
    keymap: {
      "Mod-Alt-Shift-a": "toggleApprovalWorkflowPanel",
      "Mod-Alt-Shift-A": "toggleApprovalWorkflowPanel",
      "Mod-Alt-Shift-r": "requestApprovalReview",
      "Mod-Alt-Shift-R": "requestApprovalReview",
      "Mod-Alt-Shift-p": "approveDocument",
      "Mod-Alt-Shift-P": "approveDocument",
      "Mod-Alt-Shift-d": "reopenDraft",
      "Mod-Alt-Shift-D": "reopenDraft"
    },
    init: function(n) {
      _ += 1;
      const r = this && typeof this.__pluginConfig == "object" ? z({ ...e, ...this.__pluginConfig }) : e;
      Mt(r);
      const a = x(
        n?.editorElement ? { editorElement: n.editorElement } : void 0,
        !1
      );
      a && (s.set(a, r), f(a, r), v = a, q(a));
    },
    destroy: () => {
      _ = Math.max(0, _ - 1), !(_ > 0) && Ht();
    }
  };
};
export {
  Pt as ApprovalWorkflowPlugin
};
