const L = ".rte-content, .editora-content", H = '.rte-conditional-block[data-conditional-content="true"]', b = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', f = ':is([data-theme="acme"], .editora-theme-acme, .rte-theme-acme)', p = ":is(.rte-content.rte-conditional-theme-dark, .editora-content.rte-conditional-theme-dark)", h = ":is(.rte-content.rte-conditional-theme-acme, .editora-content.rte-conditional-theme-acme)", Ce = "rte-conditional-content-styles", c = "rte-conditional-dialog-overlay", u = "rte-conditional-floating-toolbar", w = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map();
let le = null, se = 0, G = null, U = null, Y = null, J = null, X = null, Q = null, N = null, g = null, ee = null;
const Pe = {
  dialogTitleInsert: "Insert Conditional Content",
  dialogTitleEdit: "Edit Conditional Content",
  conditionLabel: "Condition",
  conditionPlaceholder: 'user.role == "admin"',
  audienceLabel: "Audience (comma separated)",
  audiencePlaceholder: "all",
  localeLabel: "Locale (comma separated)",
  localePlaceholder: "all",
  elseLabel: "Enable Else Block",
  saveText: "Save",
  cancelText: "Cancel",
  blockIfLabel: "IF",
  blockElseLabel: "ELSE",
  allAudiencesText: "all audiences",
  allLocalesText: "all locales"
};
function y(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function O(e) {
  return e ? e.split(",").map((t) => t.trim()).filter(Boolean) : [];
}
function Le(e) {
  return !e || e.length === 0 ? "" : e.join(", ");
}
function te(e) {
  return e ? e.map((t) => t.trim()).filter(Boolean) : [];
}
function Re(e) {
  return {
    ...Pe,
    ...e || {}
  };
}
function k(e) {
  return e.getAttribute("contenteditable") === "false" || e.getAttribute("data-readonly") === "true";
}
function ce(e) {
  return e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || e;
}
function ue(e) {
  if (!e) return !1;
  const t = e.getAttribute("data-theme") || e.getAttribute("theme");
  return t && t.toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark");
}
function qe(e) {
  const t = ce(e);
  if (ue(t)) return !0;
  const o = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return ue(o) ? !0 : ue(document.documentElement) || ue(document.body);
}
function fe(e) {
  if (!e) return !1;
  const t = e.getAttribute("data-theme") || e.getAttribute("theme");
  return t && t.toLowerCase() === "acme" ? !0 : e.classList.contains("editora-theme-acme") || e.classList.contains("rte-theme-acme");
}
function Ke(e) {
  const t = ce(e);
  if (fe(t)) return !0;
  const o = t.closest("[data-theme], [theme], .editora-theme-acme, .rte-theme-acme");
  return fe(o) ? !0 : fe(document.documentElement) || fe(document.body);
}
function Ie(e) {
  return qe(e) ? "dark" : Ke(e) ? "acme" : "light";
}
function he(e, t) {
  const o = Ie(t);
  e.classList.remove("rte-conditional-theme-dark", "rte-conditional-theme-acme"), o === "dark" ? e.classList.add("rte-conditional-theme-dark") : o === "acme" && e.classList.add("rte-conditional-theme-acme");
}
function A(e, t = !0) {
  if (e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const n = e.editorElement;
    if (n.matches(L)) return n;
    const a = n.querySelector(L);
    if (a instanceof HTMLElement) return a;
  }
  const o = window.getSelection();
  if (o && o.rangeCount > 0) {
    const n = o.getRangeAt(0).startContainer, r = (n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(L);
    if (r) return r;
  }
  const i = document.activeElement;
  if (i) {
    if (i.matches(L)) return i;
    const n = i.closest(L);
    if (n) return n;
  }
  return g && g.isConnected ? g : t ? document.querySelector(L) : null;
}
function ke(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const o = t.getRangeAt(0);
  return e.contains(o.commonAncestorContainer) ? o.cloneRange() : null;
}
function xe(e, t) {
  const o = window.getSelection();
  o && (o.removeAllRanges(), o.addRange(t), e.focus({ preventScroll: !0 }));
}
function Se(e) {
  e.dispatchEvent(new Event("input", { bubbles: !0 }));
}
function Te(e, t) {
  if (t === e.innerHTML) return;
  const o = window.execEditorCommand || window.executeEditorCommand;
  if (typeof o == "function")
    try {
      o("recordDomTransaction", e, t, e.innerHTML);
    } catch {
    }
}
function pe(e, t) {
  const o = document.createRange();
  o.selectNodeContents(t), o.collapse(!1), xe(e, o);
}
function ye(e, t) {
  if (t)
    return t.split(".").filter(Boolean).reduce((o, i) => {
      if (o != null && typeof o == "object")
        return o[i];
    }, e);
}
function _e(e) {
  const t = e.trim();
  if (t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'"))
    return t.slice(1, -1);
  if (t === "true") return !0;
  if (t === "false") return !1;
  if (t === "null") return null;
  const o = Number(t);
  if (!Number.isNaN(o) && t !== "") return o;
  if (t.startsWith("[") && t.endsWith("]") || t.startsWith("{") && t.endsWith("}"))
    try {
      return JSON.parse(t);
    } catch {
      return t;
    }
  return t;
}
function ze(e, t) {
  const o = e.trim();
  if (!o) return !0;
  if (o.startsWith("!")) {
    const E = o.slice(1).trim();
    return !ye(t, E);
  }
  const i = o.match(/^([a-zA-Z_$][\w.$]*)\s*(==|!=|>=|<=|>|<|in|contains|~=)\s*(.+)$/);
  if (!i)
    return !!ye(t, o);
  const [, n, a, r] = i, l = ye(t, n), d = _e(r);
  switch (a) {
    case "==":
      return l == d;
    case "!=":
      return l != d;
    case ">":
      return Number(l) > Number(d);
    case "<":
      return Number(l) < Number(d);
    case ">=":
      return Number(l) >= Number(d);
    case "<=":
      return Number(l) <= Number(d);
    case "in":
      return Array.isArray(d) ? d.some((E) => E == l) : typeof d == "string" ? d.split(",").map((E) => E.trim()).includes(String(l)) : !1;
    case "contains":
    case "~=":
      return Array.isArray(l) ? l.some((E) => String(E).toLowerCase() === String(d).toLowerCase()) : typeof l == "string" ? l.toLowerCase().includes(String(d).toLowerCase()) : !1;
    default:
      return !1;
  }
}
function Fe() {
  if (typeof document > "u" || document.getElementById(Ce)) return;
  const e = document.createElement("style");
  e.id = Ce, e.textContent = `
    .rte-conditional-block {
      border: 1px solid #dbe3ec;
      border-radius: 8px;
      margin: 10px 0;
      background: #f8fafc;
      overflow: hidden;
    }

    .rte-conditional-header,
    .rte-conditional-else-label {
      display: flex;
      align-items: center;
      gap: 8px;
      background: #eef2f7;
      border-bottom: 1px solid #dbe3ec;
      padding: 8px 10px;
      user-select: none;
    }

    .rte-conditional-else-label {
      border-top: 1px solid #dbe3ec;
      border-bottom: 1px solid #dbe3ec;
    }

    .rte-conditional-chip {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 34px;
      height: 20px;
      border-radius: 999px;
      border: 1px solid #bfdbfe;
      background: #dbeafe;
      color: #1e3a8a;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 0.03em;
      text-transform: uppercase;
      padding: 0 7px;
      flex: 0 0 auto;
    }

    .rte-conditional-chip-else {
      border-color: #fecaca;
      background: #fee2e2;
      color: #991b1b;
    }

    .rte-conditional-summary {
      font-size: 12px;
      color: #0f172a;
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      flex: 1;
    }

    .rte-conditional-meta {
      font-size: 11px;
      color: #64748b;
      white-space: nowrap;
      flex: 0 0 auto;
    }

    .rte-conditional-body {
      padding: 10px;
      background: #ffffff;
      min-height: 44px;
    }

    .rte-conditional-hidden {
      display: none !important;
    }

    .rte-toolbar-group-items.conditional-content,
    .editora-toolbar-group-items.conditional-content {
      display: flex;
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      background: #ffffff;
    }

    .rte-toolbar-group-items.conditional-content .rte-toolbar-item,
    .editora-toolbar-group-items.conditional-content .editora-toolbar-item {
      display: flex;
    }

    .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    .editora-toolbar-group-items.conditional-content .editora-toolbar-button {
      border: none;
      border-right: 1px solid #cbd5e1;
      border-radius: 0;
    }

    .rte-toolbar-group-items.conditional-content .rte-toolbar-item:last-child .rte-toolbar-button,
    .editora-toolbar-group-items.conditional-content .editora-toolbar-item:last-child .editora-toolbar-button {
      border-right: none;
    }

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

    .rte-conditional-block.rte-conditional-preview {
      border-style: dashed;
    }

    .rte-conditional-block.rte-conditional-preview .rte-conditional-body[contenteditable="false"] {
      cursor: default;
    }

    .${c} {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.5);
      z-index: 2147483646;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }

    .rte-conditional-dialog {
      width: min(560px, 96vw);
      max-height: min(88vh, 760px);
      border: 1px solid #dbe3ec;
      border-radius: 8px;
      background: #ffffff;
      box-shadow: 0 24px 50px rgba(15, 23, 42, 0.25);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

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

    .rte-conditional-dialog-footer {
      border-top: 1px solid #e2e8f0;
      border-bottom: none;
      justify-content: flex-end;
    }

    .rte-conditional-dialog-title {
      margin: 0;
      font-size: 16px;
      font-weight: 700;
      color: #0f172a;
    }

    .rte-conditional-dialog-body {
      padding: 14px;
      overflow: auto;
      display: grid;
      grid-template-columns: 1fr;
      gap: 12px;
    }

    .rte-conditional-field {
      display: grid;
      gap: 6px;
    }

    .rte-conditional-field label {
      font-size: 12px;
      font-weight: 600;
      color: #334155;
    }

    .rte-conditional-field input[type="text"] {
      width: 100%;
      min-height: 36px;
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      padding: 8px 10px;
      font-size: 13px;
      line-height: 1.4;
      box-sizing: border-box;
      color: #0f172a;
      background: #ffffff;
    }

    .rte-conditional-field input[type="text"]:focus-visible,
    .rte-conditional-btn:focus-visible {
      outline: none;
      border-color: #3b82f6;
      box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
    }

    .rte-conditional-checkbox {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
      color: #334155;
      min-height: 36px;
    }

    .rte-conditional-help {
      margin: 0;
      font-size: 12px;
      color: #64748b;
    }

    .rte-conditional-btn {
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      min-height: 34px;
      padding: 6px 12px;
      background: #ffffff;
      color: #0f172a;
      font-size: 13px;
      cursor: pointer;
    }

    .rte-conditional-btn-primary {
      border-color: #2563eb;
      background: #2563eb;
      color: #ffffff;
    }

    .rte-conditional-btn-primary:hover {
      background: #1d4ed8;
    }

    .${u} {
      position: fixed;
      z-index: 2147483645;
      display: none;
      align-items: center;
      gap: 6px;
      padding: 6px;
      border-radius: 8px;
      border: 1px solid #cbd5e1;
      background: rgba(255, 255, 255, 0.98);
      box-shadow: 0 14px 30px rgba(15, 23, 42, 0.2);
      backdrop-filter: blur(6px);
    }

    .${u}.show {
      display: inline-flex;
    }

    .${u} .rte-conditional-float-btn {
      border: 1px solid #cbd5e1;
      border-radius: 6px;
      min-height: 30px;
      min-width: 30px;
      padding: 0 8px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      background: #ffffff;
      color: #0f172a;
      cursor: pointer;
      font-size: 12px;
      line-height: 1;
    }

    .${u} .rte-conditional-float-btn:hover {
      background: #f8fafc;
    }

    .${u} .rte-conditional-float-btn[data-action="delete"] {
      border-color: #fecaca;
      color: #991b1b;
      background: #fff5f5;
    }

    .rte-conditional-preview-on ${H} {
      border-width: 2px;
    }

    .rte-conditional-preview-on ${H} .rte-conditional-header {
      background: #ecfeff;
      border-color: #bae6fd;
    }

    ${b} .rte-conditional-block,
    ${p} .rte-conditional-block,
    .${c}.rte-conditional-theme-dark .rte-conditional-block {
      background: #111827;
      border-color: #334155;
    }

    ${b} .rte-conditional-header,
    ${b} .rte-conditional-else-label,
    ${p} .rte-conditional-header,
    ${p} .rte-conditional-else-label,
    .${c}.rte-conditional-theme-dark .rte-conditional-header,
    .${c}.rte-conditional-theme-dark .rte-conditional-else-label {
      background: #0f172a;
      border-color: #334155;
    }

    ${b} .rte-conditional-summary,
    ${p} .rte-conditional-summary,
    .${c}.rte-conditional-theme-dark .rte-conditional-summary {
      color: #e2e8f0;
    }

    ${b} .rte-conditional-meta,
    ${p} .rte-conditional-meta,
    .${c}.rte-conditional-theme-dark .rte-conditional-meta {
      color: #94a3b8;
    }

    ${b} .rte-conditional-chip,
    ${p} .rte-conditional-chip,
    .${c}.rte-conditional-theme-dark .rte-conditional-chip {
      background: #1e3a8a;
      border-color: #3b82f6;
      color: #dbeafe;
    }

    ${b} .rte-conditional-chip-else,
    ${p} .rte-conditional-chip-else,
    .${c}.rte-conditional-theme-dark .rte-conditional-chip-else {
      background: #7f1d1d;
      border-color: #ef4444;
      color: #fee2e2;
    }

    ${b} .rte-conditional-body,
    ${p} .rte-conditional-body,
    .${c}.rte-conditional-theme-dark .rte-conditional-body {
      background: #1f2937;
      color: #e2e8f0;
    }

    ${b} .rte-conditional-dialog,
    ${p} .rte-conditional-dialog,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog {
      background: #1f2937;
      border-color: #334155;
    }

    ${b} .rte-conditional-dialog-header,
    ${b} .rte-conditional-dialog-footer,
    ${p} .rte-conditional-dialog-header,
    ${p} .rte-conditional-dialog-footer,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-header,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-footer {
      background: #111827;
      border-color: #334155;
    }

    ${b} .rte-conditional-dialog-title,
    ${b} .rte-conditional-field label,
    ${b} .rte-conditional-checkbox,
    ${p} .rte-conditional-dialog-title,
    ${p} .rte-conditional-field label,
    ${p} .rte-conditional-checkbox,
    .${c}.rte-conditional-theme-dark .rte-conditional-dialog-title,
    .${c}.rte-conditional-theme-dark .rte-conditional-field label,
    .${c}.rte-conditional-theme-dark .rte-conditional-checkbox {
      color: #e2e8f0;
    }

    ${b} .rte-conditional-help,
    ${p} .rte-conditional-help,
    .${c}.rte-conditional-theme-dark .rte-conditional-help {
      color: #94a3b8;
    }

    ${b} .rte-conditional-field input[type="text"],
    ${b} .rte-conditional-btn,
    ${p} .rte-conditional-field input[type="text"],
    ${p} .rte-conditional-btn,
    .${c}.rte-conditional-theme-dark .rte-conditional-field input[type="text"],
    .${c}.rte-conditional-theme-dark .rte-conditional-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    ${b} .rte-conditional-btn-primary,
    ${p} .rte-conditional-btn-primary,
    .${c}.rte-conditional-theme-dark .rte-conditional-btn-primary {
      border-color: #3b82f6;
      background: #2563eb;
      color: #ffffff;
    }

    ${b} .rte-toolbar-group-items.conditional-content,
    .${c}.rte-conditional-theme-dark .rte-toolbar-group-items.conditional-content,
    ${p} .rte-toolbar-group-items.conditional-content,
    ${b} .editora-toolbar-group-items.conditional-content {
      border-color: #566275;
    }

    ${b} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${p} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${b} .editora-toolbar-group-items.conditional-content .editora-toolbar-button {
      border-right-color: #566275;
    }

    ${b} .${u},
    .${c}.rte-conditional-theme-dark .${u},
    .${u}.rte-conditional-theme-dark {
      background: rgba(17, 24, 39, 0.98);
      border-color: #334155;
      box-shadow: 0 14px 30px rgba(2, 6, 23, 0.5);
    }

    ${b} .${u} .rte-conditional-float-btn,
    .${c}.rte-conditional-theme-dark .${u} .rte-conditional-float-btn,
    .${u}.rte-conditional-theme-dark .rte-conditional-float-btn {
      background: #0f172a;
      border-color: #475569;
      color: #e2e8f0;
    }

    ${b} .${u} .rte-conditional-float-btn[data-action="delete"],
    .${c}.rte-conditional-theme-dark .${u} .rte-conditional-float-btn[data-action="delete"],
    .${u}.rte-conditional-theme-dark .rte-conditional-float-btn[data-action="delete"] {
      border-color: #ef4444;
      color: #fecaca;
      background: rgba(127, 29, 29, 0.45);
    }

    ${f} .rte-conditional-block,
    ${h} .rte-conditional-block,
    .${c}.rte-conditional-theme-acme .rte-conditional-block {
      background: #f8fbff;
      border-color: #cbd8e8;
    }

    ${f} .rte-conditional-header,
    ${f} .rte-conditional-else-label,
    ${h} .rte-conditional-header,
    ${h} .rte-conditional-else-label,
    .${c}.rte-conditional-theme-acme .rte-conditional-header,
    .${c}.rte-conditional-theme-acme .rte-conditional-else-label {
      background: linear-gradient(180deg, #eef4fb 0%, #e6eef8 100%);
      border-color: #cbd8e8;
    }

    ${f} .rte-conditional-summary,
    ${h} .rte-conditional-summary,
    .${c}.rte-conditional-theme-acme .rte-conditional-summary {
      color: #0f172a;
    }

    ${f} .rte-conditional-meta,
    ${h} .rte-conditional-meta,
    .${c}.rte-conditional-theme-acme .rte-conditional-meta {
      color: #587089;
    }

    ${f} .rte-conditional-chip,
    ${h} .rte-conditional-chip,
    .${c}.rte-conditional-theme-acme .rte-conditional-chip {
      background: #d9f5ee;
      border-color: #66c6b3;
      color: #0f4f4a;
    }

    ${f} .rte-conditional-chip-else,
    ${h} .rte-conditional-chip-else,
    .${c}.rte-conditional-theme-acme .rte-conditional-chip-else {
      background: #fde8ea;
      border-color: #f1a7b2;
      color: #8b1f2f;
    }

    ${f} .rte-conditional-body,
    ${h} .rte-conditional-body,
    .${c}.rte-conditional-theme-acme .rte-conditional-body {
      background: #fcfeff;
      color: #0f172a;
    }

    ${f} .rte-conditional-dialog,
    ${h} .rte-conditional-dialog,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog {
      background: #ffffff;
      border-color: #cbd8e8;
      box-shadow: 0 20px 44px rgba(15, 23, 42, 0.18);
    }

    ${f} .rte-conditional-dialog-header,
    ${f} .rte-conditional-dialog-footer,
    ${h} .rte-conditional-dialog-header,
    ${h} .rte-conditional-dialog-footer,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-header,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-footer {
      background: #f3f8fd;
      border-color: #d8e4f1;
    }

    ${f} .rte-conditional-dialog-title,
    ${f} .rte-conditional-field label,
    ${f} .rte-conditional-checkbox,
    ${h} .rte-conditional-dialog-title,
    ${h} .rte-conditional-field label,
    ${h} .rte-conditional-checkbox,
    .${c}.rte-conditional-theme-acme .rte-conditional-dialog-title,
    .${c}.rte-conditional-theme-acme .rte-conditional-field label,
    .${c}.rte-conditional-theme-acme .rte-conditional-checkbox {
      color: #1f334a;
    }

    ${f} .rte-conditional-help,
    ${h} .rte-conditional-help,
    .${c}.rte-conditional-theme-acme .rte-conditional-help {
      color: #5f738d;
    }

    ${f} .rte-conditional-field input[type="text"],
    ${f} .rte-conditional-btn,
    ${h} .rte-conditional-field input[type="text"],
    ${h} .rte-conditional-btn,
    .${c}.rte-conditional-theme-acme .rte-conditional-field input[type="text"],
    .${c}.rte-conditional-theme-acme .rte-conditional-btn {
      background: #ffffff;
      border-color: #bfd0e2;
      color: #0f172a;
    }

    ${f} .rte-conditional-btn-primary,
    ${h} .rte-conditional-btn-primary,
    .${c}.rte-conditional-theme-acme .rte-conditional-btn-primary {
      border-color: #0f766e;
      background: #0f766e;
      color: #ffffff;
    }

    ${f} .rte-toolbar-group-items.conditional-content,
    .${c}.rte-conditional-theme-acme .rte-toolbar-group-items.conditional-content,
    ${h} .rte-toolbar-group-items.conditional-content,
    ${f} .editora-toolbar-group-items.conditional-content {
      border-color: #bfd0e2;
    }

    ${f} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${h} .rte-toolbar-group-items.conditional-content .rte-toolbar-button,
    ${f} .editora-toolbar-group-items.conditional-content .editora-toolbar-button {
      border-right-color: #bfd0e2;
    }

    ${f} .${u},
    .${c}.rte-conditional-theme-acme .${u},
    .${u}.rte-conditional-theme-acme {
      background: rgba(255, 255, 255, 0.98);
      border-color: #bfd0e2;
      box-shadow: 0 14px 28px rgba(15, 23, 42, 0.16);
    }

    ${f} .${u} .rte-conditional-float-btn,
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn,
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn {
      background: #ffffff;
      border-color: #bfd0e2;
      color: #1f334a;
    }

    ${f} .${u} .rte-conditional-float-btn:hover,
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn:hover,
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn:hover {
      background: #eef7f5;
      color: #0f4f4a;
    }

    ${f} .${u} .rte-conditional-float-btn[data-action="delete"],
    .${c}.rte-conditional-theme-acme .${u} .rte-conditional-float-btn[data-action="delete"],
    .${u}.rte-conditional-theme-acme .rte-conditional-float-btn[data-action="delete"] {
      border-color: #f1a7b2;
      color: #8b1f2f;
      background: #fff4f6;
    }
  `, document.head.appendChild(e);
}
function je(e) {
  return {
    defaultCondition: e.defaultCondition || "",
    defaultAudience: te(e.defaultAudience || []),
    defaultLocale: te(e.defaultLocale || []),
    enableElseByDefault: e.enableElseByDefault === !0,
    labels: Re(e.labels),
    context: e.context,
    getContext: e.getContext,
    currentAudience: e.currentAudience,
    currentLocale: e.currentLocale,
    evaluateCondition: e.evaluateCondition || ze
  };
}
function Be() {
  le && (le.cleanup(), le = null);
}
function Ve(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function oe(e, t) {
  e.setAttribute("contenteditable", "false"), e.setAttribute("spellcheck", "false");
  const o = e.querySelector(".rte-conditional-header");
  o && (o.setAttribute("contenteditable", "false"), o.setAttribute("tabindex", "0"), o.setAttribute("role", "button"), o.setAttribute("aria-label", "Edit conditional rule"));
  const i = e.querySelector(".rte-conditional-else-label");
  i && i.setAttribute("contenteditable", "false"), Ge(e, !t);
}
function We(e) {
  const t = e.querySelector('.rte-conditional-body[data-slot="if"]');
  if (!t) return;
  const o = /* @__PURE__ */ new Set(), i = e.querySelector(".rte-conditional-header"), n = e.querySelector(".rte-conditional-else-label"), a = e.querySelector('.rte-conditional-body[data-slot="else"]');
  i && o.add(i), o.add(t), n && o.add(n), a && o.add(a), Array.from(e.childNodes).forEach((l) => {
    if (!(l instanceof HTMLElement && o.has(l))) {
      if (l.nodeType === Node.TEXT_NODE && !(l.textContent || "").trim()) {
        l.remove();
        return;
      }
      t.appendChild(l);
    }
  });
}
function W(e) {
  const t = window.getSelection();
  if (t && t.rangeCount > 0) {
    const n = t.getRangeAt(0).startContainer, r = (n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement)?.closest(H);
    if (r && e.contains(r)) return r;
  }
  const i = document.activeElement?.closest(H);
  return i && e.contains(i) ? i : null;
}
function Ee(e, t) {
  let o = e.querySelector(".rte-conditional-else-label"), i = e.querySelector('.rte-conditional-body[data-slot="else"]');
  o || (o = document.createElement("div"), o.className = "rte-conditional-else-label", o.setAttribute("contenteditable", "false"), o.innerHTML = `
      <span class="rte-conditional-chip rte-conditional-chip-else">${y(t.blockElseLabel)}</span>
      <span class="rte-conditional-summary">Else branch</span>
    `, e.appendChild(o)), i || (i = document.createElement("div"), i.className = "rte-conditional-body rte-conditional-else-body", i.setAttribute("data-slot", "else"), i.innerHTML = "<p><br></p>", e.appendChild(i));
}
function Ze(e, t) {
  e.setAttribute("data-has-else", t ? "true" : "false");
  const o = e.querySelector(".rte-conditional-else-label"), i = e.querySelector('.rte-conditional-body[data-slot="else"]');
  o && o.classList.toggle("rte-conditional-hidden", !t), i && i.classList.toggle("rte-conditional-hidden", !t);
}
function Ge(e, t) {
  Array.from(e.querySelectorAll(".rte-conditional-body")).forEach((i) => {
    i.setAttribute("contenteditable", t ? "true" : "false");
  }), e.setAttribute("contenteditable", "false");
}
function ve(e, t) {
  const o = e.getAttribute("data-condition") || "", i = O(e.getAttribute("data-audience")), n = O(e.getAttribute("data-locale"));
  let a = e.querySelector(".rte-conditional-header");
  a || (a = document.createElement("div"), a.className = "rte-conditional-header", e.prepend(a)), a.setAttribute("contenteditable", "false"), a.setAttribute("tabindex", "0"), a.setAttribute("role", "button"), a.setAttribute("aria-label", "Edit conditional rule");
  const r = o || "(always true)", l = i.length > 0 ? i.join(", ") : t.allAudiencesText, d = n.length > 0 ? n.join(", ") : t.allLocalesText;
  if (a.innerHTML = `
    <span class="rte-conditional-chip">${y(t.blockIfLabel)}</span>
    <span class="rte-conditional-summary">${y(r)}</span>
    <span class="rte-conditional-meta">${y(l)} · ${y(d)}</span>
  `, !e.querySelector('.rte-conditional-body[data-slot="if"]')) {
    const v = document.createElement("div");
    v.className = "rte-conditional-body", v.setAttribute("data-slot", "if"), v.innerHTML = "<p><br></p>", e.insertBefore(v, e.children[1] || null);
  }
  const m = e.getAttribute("data-has-else") === "true";
  m && Ee(e, t), We(e), Ze(e, m);
}
function Me(e, t) {
  const o = document.createElement("section");
  o.className = "rte-conditional-block", o.setAttribute("data-conditional-content", "true"), o.setAttribute("data-condition", (e.condition || "").trim()), o.setAttribute("data-audience", te(e.audience).join(",")), o.setAttribute("data-locale", te(e.locale).join(",")), o.setAttribute("data-has-else", e.hasElse ? "true" : "false"), o.setAttribute("role", "group"), o.setAttribute("aria-label", "Conditional content block"), o.setAttribute("contenteditable", "false"), o.setAttribute("spellcheck", "false");
  const i = document.createElement("div");
  i.className = "rte-conditional-header", i.setAttribute("contenteditable", "false");
  const n = document.createElement("div");
  return n.className = "rte-conditional-body", n.setAttribute("data-slot", "if"), n.innerHTML = "<p><br></p>", o.appendChild(i), o.appendChild(n), e.hasElse && Ee(o, t), ve(o, t), oe(o, !1), o;
}
function Ue(e, t) {
  if (t)
    try {
      if (!e.isConnected) return;
      const o = e.contains(t.startContainer), i = e.contains(t.endContainer);
      if (!o || !i) return;
      xe(e, t);
    } catch {
    }
}
function Ye(e) {
  return (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !0 : e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol") !== null;
}
function Ne(e, t, o) {
  let i = null;
  i || (i = ke(e)), i || (i = document.createRange(), i.selectNodeContents(e), i.collapse(!1));
  let n = null;
  i.collapsed || (n = i.extractContents()), i.insertNode(t);
  const a = t.querySelector('.rte-conditional-body[data-slot="if"]');
  a && n && Ye(n) && (a.innerHTML = "", a.appendChild(n)), a ? pe(e, a) : pe(e, t), e.normalize();
}
function Je(e) {
  return {
    condition: e.getAttribute("data-condition") || "",
    audience: O(e.getAttribute("data-audience")),
    locale: O(e.getAttribute("data-locale")),
    hasElse: e.getAttribute("data-has-else") === "true"
  };
}
function Xe(e, t, o) {
  e.setAttribute("data-condition", (t.condition || "").trim()), e.setAttribute("data-audience", te(t.audience).join(",")), e.setAttribute("data-locale", te(t.locale).join(",")), e.setAttribute("data-has-else", t.hasElse ? "true" : "false"), t.hasElse && Ee(e, o), ve(e, o), oe(e, e.classList.contains("rte-conditional-preview"));
}
function ne(e, t) {
  he(e, e);
  const o = Array.from(e.querySelectorAll(H)), i = w.get(e) === !0;
  return o.forEach((n) => {
    n.classList.add("rte-conditional-block"), n.setAttribute("data-conditional-content", "true"), n.hasAttribute("data-condition") || n.setAttribute("data-condition", ""), n.hasAttribute("data-audience") || n.setAttribute("data-audience", ""), n.hasAttribute("data-locale") || n.setAttribute("data-locale", ""), n.hasAttribute("data-has-else") || n.setAttribute("data-has-else", "false"), n.setAttribute("role", "group"), n.setAttribute("aria-label", "Conditional content block"), n.setAttribute("contenteditable", "false"), n.setAttribute("spellcheck", "false"), ve(n, t), oe(n, i);
  }), o;
}
async function Qe(e, t) {
  const o = $e.get(e);
  if (o)
    return o;
  if (typeof t.getContext == "function")
    try {
      const i = ce(e), n = await Promise.resolve(t.getContext({ editor: e, editorRoot: i }));
      if (n && typeof n == "object")
        return n;
    } catch {
      return {};
    }
  if (typeof t.context == "function")
    try {
      const i = t.context();
      if (i && typeof i == "object")
        return i;
    } catch {
      return {};
    }
  return t.context && typeof t.context == "object" ? t.context : {};
}
function be(e) {
  return Array.isArray(e) ? e.map((t) => t.trim().toLowerCase()).filter(Boolean) : typeof e == "string" ? e.split(",").map((t) => t.trim().toLowerCase()).filter(Boolean) : [];
}
function Ae(e, t) {
  return e.length === 0 || e.includes("all") ? !0 : t.length === 0 ? !1 : e.some((o) => t.includes(o));
}
async function Z(e, t, o) {
  const i = t.labels, n = ne(e, i);
  if (w.set(e, o), De(e, o), ce(e).classList.toggle("rte-conditional-preview-on", o), !o) {
    n.forEach(($) => {
      $.classList.remove("rte-conditional-preview"), oe($, !1);
      const P = $.querySelector('.rte-conditional-body[data-slot="if"]'), T = $.querySelector('.rte-conditional-body[data-slot="else"]'), F = $.querySelector(".rte-conditional-else-label"), B = $.getAttribute("data-has-else") === "true";
      P && (P.classList.remove("rte-conditional-hidden"), P.removeAttribute("aria-hidden")), T && (T.classList.toggle("rte-conditional-hidden", !B), T.setAttribute("aria-hidden", B ? "false" : "true")), F && F.classList.toggle("rte-conditional-hidden", !B);
    });
    return;
  }
  const r = await Qe(e, t), l = be(t.currentAudience), d = be(t.currentLocale), E = be(
    r.audience ?? r.user?.audience
  ), m = be(
    r.locale ?? r.user?.locale
  ), v = l.length > 0 ? l : E, S = d.length > 0 ? d : m;
  n.forEach(($) => {
    const P = $.getAttribute("data-condition") || "", T = O($.getAttribute("data-audience")).map((s) => s.toLowerCase()), F = O($.getAttribute("data-locale")).map((s) => s.toLowerCase()), B = $.getAttribute("data-has-else") === "true", ge = t.evaluateCondition(P, r), M = Ae(T, v), de = Ae(F, S), R = ge && M && de, ie = $.querySelector('.rte-conditional-body[data-slot="if"]'), j = $.querySelector('.rte-conditional-body[data-slot="else"]'), ae = $.querySelector(".rte-conditional-else-label");
    if ($.classList.add("rte-conditional-preview"), oe($, !0), ie && (ie.classList.toggle("rte-conditional-hidden", !R), ie.setAttribute("aria-hidden", R ? "false" : "true")), j) {
      const s = B && !R;
      j.classList.toggle("rte-conditional-hidden", !s), j.setAttribute("aria-hidden", s ? "false" : "true");
    }
    if (ae) {
      const s = B && !R;
      ae.classList.toggle("rte-conditional-hidden", !s);
    }
  });
}
function De(e, t) {
  const o = ce(e);
  Array.from(
    o.querySelectorAll('[data-command="toggleConditionalPreview"], [data-command="conditionalPreview"]')
  ).forEach((n) => {
    n.setAttribute("data-active", t ? "true" : "false"), n.classList.toggle("active", t), n.setAttribute("aria-pressed", t ? "true" : "false");
  });
}
function et(e) {
  const t = _.get(e);
  if (t && t.isConnected) return t;
  const o = document.createElement("div");
  return o.className = u, o.setAttribute("role", "toolbar"), o.setAttribute("aria-label", "Conditional block actions"), o.innerHTML = `
    <button type="button" class="rte-conditional-float-btn" data-action="edit" title="Edit Condition" aria-label="Edit Condition">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 17.3V20h2.7l9.7-9.7-2.7-2.7L4 17.3Zm14.7-9.4a1 1 0 0 0 0-1.4l-1.2-1.2a1 1 0 0 0-1.4 0l-1.1 1.1 2.7 2.7 1-1.2Z" fill="currentColor"></path></svg>
    </button>
    <button type="button" class="rte-conditional-float-btn" data-action="delete" title="Delete Block" aria-label="Delete Block">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M8 4h8l1 2h4v2H3V6h4l1-2Zm1 6h2v8H9v-8Zm4 0h2v8h-2v-8Z" fill="currentColor"></path></svg>
    </button>
  `, o.addEventListener("mousedown", (i) => {
    i.preventDefault();
  }), o.addEventListener("click", (i) => {
    const a = i.target?.closest("[data-action]")?.getAttribute("data-action");
    if (!a) return;
    const r = x.get(e) || ee;
    if (!r) return;
    const l = z.get(e);
    if (!(!l || !e.contains(l))) {
      if (a === "edit") {
        C(e, r, "edit", void 0, l);
        return;
      }
      a === "delete" && (Oe(e, l), z.set(e, null), I(e));
    }
  }), document.body.appendChild(o), _.set(e, o), o;
}
function I(e) {
  const t = _.get(e);
  t && t.classList.remove("show");
}
function He(e, t) {
  const o = t.getBoundingClientRect();
  e.style.left = "0px", e.style.top = "0px", e.classList.add("show");
  const i = e.getBoundingClientRect(), n = 8, a = window.innerWidth, r = window.innerHeight;
  let l = o.top - i.height - n;
  l < n && (l = o.bottom + n), l = Math.min(l, r - i.height - n);
  let d = o.right - i.width;
  d = Math.max(n, Math.min(d, a - i.width - n)), e.style.left = `${d}px`, e.style.top = `${l}px`;
}
function me(e, t) {
  const o = et(e);
  he(o, e), z.set(e, t), He(o, t);
}
function D(e) {
  const t = x.get(e) || ee;
  if (!t) return;
  const o = W(e);
  if (!o || !e.contains(o) || k(e)) {
    z.set(e, null), I(e);
    return;
  }
  ne(e, t.labels), me(e, o);
}
function tt() {
  _.forEach((e, t) => {
    if (!t.isConnected || !e.isConnected) {
      e.remove(), _.delete(t), z.delete(t);
      return;
    }
    if (!e.classList.contains("show")) return;
    he(e, t);
    const o = z.get(t);
    if (!o || !t.contains(o)) {
      I(t);
      return;
    }
    He(e, o);
  });
}
function Oe(e, t) {
  if (!e.contains(t)) return !1;
  const o = e.innerHTML, i = t.parentNode, n = t.nextSibling;
  t.remove(), i === e && e.innerHTML.trim() === "" && (e.innerHTML = "<p><br></p>");
  const a = document.createRange();
  return n && e.contains(n) ? a.setStartBefore(n) : (a.selectNodeContents(e), a.collapse(!1)), a.collapse(!0), xe(e, a), Se(e), Te(e, o), !0;
}
function we(e, t, o) {
  const i = e.cloneRange(), n = document.createRange();
  return n.selectNodeContents(t), n.collapse(o === "start"), i.startContainer === n.startContainer && i.startOffset === n.startOffset && i.endContainer === n.endContainer && i.endOffset === n.endOffset;
}
function C(e, t, o, i, n) {
  Be();
  const a = t.labels, r = o === "insert" ? ke(e) : null, l = document.createElement("div");
  l.className = c, he(l, e);
  const d = document.createElement("section");
  d.className = "rte-conditional-dialog", d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-labelledby", "rte-conditional-dialog-title");
  const E = n ? Je(n) : void 0, m = i || E || {}, v = m.condition ?? t.defaultCondition, S = m.audience ?? t.defaultAudience, $ = m.locale ?? t.defaultLocale, P = m.hasElse ?? t.enableElseByDefault;
  d.innerHTML = `
    <header class="rte-conditional-dialog-header">
      <h2 id="rte-conditional-dialog-title" class="rte-conditional-dialog-title">${y(
    o === "edit" ? a.dialogTitleEdit : a.dialogTitleInsert
  )}</h2>
      <button type="button" class="rte-conditional-btn" data-action="cancel" aria-label="${y(a.cancelText)}">✕</button>
    </header>
    <div class="rte-conditional-dialog-body">
      <div class="rte-conditional-field">
        <label for="rte-conditional-condition">${y(a.conditionLabel)}</label>
        <input id="rte-conditional-condition" class="rte-conditional-input-condition" type="text" value="${y(
    v || ""
  )}" placeholder="${y(a.conditionPlaceholder)}" />
      </div>
      <div class="rte-conditional-field">
        <label for="rte-conditional-audience">${y(a.audienceLabel)}</label>
        <input id="rte-conditional-audience" class="rte-conditional-input-audience" type="text" value="${y(
    Le(S)
  )}" placeholder="${y(a.audiencePlaceholder)}" />
      </div>
      <div class="rte-conditional-field">
        <label for="rte-conditional-locale">${y(a.localeLabel)}</label>
        <input id="rte-conditional-locale" class="rte-conditional-input-locale" type="text" value="${y(
    Le($)
  )}" placeholder="${y(a.localePlaceholder)}" />
      </div>
      <label class="rte-conditional-checkbox">
        <input class="rte-conditional-input-else" type="checkbox" ${P ? "checked" : ""} />
        <span>${y(a.elseLabel)}</span>
      </label>
      <p class="rte-conditional-help">Example condition: <code>user.role == "admin"</code>, <code>locale == "en-US"</code>, <code>!feature.beta</code></p>
    </div>
    <footer class="rte-conditional-dialog-footer">
      <button type="button" class="rte-conditional-btn" data-action="cancel">${y(a.cancelText)}</button>
      <button type="button" class="rte-conditional-btn rte-conditional-btn-primary" data-action="save">${y(a.saveText)}</button>
    </footer>
  `, l.appendChild(d), document.body.appendChild(l);
  const T = d.querySelector(".rte-conditional-input-condition"), F = d.querySelector(".rte-conditional-input-audience"), B = d.querySelector(".rte-conditional-input-locale"), ge = d.querySelector(".rte-conditional-input-else"), M = () => {
    l.removeEventListener("click", R), l.removeEventListener("keydown", ae, !0), document.removeEventListener("keydown", de, !0), l.parentNode && l.parentNode.removeChild(l), le = null, e.focus({ preventScroll: !0 }), D(e);
  }, de = (s) => {
    s.key === "Escape" && (s.preventDefault(), s.stopPropagation(), M());
  }, R = (s) => {
    s.target === l && M();
  }, ie = (s) => {
    if (s.key !== "Tab") return;
    const q = Array.from(
      d.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')
    );
    if (q.length === 0) return;
    const V = q[0], K = q[q.length - 1], re = document.activeElement;
    if (s.shiftKey && re === V) {
      s.preventDefault(), K.focus();
      return;
    }
    !s.shiftKey && re === K && (s.preventDefault(), V.focus());
  }, j = async () => {
    const s = {
      condition: T?.value?.trim() || "",
      audience: O(F?.value),
      locale: O(B?.value),
      hasElse: ge?.checked || !1
    }, q = e.innerHTML;
    if (n)
      Xe(n, s, a), oe(n, w.get(e) === !0);
    else {
      Ue(e, r);
      const K = Me(s, a);
      try {
        Ne(e, K);
      } catch {
        e.appendChild(K);
        const re = K.querySelector('.rte-conditional-body[data-slot="if"]');
        re ? pe(e, re) : pe(e, K);
      }
    }
    w.get(e) === !0 && await Z(e, t, !0), Se(e), Te(e, q), D(e), M();
  }, ae = (s) => {
    if (s.key === "Escape") {
      s.preventDefault(), M();
      return;
    }
    ie(s), s.key === "Enter" && !s.shiftKey && s.target instanceof HTMLInputElement && (s.preventDefault(), j());
  };
  d.addEventListener("click", (s) => {
    const V = s.target.getAttribute("data-action");
    if (V === "cancel") {
      M();
      return;
    }
    V === "save" && j();
  }), l.addEventListener("click", R), l.addEventListener("keydown", ae, !0), document.addEventListener("keydown", de, !0), le = { cleanup: M }, T?.focus();
}
function ot(e) {
  const t = e.metaKey || e.ctrlKey, i = (typeof e.key == "string" ? e.key : "").toLowerCase(), n = typeof e.code == "string" ? e.code.toLowerCase() : "", a = t && e.altKey && e.shiftKey && (i === "c" || n === "keyc"), r = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (i === "f9" || n === "f9");
  return a || r;
}
function nt(e) {
  const t = e.metaKey || e.ctrlKey, i = (typeof e.key == "string" ? e.key : "").toLowerCase(), n = typeof e.code == "string" ? e.code.toLowerCase() : "", a = t && e.altKey && e.shiftKey && (i === "p" || n === "keyp"), r = !e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey && (i === "f10" || n === "f10");
  return a || r;
}
function it(e) {
  ee = e, U || (U = (t) => {
    const i = t.target?.closest(L);
    if (!i) return;
    g = i, x.has(i) || x.set(i, e);
    const n = x.get(i) || e;
    ne(i, n.labels), De(i, w.get(i) === !0), D(i);
  }, document.addEventListener("focusin", U, !0)), G || (G = (t) => {
    if (document.querySelector(`.${c}`)) return;
    const i = t.target;
    if (!!i?.closest("input, textarea, select")) return;
    const r = i?.closest(L) || A(void 0, !1) || g;
    if (!r || k(r)) return;
    const l = x.get(r) || ee || e, d = document.activeElement, E = i?.closest(".rte-conditional-header") || d?.closest(".rte-conditional-header");
    if (E && (t.key === "Enter" || t.key === " ")) {
      const m = E.closest(H);
      if (m && r.contains(m)) {
        t.preventDefault(), t.stopPropagation(), C(r, l, "edit", void 0, m);
        return;
      }
    }
    if (ot(t)) {
      t.preventDefault(), t.stopPropagation();
      const m = W(r);
      m ? C(r, l, "edit", void 0, m) : C(r, l, "insert");
      return;
    }
    if (nt(t)) {
      t.preventDefault(), t.stopPropagation();
      const m = w.get(r) !== !0;
      Z(r, l, m), D(r);
      return;
    }
    if ((t.key === "Backspace" || t.key === "Delete") && !t.altKey && !t.ctrlKey && !t.metaKey) {
      const m = window.getSelection();
      if (!m || m.rangeCount === 0) return;
      const v = m.getRangeAt(0);
      if (!v.collapsed || !r.contains(v.commonAncestorContainer)) return;
      const S = Ve(v.startContainer)?.closest(".rte-conditional-body");
      if (!S || !r.contains(S)) return;
      if (t.key === "Backspace" && we(v, S, "start")) {
        t.preventDefault();
        return;
      }
      if (t.key === "Delete" && we(v, S, "end")) {
        t.preventDefault();
        return;
      }
    }
  }, document.addEventListener("keydown", G, !0)), J || (J = (t) => {
    const o = t.target;
    if (!o || o.closest(`.${u}`)) return;
    const i = o.closest(L);
    if (!i) {
      g && I(g);
      return;
    }
    if (k(i)) return;
    g = i, x.has(i) || x.set(i, e);
    const n = o.closest(H);
    if (!n) {
      I(i);
      return;
    }
    requestAnimationFrame(() => {
      !i.isConnected || !i.contains(n) || me(i, n);
    });
  }, document.addEventListener("mousedown", J, !0)), Y || (Y = (t) => {
    const o = t.target;
    if (!o || o.closest(`.${u}`)) return;
    const i = o.closest(L);
    if (!i) {
      g && I(g);
      return;
    }
    if (k(i)) return;
    g = i, x.has(i) || x.set(i, e);
    const n = x.get(i) || e, a = o.closest(H), r = !!o.closest(".rte-conditional-header, .rte-conditional-summary, .rte-conditional-meta, .rte-conditional-else-label");
    if (a && r) {
      t.preventDefault(), t.stopPropagation(), C(i, n, "edit", void 0, a), me(i, a);
      return;
    }
    a ? me(i, a) : I(i);
  }, document.addEventListener("click", Y, !0)), X || (X = () => {
    const t = A(void 0, !1) || g;
    t && t.isConnected && D(t);
  }, document.addEventListener("selectionchange", X)), Q || (Q = (t) => {
    const i = t.target?.closest(L);
    if (!i) return;
    const n = x.get(i) || ee || e;
    ne(i, n.labels), D(i);
  }, document.addEventListener("input", Q, !0)), N || (N = () => {
    tt();
  }, window.addEventListener("scroll", N, !0), window.addEventListener("resize", N));
}
function at() {
  U && (document.removeEventListener("focusin", U, !0), U = null), G && (document.removeEventListener("keydown", G, !0), G = null), Y && (document.removeEventListener("click", Y, !0), Y = null), J && (document.removeEventListener("mousedown", J, !0), J = null), X && (document.removeEventListener("selectionchange", X), X = null), Q && (document.removeEventListener("input", Q, !0), Q = null), N && (window.removeEventListener("scroll", N, !0), window.removeEventListener("resize", N), N = null), _.forEach((e) => {
    e.remove();
  }), _.clear(), z.clear(), ee = null, g = null;
}
const rt = (e = {}) => {
  const t = je(e);
  return Fe(), {
    name: "conditionalContent",
    toolbar: [
      {
        id: "conditionalContentGroup",
        label: "Conditional Content",
        type: "group",
        command: "conditionalContent",
        items: [
          {
            id: "conditionalContent",
            label: "Conditional Rule",
            command: "openConditionalDialog",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M6 5h12a1 1 0 0 1 1 1v3h-2V7H7v3H5V6a1 1 0 0 1 1-1Zm-1 9h2v3h10v-3h2v4a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-4Zm3-2a1 1 0 0 1 1-1h2.6l1.8-2.4a1 1 0 1 1 1.6 1.2L13.8 11H15a1 1 0 1 1 0 2h-2.7l-1.9 2.5a1 1 0 1 1-1.6-1.2L10.1 13H9a1 1 0 0 1-1-1Z" fill="currentColor"></path></svg>',
            shortcut: "Mod-Alt-Shift-c"
          },
          {
            id: "conditionalPreview",
            label: "Conditional Preview",
            command: "toggleConditionalPreview",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 6h16a1 1 0 0 1 1 1v3h-2V8H5v8h14v-2h2v3a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1Zm5 3h2v2H9V9Zm0 4h2v2H9v-2Zm4-4h6v2h-6V9Zm0 4h6v2h-6v-2Z" fill="currentColor"></path></svg>',
            shortcut: "Mod-Alt-Shift-p"
          }
        ]
      }
    ],
    commands: {
      conditionalContent: (o, i) => {
        const n = A(i);
        if (!n || k(n)) return !1;
        g = n, x.set(n, t), ne(n, t.labels);
        const a = o?.target;
        if (a === "insert")
          return C(n, t, "insert", o), !0;
        const r = W(n);
        return a === "edit" || r ? !r && a === "edit" ? !1 : (C(n, t, "edit", o, r || void 0), !0) : (C(n, t, "insert", o), !0);
      },
      openConditionalDialog: (o, i) => {
        const n = A(i);
        if (!n || k(n)) return !1;
        g = n, x.set(n, t), ne(n, t.labels);
        const a = o?.target;
        if (a === "insert")
          return C(n, t, "insert", o), !0;
        const r = W(n);
        return a === "edit" || r ? !r && a === "edit" ? !1 : (C(n, t, "edit", o, r || void 0), !0) : (C(n, t, "insert", o), !0);
      },
      conditionalPreview: async (o, i) => {
        const n = A(i);
        if (!n) return !1;
        g = n, x.set(n, t);
        const a = typeof o == "boolean" ? o : w.get(n) !== !0;
        return await Z(n, t, a), D(n), !0;
      },
      editConditionalBlock: (o, i) => {
        const n = A(i);
        if (!n || k(n)) return !1;
        g = n, x.set(n, t);
        const a = W(n);
        return a ? (C(n, t, "edit", o, a), !0) : !1;
      },
      deleteConditionalBlock: (o, i) => {
        const n = A(i);
        if (!n || k(n)) return !1;
        const a = W(n);
        if (!a) return !1;
        const r = Oe(n, a);
        return r && D(n), r;
      },
      insertConditionalBlock: (o, i) => {
        const n = A(i);
        if (!n || k(n)) return !1;
        g = n, x.set(n, t);
        const a = {
          condition: o?.condition ?? t.defaultCondition,
          audience: o?.audience ?? t.defaultAudience,
          locale: o?.locale ?? t.defaultLocale,
          hasElse: o?.hasElse ?? t.enableElseByDefault
        }, r = Me(a, t.labels);
        return Ne(n, r), w.get(n) === !0 && Z(n, t, !0), !0;
      },
      toggleConditionalPreview: async (o, i) => {
        const n = A(i);
        if (!n) return !1;
        g = n, x.set(n, t);
        const a = typeof o == "boolean" ? o : w.get(n) !== !0;
        return await Z(n, t, a), !0;
      },
      setConditionalContext: (o, i) => {
        const n = A(i);
        return n ? (g = n, !o || typeof o != "object" ? $e.delete(n) : $e.set(n, o), w.get(n) === !0 && Z(n, t, !0), !0) : !1;
      }
    },
    keymap: {
      "Mod-Alt-Shift-c": "openConditionalDialog",
      "Mod-Alt-Shift-C": "openConditionalDialog",
      "Mod-Alt-Shift-p": "toggleConditionalPreview",
      "Mod-Alt-Shift-P": "toggleConditionalPreview",
      F9: "openConditionalDialog",
      F10: "toggleConditionalPreview"
    },
    init: () => {
      se += 1, it(t);
    },
    destroy: () => {
      se = Math.max(0, se - 1), se === 0 && (Be(), at());
    }
  };
};
export {
  rt as ConditionalContentPlugin
};
