const S = ".rte-content, .editora-content", ke = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", ve = "__editoraCommandEditorRoot", $e = "rte-translation-workflow-styles", u = "rte-translation-workflow-panel", y = "translation-workflow", $ = "translationWorkflow", h = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', Ee = [
  "p",
  "h1",
  "h2",
  "h3",
  "h4",
  "h5",
  "h6",
  "li",
  "td",
  "th",
  "blockquote",
  "figcaption"
].join(", "), Ce = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "Home", "End"]), Ae = [
  {
    locale: "en",
    label: "English",
    minLengthRatio: 0.6,
    maxLengthRatio: 1.4,
    requireDifferentFromSource: !1,
    preserveTokens: !0
  },
  {
    locale: "fr",
    label: "French",
    minLengthRatio: 0.75,
    maxLengthRatio: 1.7,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  },
  {
    locale: "de",
    label: "German",
    minLengthRatio: 0.8,
    maxLengthRatio: 1.9,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  },
  {
    locale: "es",
    label: "Spanish",
    minLengthRatio: 0.7,
    maxLengthRatio: 1.7,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  },
  {
    locale: "it",
    label: "Italian",
    minLengthRatio: 0.7,
    maxLengthRatio: 1.7,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  },
  {
    locale: "ja",
    label: "Japanese",
    minLengthRatio: 0.45,
    maxLengthRatio: 1.2,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  },
  {
    locale: "zh",
    label: "Chinese",
    minLengthRatio: 0.4,
    maxLengthRatio: 1.2,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  }
], _e = {
  panelTitle: "Translation Workflow",
  panelAriaLabel: "Translation workflow panel",
  sourceLocaleLabel: "Source Locale",
  targetLocaleLabel: "Target Locale",
  validateText: "Validate Locale",
  captureSourceText: "Capture Source",
  lockSelectedText: "Lock Selected",
  unlockSelectedText: "Unlock Selected",
  lockSegmentAriaLabel: "Lock segment",
  unlockSegmentAriaLabel: "Unlock segment",
  realtimeOnText: "Realtime On",
  realtimeOffText: "Realtime Off",
  closeText: "Close",
  summaryPrefix: "Locale QA",
  noIssuesText: "No locale validation issues.",
  issuesLabel: "Locale issues",
  segmentsLabel: "Segments",
  sourcePreviewLabel: "Source",
  targetPreviewLabel: "Target",
  helperText: "Select segments, lock finalized ones, and run locale validation before handoff.",
  shortcutText: "Shortcuts: Ctrl/Cmd+Alt+Shift+L (panel), Ctrl/Cmd+Alt+Shift+V (validate), Ctrl/Cmd+Alt+Shift+K (lock segment)",
  readonlySegmentMessage: "This segment is locked. Unlock before editing.",
  sourceCapturedMessage: "Source snapshot captured from current content.",
  selectedSegmentPrefix: "Selected Segment",
  missingTargetMessage: "Segment is empty in target locale.",
  tokenMismatchMessage: "Tokens/placeholders do not match source segment.",
  untranslatedMessage: "Segment appears untranslated (same as source).",
  lengthOutOfRangeMessage: "Translation length is outside expected locale range."
}, c = /* @__PURE__ */ new WeakMap(), re = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new WeakMap(), le = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new Set();
let X = 0, Fe = 0, Re = 0, We = 0, k = null, x = null, D = null, z = null, N = null, O = null, I = null, _ = null;
function m(e) {
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function Ke(e) {
  return e.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
}
function C(e, t, r) {
  return Number.isFinite(e) ? Math.max(t, Math.min(r, e)) : t;
}
function A(e) {
  return (e || "").trim() || "en-US";
}
function W(e) {
  return e.trim().toLowerCase();
}
function Ve(e) {
  return e.replace(/"/g, "&quot;");
}
function je(e, t = 120) {
  return e.length <= t ? e : `${e.slice(0, Math.max(0, t - 1)).trimEnd()}…`;
}
function Ie(e) {
  const t = e.match(/\{\{[^{}]+\}\}|%[A-Z0-9_]+%|\$\{[^{}]+\}/gi);
  return !t || t.length === 0 ? [] : t.map((r) => r.trim()).filter(Boolean);
}
function Ue(e, t) {
  const r = Ie(e).sort(), n = Ie(t).sort();
  if (r.length !== n.length) return !1;
  for (let a = 0; a < r.length; a += 1)
    if (r[a] !== n[a]) return !1;
  return !0;
}
function Ge(e, t) {
  const r = Array.isArray(t) && t.length > 0 ? t : Ae, n = [], a = /* @__PURE__ */ new Set();
  return r.forEach((o) => {
    const l = W(o.locale || "");
    if (!l) return;
    const s = l;
    a.has(s) || (a.add(s), n.push({
      locale: s,
      label: (o.label || l).trim() || l,
      minLengthRatio: C(Number(o.minLengthRatio ?? 0.5), 0.1, 3),
      maxLengthRatio: C(Number(o.maxLengthRatio ?? 1.8), 0.2, 4),
      requireDifferentFromSource: o.requireDifferentFromSource !== !1,
      preserveTokens: o.preserveTokens !== !1
    }));
  }), e.forEach((o) => {
    const l = W(o);
    if (a.has(l)) return;
    const s = Ae.find((i) => l.startsWith(i.locale));
    n.push(
      s ? { ...s, locale: l, label: o } : {
        locale: l,
        label: o,
        minLengthRatio: 0.5,
        maxLengthRatio: 1.8,
        requireDifferentFromSource: !0,
        preserveTokens: !0
      }
    );
  }), n;
}
function oe(e = {}) {
  const t = e.normalizeText || Ke, r = A(e.sourceLocale || "en-US"), n = A(e.targetLocale || "fr-FR"), a = /* @__PURE__ */ new Set([r, n]);
  (Array.isArray(e.locales) ? e.locales : []).forEach((s) => {
    if (typeof s != "string") return;
    const i = A(s);
    a.add(i);
  });
  const o = Array.from(a), l = Ge(o, e.localeRules);
  return {
    sourceLocale: r,
    targetLocale: n,
    locales: o,
    localeRules: l,
    enableRealtime: e.enableRealtime !== !1,
    debounceMs: C(Number(e.debounceMs ?? 260), 60, 2e3),
    maxIssues: C(Number(e.maxIssues ?? 120), 5, 1e3),
    maxSegments: C(Number(e.maxSegments ?? 600), 20, 3e3),
    minSourceLengthForRatio: C(Number(e.minSourceLengthForRatio ?? 8), 2, 100),
    segmentSelector: (e.segmentSelector || Ee).trim() || Ee,
    labels: {
      ..._e,
      ...e.labels || {}
    },
    normalizeText: t
  };
}
function Ye(e) {
  return {
    sourceLocale: e.sourceLocale,
    targetLocale: e.targetLocale,
    locales: [...e.locales],
    localeRules: e.localeRules.map((t) => ({
      locale: t.locale,
      label: t.label,
      minLengthRatio: t.minLengthRatio,
      maxLengthRatio: t.maxLengthRatio,
      requireDifferentFromSource: t.requireDifferentFromSource,
      preserveTokens: t.preserveTokens
    })),
    enableRealtime: e.enableRealtime,
    debounceMs: e.debounceMs,
    maxIssues: e.maxIssues,
    maxSegments: e.maxSegments,
    minSourceLengthForRatio: e.minSourceLengthForRatio,
    segmentSelector: e.segmentSelector,
    labels: { ...e.labels },
    normalizeText: e.normalizeText
  };
}
function xe(e) {
  return e.closest(ke) || e;
}
function K(e) {
  if (!e) return null;
  if (e.matches(S)) return e;
  const t = e.querySelector(S);
  return t instanceof HTMLElement ? t : null;
}
function Ze() {
  if (typeof window > "u") return null;
  const e = window[ve];
  if (!(e instanceof HTMLElement)) return null;
  window[ve] = null;
  const t = K(e);
  if (t) return t;
  const r = e.closest(ke);
  if (r) {
    const a = K(r);
    if (a) return a;
  }
  const n = e.closest(S);
  return n instanceof HTMLElement ? n : null;
}
function Je(e) {
  const t = e.closest("[data-editora-editor]");
  if (t && K(t) === e)
    return t;
  let r = e;
  for (; r; ) {
    if (r.matches(ke) && (r === e || K(r) === e))
      return r;
    r = r.parentElement;
  }
  return xe(e);
}
function He(e) {
  return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function ee(e) {
  return e ? (e.getAttribute("data-theme") || e.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : e.classList.contains("dark") || e.classList.contains("editora-theme-dark") || e.classList.contains("rte-theme-dark") : !1;
}
function Qe(e) {
  const t = xe(e);
  if (ee(t)) return !0;
  const r = t.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
  return ee(r) ? !0 : ee(document.documentElement) || ee(document.body);
}
function ge(e, t) {
  e.classList.remove("rte-translation-workflow-theme-dark"), Qe(t) && e.classList.add("rte-translation-workflow-theme-dark");
}
function Xe(e) {
  for (let t = 0; t < e.length; t += 1) {
    const r = e[t];
    if (!(r.type !== "childList" || r.removedNodes.length === 0))
      for (let n = 0; n < r.removedNodes.length; n += 1) {
        const a = r.removedNodes[n];
        if (a.nodeType !== Node.ELEMENT_NODE) continue;
        const o = a;
        if (o.matches?.(S) || o.matches?.(`.${u}`) || o.querySelector?.(S) || o.querySelector?.(`.${u}`))
          return !0;
      }
  }
  return !1;
}
function ae() {
  Array.from(U).forEach((t) => {
    t.isConnected || Se(t);
  });
}
function T(e, t = !0, r = !0) {
  if (ae(), e?.contentElement instanceof HTMLElement) return e.contentElement;
  if (e?.editorElement instanceof HTMLElement) {
    const s = K(e.editorElement);
    if (s) return s;
  }
  const n = Ze();
  if (n) return n;
  const a = window.getSelection();
  if (a && a.rangeCount > 0) {
    const s = He(a.getRangeAt(0).startContainer)?.closest(
      S
    );
    if (s) return s;
  }
  const o = document.activeElement;
  if (o) {
    if (o.matches(S)) return o;
    const s = o.closest(S);
    if (s) return s;
  }
  if (r && x && x.isConnected)
    return x;
  if (!t) return null;
  const l = document.querySelector(S);
  return l instanceof HTMLElement ? l : null;
}
function et(e) {
  const t = e.target;
  if (t) {
    const n = t.closest(`.${u}`);
    if (n) {
      const o = Array.from(p.entries()).find(([, l]) => l === n);
      if (o) return o[0];
    }
    const a = t.closest(S);
    if (a) return a;
  }
  const r = document.activeElement;
  if (r) {
    const n = r.closest(`.${u}`);
    if (n) {
      const o = Array.from(p.entries()).find(([, l]) => l === n);
      if (o) return o[0];
    }
    const a = r.closest(S);
    if (a) return a;
  }
  return null;
}
function fe(e, t, r) {
  const n = Je(e);
  Array.from(
    n.querySelectorAll(
      `.rte-toolbar-button[data-command="${t}"], .editora-toolbar-button[data-command="${t}"]`
    )
  ).forEach((o) => {
    o.classList.toggle("active", r), o.setAttribute("data-active", r ? "true" : "false"), o.setAttribute("aria-pressed", r ? "true" : "false");
  });
}
function we(e) {
  const t = le.get(e);
  typeof t == "number" && (window.clearTimeout(t), le.delete(e));
}
function tt(e, t) {
  const r = W(t), n = e.localeRules.find((l) => W(l.locale) === r);
  if (n) return n;
  const a = r.split("-")[0], o = e.localeRules.find((l) => W(l.locale).split("-")[0] === a);
  return o || {
    locale: r,
    label: t,
    minLengthRatio: 0.5,
    maxLengthRatio: 1.8,
    requireDifferentFromSource: !0,
    preserveTokens: !0
  };
}
function te(e, t, r, n = {}) {
  return Re += 1, {
    id: `translation-workflow-issue-${Re}`,
    type: e,
    severity: t,
    message: r,
    ...n
  };
}
function ie(e, t) {
  if (t) {
    e.hasAttribute("data-translation-prev-contenteditable") || e.setAttribute(
      "data-translation-prev-contenteditable",
      e.hasAttribute("contenteditable") && e.getAttribute("contenteditable") || "inherit"
    ), e.setAttribute("data-translation-locked", "true"), e.setAttribute("contenteditable", "false"), e.setAttribute("aria-readonly", "true"), e.classList.add("rte-translation-segment-locked");
    return;
  }
  if (e.removeAttribute("data-translation-locked"), e.removeAttribute("aria-readonly"), e.classList.remove("rte-translation-segment-locked"), e.hasAttribute("data-translation-prev-contenteditable")) {
    const r = e.getAttribute("data-translation-prev-contenteditable") || "";
    r === "inherit" ? e.setAttribute("contenteditable", "true") : e.setAttribute("contenteditable", r), e.removeAttribute("data-translation-prev-contenteditable");
  } else
    e.setAttribute("contenteditable", "true");
}
function ce(e, t) {
  return e.querySelector(`[data-translation-segment-id="${Ve(t)}"]`);
}
function qe(e) {
  const t = window.getSelection();
  if (!t || t.rangeCount === 0) return null;
  const r = He(t.getRangeAt(0).startContainer);
  return !r || !e.contains(r) ? null : r.closest("[data-translation-segment-id]");
}
function nt(e, t) {
  const r = Array.from(e.querySelectorAll(t));
  if (r.length <= 1) return r;
  const n = new Set(r);
  return r.filter((a) => {
    let o = a.parentElement;
    for (; o && o !== e; ) {
      if (n.has(o))
        return !1;
      o = o.parentElement;
    }
    return !0;
  });
}
function rt(e, t, r) {
  let n = (r || "").trim();
  if (!n || t.has(n)) {
    do
      n = `translation-segment-${Fe++}`;
    while (t.has(n));
    e.setAttribute("data-translation-segment-id", n);
  }
  return n;
}
function me(e, t) {
  if (t.lockedSegmentIds.size === 0) return !1;
  let r = !1;
  return t.lockedSegmentIds.forEach((n) => {
    const a = ce(e, n);
    if (!a) return;
    ie(a, !0);
    const o = t.lockedHtmlBySegmentId.get(n);
    if (typeof o == "string") {
      a.innerHTML !== o && (a.innerHTML = o, r = !0);
      return;
    }
    t.lockedHtmlBySegmentId.set(n, a.innerHTML);
  }), r;
}
function M(e, t, r) {
  const n = nt(e, t.segmentSelector), a = [], o = /* @__PURE__ */ new Set();
  for (let l = 0; l < n.length && !(a.length >= t.maxSegments); l += 1) {
    const s = n[l], i = rt(s, o, s.getAttribute("data-translation-segment-id")), d = r.lockedSegmentIds.has(i), g = s.getAttribute("data-translation-locked") === "true", w = d || g;
    if (w)
      if (r.lockedSegmentIds.add(i), ie(s, !0), !r.lockedHtmlBySegmentId.has(i))
        r.lockedHtmlBySegmentId.set(i, s.innerHTML);
      else {
        const B = r.lockedHtmlBySegmentId.get(i) || "";
        s.innerHTML !== B && (s.innerHTML = B);
      }
    else
      r.lockedHtmlBySegmentId.delete(i);
    const v = t.normalizeText(s.textContent || "");
    if (!v) continue;
    r.sourceTextBySegmentId.has(i) || r.sourceTextBySegmentId.set(i, v);
    const G = r.sourceTextBySegmentId.get(i) || v;
    a.push({
      id: i,
      tagName: s.tagName.toLowerCase(),
      index: a.length,
      text: v,
      sourceText: G,
      locked: w
    }), o.add(i);
  }
  return Array.from(r.sourceTextBySegmentId.keys()).forEach((l) => {
    o.has(l) || r.sourceTextBySegmentId.delete(l);
  }), Array.from(r.lockedSegmentIds.keys()).forEach((l) => {
    o.has(l) || r.lockedSegmentIds.delete(l);
  }), Array.from(r.lockedHtmlBySegmentId.keys()).forEach((l) => {
    (!o.has(l) || !r.lockedSegmentIds.has(l)) && r.lockedHtmlBySegmentId.delete(l);
  }), (!r.selectedSegmentId || !a.some((l) => l.id === r.selectedSegmentId)) && (r.selectedSegmentId = a[0]?.id || null), a;
}
function b(e, t) {
  c.has(e) || c.set(e, t);
  let r = q.get(e);
  return r || (r = {
    sourceLocale: t.sourceLocale,
    targetLocale: t.targetLocale,
    selectedSegmentId: null,
    realtimeEnabled: t.enableRealtime,
    segments: [],
    issues: [],
    sourceTextBySegmentId: /* @__PURE__ */ new Map(),
    lockedSegmentIds: /* @__PURE__ */ new Set(),
    lockedHtmlBySegmentId: /* @__PURE__ */ new Map(),
    snapshot: "",
    lastRunAt: null
  }, q.set(e, r)), U.add(e), r;
}
function Se(e) {
  we(e);
  const t = p.get(e);
  t && t.remove(), p.delete(e), j.delete(e);
  const r = q.get(e);
  r && (r.lockedSegmentIds.forEach((n) => {
    const a = ce(e, n);
    a && ie(a, !1);
  }), r.lockedHtmlBySegmentId.clear()), c.delete(e), re.delete(e), q.delete(e), U.delete(e), x === e && (x = null);
}
function ye(e) {
  return j.get(e) === !0;
}
function be(e, t) {
  if (!t.classList.contains("show")) return;
  const r = xe(e).getBoundingClientRect(), n = Math.min(window.innerWidth - 20, 520), a = Math.max(10, window.innerWidth - n - 10), o = Math.min(Math.max(10, r.right - n), a), l = Math.max(10, Math.min(window.innerHeight - 10, r.top + 12));
  t.style.width = `${n}px`, t.style.left = `${o}px`, t.style.top = `${l}px`, t.style.maxHeight = `${Math.max(260, window.innerHeight - 20)}px`;
}
function H(e, t) {
  const r = e.querySelector(".rte-translation-live");
  r && (r.textContent = t);
}
function ot(e, t) {
  return `${e.innerHTML}::${t.sourceLocale}::${t.targetLocale}::${Array.from(t.lockedSegmentIds).sort().join("|")}`;
}
function at(e, t, r) {
  const n = [], a = tt(r, t.targetLocale);
  for (let o = 0; o < e.length && !(n.length >= r.maxIssues); o += 1) {
    const l = e[o], s = r.normalizeText(l.sourceText || ""), i = r.normalizeText(l.text || "");
    if (!i) {
      n.push(
        te("missing-target", "error", r.labels.missingTargetMessage, {
          segmentId: l.id,
          sourceText: s,
          targetText: i,
          suggestion: "Provide translated content for this segment before export."
        })
      );
      continue;
    }
    if (a.preserveTokens && s && !Ue(s, i) && (n.push(
      te("token-mismatch", "error", r.labels.tokenMismatchMessage, {
        segmentId: l.id,
        sourceText: s,
        targetText: i,
        suggestion: "Preserve placeholders/tokens exactly (for example {{name}}, %ID%, ${value})."
      })
    ), n.length >= r.maxIssues) || a.requireDifferentFromSource && s && r.normalizeText(s) === r.normalizeText(i) && (n.push(
      te("untranslated", "warning", r.labels.untranslatedMessage, {
        segmentId: l.id,
        sourceText: s,
        targetText: i,
        suggestion: "Translate the segment or mark it intentionally unchanged."
      })
    ), n.length >= r.maxIssues))
      break;
    if (s.length >= r.minSourceLengthForRatio) {
      const d = i.length / Math.max(1, s.length);
      (d < a.minLengthRatio || d > a.maxLengthRatio) && n.push(
        te("length-out-of-range", "warning", r.labels.lengthOutOfRangeMessage, {
          segmentId: l.id,
          sourceText: s,
          targetText: i,
          suggestion: `Expected ratio for ${a.label}: ${a.minLengthRatio.toFixed(2)} - ${a.maxLengthRatio.toFixed(2)}.`
        })
      );
    }
  }
  return n;
}
function Be(e) {
  const t = c.get(e) || k, r = q.get(e);
  return {
    sourceLocale: r?.sourceLocale || t?.sourceLocale || "en-US",
    targetLocale: r?.targetLocale || t?.targetLocale || "fr-FR",
    realtimeEnabled: r?.realtimeEnabled === !0,
    selectedSegmentId: r?.selectedSegmentId || null,
    segmentCount: r?.segments.length || 0,
    lockedSegmentCount: r ? r.segments.filter((n) => n.locked).length : 0,
    issues: r?.issues ? r.issues.map((n) => ({ ...n })) : [],
    segments: r?.segments.map((n) => ({
      id: n.id,
      tagName: n.tagName,
      index: n.index,
      sourceLength: n.sourceText.length,
      targetLength: n.text.length,
      locked: n.locked
    })) || [],
    lastRunAt: r?.lastRunAt || null
  };
}
function E(e) {
  const t = q.get(e), r = t && t.selectedSegmentId ? t.segments.find((n) => n.id === t.selectedSegmentId) : null;
  fe(e, "toggleTranslationWorkflowPanel", ye(e)), fe(e, "toggleTranslationRealtime", t?.realtimeEnabled === !0), fe(e, "toggleTranslationSegmentLock", r?.locked === !0);
}
function lt(e, t) {
  const r = ce(e, t);
  if (!r) return;
  try {
    r.scrollIntoView({ block: "nearest", inline: "nearest" });
  } catch {
  }
  const n = window.getSelection();
  if (!(!n || typeof document.createRange != "function"))
    try {
      const a = document.createRange();
      a.selectNodeContents(r), a.collapse(!0), n.removeAllRanges(), n.addRange(a), e.focus({ preventScroll: !0 });
    } catch {
    }
}
function R(e) {
  const t = p.get(e);
  if (!t) return;
  const r = c.get(e) || k;
  if (!r) return;
  const n = b(e, r), a = t.querySelector(".rte-translation-source-label");
  a && (a.textContent = r.labels.sourceLocaleLabel);
  const o = t.querySelector(".rte-translation-target-label");
  o && (o.textContent = r.labels.targetLocaleLabel);
  const l = t.querySelector('[data-field="source-locale"]'), s = t.querySelector('[data-field="target-locale"]'), i = r.locales.map((f) => `<option value="${m(f)}">${m(f)}</option>`).join("");
  l && (l.innerHTML = i, l.value = n.sourceLocale), s && (s.innerHTML = i, s.value = n.targetLocale);
  const d = t.querySelector(".rte-translation-summary");
  if (d) {
    const f = n.issues.length, P = n.selectedSegmentId ? ` • ${r.labels.selectedSegmentPrefix}: ${n.selectedSegmentId}` : "";
    d.textContent = `${r.labels.summaryPrefix}: ${n.sourceLocale} → ${n.targetLocale} • ${f} issue${f === 1 ? "" : "s"}${P}`;
  }
  const g = t.querySelector(".rte-translation-helper");
  g && (g.textContent = r.labels.helperText);
  const w = t.querySelector(".rte-translation-shortcut");
  w && (w.textContent = r.labels.shortcutText);
  const v = t.querySelector('[data-action="run-validation"]');
  v && (v.textContent = r.labels.validateText);
  const G = t.querySelector('[data-action="capture-source"]');
  G && (G.textContent = r.labels.captureSourceText);
  const B = t.querySelector('[data-action="toggle-realtime"]');
  B && (B.textContent = n.realtimeEnabled ? r.labels.realtimeOnText : r.labels.realtimeOffText, B.setAttribute("aria-pressed", n.realtimeEnabled ? "true" : "false"));
  const Y = t.querySelector('[data-action="lock-selected"]'), ue = n.selectedSegmentId && n.segments.find((f) => f.id === n.selectedSegmentId) || null;
  Y && (Y.textContent = ue?.locked ? r.labels.unlockSelectedText : r.labels.lockSelectedText, Y.disabled = !ue, Y.setAttribute("aria-pressed", ue?.locked ? "true" : "false"));
  const Te = t.querySelector('[data-action="close"]');
  Te && Te.setAttribute("aria-label", r.labels.closeText);
  const Z = t.querySelector(".rte-translation-issues"), F = t.querySelector(".rte-translation-empty");
  Z && (Z.setAttribute("aria-label", r.labels.issuesLabel), n.issues.length === 0 ? (Z.innerHTML = "", F && (F.hidden = !1, F.textContent = r.labels.noIssuesText)) : (F && (F.hidden = !0), Z.innerHTML = n.issues.map((f) => `
            <li class="rte-translation-issue ${f.severity === "error" ? "error" : f.severity === "warning" ? "warning" : "info"}" role="listitem" data-segment-id="${m(
    f.segmentId || ""
  )}">
              <p class="rte-translation-issue-message">${m(f.message)}</p>
              ${f.suggestion ? `<p class="rte-translation-issue-suggestion">${m(f.suggestion)}</p>` : ""}
            </li>
          `).join("")));
  const de = t.querySelector(".rte-translation-segments");
  de && (de.setAttribute("aria-label", r.labels.segmentsLabel), de.innerHTML = n.segments.map((f) => {
    const P = f.id === n.selectedSegmentId ? "selected" : "", Oe = f.locked ? "locked" : "";
    return `
          <li class="rte-translation-segment-item ${P} ${Oe}" role="option" aria-selected="${f.id === n.selectedSegmentId ? "true" : "false"}" data-segment-id="${m(f.id)}">
            <button type="button" class="rte-translation-segment-select" data-action="select-segment" data-segment-id="${m(
      f.id
    )}" title="${m(f.text)}">
              <span class="rte-translation-segment-meta">#${f.index + 1} • ${m(f.tagName)}</span>
              <span class="rte-translation-segment-text">${m(je(f.text, 110))}</span>
            </button>
            <button type="button" class="rte-translation-segment-lock" data-action="toggle-lock" data-segment-id="${m(
      f.id
    )}" aria-label="${f.locked ? r.labels.unlockSegmentAriaLabel : r.labels.lockSegmentAriaLabel}" aria-pressed="${f.locked ? "true" : "false"}"></button>
          </li>
        `;
  }).join(""));
  const J = t.querySelector(".rte-translation-source-preview"), Q = t.querySelector(".rte-translation-target-preview");
  if (J || Q) {
    const f = n.selectedSegmentId && n.segments.find((P) => P.id === n.selectedSegmentId) || null;
    J && (J.textContent = f?.sourceText || "—", J.setAttribute("aria-label", r.labels.sourcePreviewLabel)), Q && (Q.textContent = f?.text || "—", Q.setAttribute("aria-label", r.labels.targetPreviewLabel));
  }
  t.setAttribute("aria-label", r.labels.panelAriaLabel);
}
function Pe(e) {
  const t = c.get(e) || k;
  if (!t) return;
  we(e);
  const r = window.setTimeout(() => {
    le.delete(e), L(e, "realtime", !1);
  }, t.debounceMs);
  le.set(e, r);
}
function L(e, t, r) {
  const n = c.get(e) || k;
  if (!n) return [];
  const a = b(e, n), o = me(e, a);
  a.segments = M(e, n, a);
  const l = ot(e, a);
  if (!r && a.snapshot === l)
    return a.issues;
  a.issues = at(a.segments, a, n), a.lastRunAt = (/* @__PURE__ */ new Date()).toISOString(), a.snapshot = l, R(e), E(e), e.dispatchEvent(
    new CustomEvent("editora:translation-workflow-validation", {
      bubbles: !0,
      detail: {
        reason: t,
        state: Be(e)
      }
    })
  );
  const s = p.get(e);
  if (s) {
    if (o)
      return H(s, n.labels.readonlySegmentMessage), a.issues;
    H(
      s,
      a.issues.length === 0 ? n.labels.noIssuesText : `${a.issues.length} issue${a.issues.length === 1 ? "" : "s"} detected.`
    );
  }
  return a.issues;
}
function De(e) {
  const t = c.get(e) || k;
  if (!t) return !1;
  const r = b(e, t), n = M(e, t, r);
  n.forEach((o) => {
    r.sourceTextBySegmentId.set(o.id, o.text);
  }), r.snapshot = "", L(e, "capture-source", !0);
  const a = p.get(e);
  return a && H(a, t.labels.sourceCapturedMessage), e.dispatchEvent(
    new CustomEvent("editora:translation-source-captured", {
      bubbles: !0,
      detail: {
        sourceLocale: r.sourceLocale,
        segmentCount: n.length
      }
    })
  ), !0;
}
function se(e, t, r) {
  const n = c.get(e) || k;
  if (!n) return !1;
  const a = b(e, n);
  a.segments = M(e, n, a);
  const o = qe(e)?.getAttribute("data-translation-segment-id") || null, l = t || o || a.selectedSegmentId || a.segments[0]?.id || null;
  if (!l) return !1;
  const s = ce(e, l);
  if (!s) return !1;
  const i = typeof r == "boolean" ? r : !a.lockedSegmentIds.has(l);
  return i ? (a.lockedSegmentIds.add(l), a.lockedHtmlBySegmentId.set(l, s.innerHTML)) : (a.lockedSegmentIds.delete(l), a.lockedHtmlBySegmentId.delete(l)), ie(s, i), a.selectedSegmentId = l, a.snapshot = "", L(e, "lock-segment", !0), e.dispatchEvent(
    new CustomEvent("editora:translation-segment-lock", {
      bubbles: !0,
      detail: {
        segmentId: l,
        locked: i
      }
    })
  ), !0;
}
function ze(e, t) {
  const r = c.get(e) || k;
  if (!r) return !1;
  const n = b(e, r), a = typeof t == "boolean" ? t : !n.realtimeEnabled;
  return n.realtimeEnabled = a, a ? Pe(e) : we(e), R(e), E(e), !0;
}
function pe(e, t, r = !0) {
  const n = c.get(e) || k;
  if (!n) return !1;
  const a = b(e, n);
  return a.segments = M(e, n, a), a.segments.some((o) => o.id === t) ? (a.selectedSegmentId = t, R(e), E(e), r && lt(e, t), !0) : !1;
}
function ne(e, t) {
  const r = c.get(e) || k;
  if (!r) return !1;
  const n = b(e, r);
  if (n.segments = M(e, r, n), n.segments.length === 0) return !1;
  const a = Math.max(
    0,
    n.segments.findIndex((s) => s.id === n.selectedSegmentId)
  );
  let o = a;
  t === "start" ? o = 0 : t === "end" ? o = n.segments.length - 1 : o = C(a + t, 0, n.segments.length - 1);
  const l = n.segments[o];
  return l ? pe(e, l.id, !0) : !1;
}
function V(e, t = !1) {
  const r = p.get(e);
  r && (r.classList.remove("show"), j.set(e, !1), E(e), t && e.focus({ preventScroll: !0 }));
}
function he(e) {
  const t = dt(e);
  p.forEach((n, a) => {
    a !== e && V(a, !1);
  }), t.classList.add("show"), j.set(e, !0), L(e, "panel-open", !1), R(e), be(e, t), E(e), t.querySelector('[data-field="target-locale"]')?.focus();
}
function Ne(e, t) {
  const r = ye(e);
  return (typeof t == "boolean" ? t : !r) ? he(e) : V(e, !1), !0;
}
function Le(e) {
  return typeof e.key == "string" ? e.key.toLowerCase() : "";
}
function st(e) {
  const t = Le(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "l";
}
function it(e) {
  const t = Le(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "v";
}
function ct(e) {
  const t = Le(e);
  return (e.metaKey || e.ctrlKey) && e.altKey && e.shiftKey && t === "k";
}
function ut(e) {
  return e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey ? !0 : e.key === "Backspace" || e.key === "Delete" || e.key === "Enter";
}
function Me(e) {
  return e instanceof HTMLElement ? e.closest('[data-translation-locked="true"]') : null;
}
function dt(e) {
  const t = p.get(e);
  if (t) return t;
  const r = c.get(e) || k || oe();
  b(e, r);
  const n = `rte-translation-workflow-panel-${We++}`, a = `${n}-source`, o = `${n}-target`, l = document.createElement("section");
  return l.className = u, l.id = n, l.setAttribute("role", "dialog"), l.setAttribute("aria-modal", "false"), l.setAttribute("aria-label", r.labels.panelAriaLabel), l.innerHTML = `
    <header class="rte-translation-header">
      <h2 class="rte-translation-title">${m(r.labels.panelTitle)}</h2>
      <button type="button" class="rte-translation-icon-btn" data-action="close" aria-label="${m(
    r.labels.closeText
  )}">✕</button>
    </header>
    <div class="rte-translation-body">
      <div class="rte-translation-locales">
        <div class="rte-translation-locale-field">
          <label class="rte-translation-source-label" for="${m(a)}"></label>
          <select id="${m(a)}" class="rte-translation-select" data-field="source-locale"></select>
        </div>
        <div class="rte-translation-locale-field">
          <label class="rte-translation-target-label" for="${m(o)}"></label>
          <select id="${m(o)}" class="rte-translation-select" data-field="target-locale"></select>
        </div>
      </div>
      <p class="rte-translation-summary"></p>
      <div class="rte-translation-actions">
        <button type="button" class="rte-translation-btn rte-translation-btn-primary" data-action="run-validation"></button>
        <button type="button" class="rte-translation-btn" data-action="capture-source"></button>
        <button type="button" class="rte-translation-btn" data-action="lock-selected"></button>
        <button type="button" class="rte-translation-btn" data-action="toggle-realtime" aria-pressed="false"></button>
      </div>
      <p class="rte-translation-helper"></p>
      <p class="rte-translation-shortcut"></p>
      <div class="rte-translation-grid">
        <section class="rte-translation-segments-wrap" aria-label="${m(r.labels.segmentsLabel)}">
          <h3 class="rte-translation-subtitle">${m(r.labels.segmentsLabel)}</h3>
          <ul class="rte-translation-segments" role="listbox" tabindex="0" aria-label="${m(
    r.labels.segmentsLabel
  )}"></ul>
        </section>
        <section class="rte-translation-preview-wrap">
          <h3 class="rte-translation-subtitle">${m(r.labels.sourcePreviewLabel)} / ${m(
    r.labels.targetPreviewLabel
  )}</h3>
          <div class="rte-translation-preview-block">
            <p class="rte-translation-preview-label">${m(r.labels.sourcePreviewLabel)}</p>
            <p class="rte-translation-source-preview"></p>
          </div>
          <div class="rte-translation-preview-block">
            <p class="rte-translation-preview-label">${m(r.labels.targetPreviewLabel)}</p>
            <p class="rte-translation-target-preview"></p>
          </div>
        </section>
      </div>
      <section class="rte-translation-issues-wrap">
        <h3 class="rte-translation-subtitle">${m(r.labels.issuesLabel)}</h3>
        <ul class="rte-translation-issues" role="list" aria-label="${m(r.labels.issuesLabel)}"></ul>
        <p class="rte-translation-empty" hidden></p>
      </section>
    </div>
    <div class="rte-translation-live" aria-live="polite" aria-atomic="true"></div>
  `, l.addEventListener("click", (s) => {
    const i = s.target;
    if (!i) return;
    const d = i.closest("[data-action]");
    if (!d) {
      const v = i.closest(".rte-translation-issue[data-segment-id]")?.getAttribute("data-segment-id") || "";
      v && pe(e, v, !0);
      return;
    }
    const g = d.getAttribute("data-action");
    if (g === "close") {
      V(e, !0);
      return;
    }
    if (g === "run-validation") {
      L(e, "panel-button", !0);
      return;
    }
    if (g === "capture-source") {
      De(e);
      return;
    }
    if (g === "lock-selected") {
      se(e);
      return;
    }
    if (g === "toggle-realtime") {
      ze(e);
      return;
    }
    if (g === "select-segment") {
      const w = d.getAttribute("data-segment-id") || "";
      w && pe(e, w, !0);
      return;
    }
    if (g === "toggle-lock") {
      const w = d.getAttribute("data-segment-id") || "";
      w && se(e, w);
    }
  }), l.addEventListener("change", (s) => {
    const i = s.target;
    if (!(i instanceof HTMLSelectElement)) return;
    const d = c.get(e) || k;
    if (!d) return;
    const g = b(e, d);
    if (i.getAttribute("data-field") === "source-locale") {
      g.sourceLocale = A(i.value), g.snapshot = "", L(e, "source-locale-change", !0);
      return;
    }
    i.getAttribute("data-field") === "target-locale" && (g.targetLocale = A(i.value), g.snapshot = "", L(e, "target-locale-change", !0));
  }), l.addEventListener("keydown", (s) => {
    const i = s.target;
    if (s.key === "Escape") {
      s.preventDefault(), V(e, !0);
      return;
    }
    !i?.closest(".rte-translation-segments") || !Ce.has(s.key) || (s.preventDefault(), s.key === "ArrowUp" ? ne(e, -1) : s.key === "ArrowDown" ? ne(e, 1) : s.key === "Home" ? ne(e, "start") : s.key === "End" && ne(e, "end"));
  }), ge(l, e), document.body.appendChild(l), p.set(e, l), j.set(e, !1), R(e), l;
}
function ft(e) {
  k = e, D || (D = (t) => {
    ae();
    const n = t.target?.closest(S);
    if (!n) return;
    const a = c.get(n) || e, o = b(n, a);
    c.set(n, a), x = n;
    const l = qe(n)?.getAttribute("data-translation-segment-id") || null;
    l && (o.selectedSegmentId = l), E(n);
    const s = p.get(n);
    s && (ge(s, n), be(n, s), R(n));
  }, document.addEventListener("focusin", D, !0)), z || (z = (t) => {
    const n = t.target?.closest(S);
    if (!n) return;
    const a = c.get(n) || k;
    if (!a) return;
    const o = b(n, a), l = me(n, o);
    if (o.segments = M(n, a, o), !o.realtimeEnabled) {
      if (l) {
        const s = p.get(n);
        s && H(s, a.labels.readonlySegmentMessage);
      }
      R(n), E(n);
      return;
    }
    Pe(n);
  }, document.addEventListener("input", z, !0)), N || (N = (t) => {
    const r = t, n = r.target, a = n?.closest(S);
    if (!a) return;
    const o = Me(n);
    if (!o || !a.contains(o)) return;
    r.preventDefault();
    const l = p.get(a), s = c.get(a) || k;
    l && s && H(l, s.labels.readonlySegmentMessage);
  }, document.addEventListener("beforeinput", N, !0)), O || (O = (t) => {
    if (t.defaultPrevented) return;
    const r = t.target;
    if (r?.closest(`.${u}`) && t.key !== "Escape" && !Ce.has(t.key)) return;
    const a = t.key === "Escape", o = st(t), l = it(t), s = ct(t), i = Me(r);
    if (!a && !o && !l && !s && !i)
      return;
    const d = et(t);
    if (!d) return;
    const g = c.get(d) || k || e;
    if (b(d, g), c.set(d, g), x = d, a && ye(d)) {
      t.preventDefault(), V(d, !0);
      return;
    }
    if (i && d.contains(i) && ut(t)) {
      t.preventDefault();
      const w = p.get(d);
      w && H(w, g.labels.readonlySegmentMessage);
      return;
    }
    if (o) {
      t.preventDefault(), t.stopPropagation(), Ne(d);
      return;
    }
    if (l) {
      t.preventDefault(), t.stopPropagation(), L(d, "shortcut", !0);
      return;
    }
    s && (t.preventDefault(), t.stopPropagation(), se(d));
  }, document.addEventListener("keydown", O, !0)), I || (I = () => {
    ae(), p.forEach((t, r) => {
      !r.isConnected || !t.isConnected || (ge(t, r), be(r, t));
    });
  }, window.addEventListener("scroll", I, !0), window.addEventListener("resize", I)), !_ && typeof MutationObserver < "u" && document.body && (_ = new MutationObserver((t) => {
    Xe(t) && ae(), t.some((n) => n.type === "characterData" ? !0 : n.type === "childList" && (n.addedNodes.length > 0 || n.removedNodes.length > 0)) && U.forEach((n) => {
      const a = q.get(n);
      if (!a || a.lockedSegmentIds.size === 0 || !me(n, a)) return;
      a.snapshot = "";
      const l = c.get(n) || k, s = p.get(n);
      s && l && H(s, l.labels.readonlySegmentMessage), l && (a.segments = M(n, l, a), R(n), E(n));
    });
  }), _.observe(document.body, {
    childList: !0,
    subtree: !0,
    characterData: !0
  }));
}
function gt() {
  D && (document.removeEventListener("focusin", D, !0), D = null), z && (document.removeEventListener("input", z, !0), z = null), N && (document.removeEventListener("beforeinput", N, !0), N = null), O && (document.removeEventListener("keydown", O, !0), O = null), I && (window.removeEventListener("scroll", I, !0), window.removeEventListener("resize", I), I = null), _ && (_.disconnect(), _ = null), p.forEach((t) => t.remove()), p.clear(), Array.from(U).forEach((t) => Se(t)), k = null, x = null;
}
function mt() {
  if (typeof document > "u" || document.getElementById($e)) return;
  const e = document.createElement("style");
  e.id = $e, e.textContent = `
    .rte-toolbar-group-items.${y},
    .editora-toolbar-group-items.${y},
    .rte-toolbar-group-items.${$},
    .editora-toolbar-group-items.${$} {
      display: flex;
      border: 1px solid #cbd5e1;
      border-radius: 4px;
      background: #ffffff;
    }

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

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

    ${h} .rte-toolbar-group-items.${y},
    ${h} .editora-toolbar-group-items.${y},
    ${h} .rte-toolbar-group-items.${$},
    ${h} .editora-toolbar-group-items.${$} {
      border-color: #566275;
    }
    .rte-toolbar-button[data-command="toggleTranslationWorkflowPanel"].active,
    .editora-toolbar-button[data-command="toggleTranslationWorkflowPanel"].active,
    .rte-toolbar-button[data-command="toggleTranslationSegmentLock"].active,
    .editora-toolbar-button[data-command="toggleTranslationSegmentLock"].active, 
    .rte-toolbar-button[data-command="toggleTranslationRealtime"].active,
    .editora-toolbar-button[data-command="toggleTranslationRealtime"].active {
      background: #ccc;
    }
    ${h} .rte-toolbar-group-items.${y} .rte-toolbar-button svg,
    ${h} .editora-toolbar-group-items.${y} .editora-toolbar-button svg,
    ${h} .rte-toolbar-group-items.${$} .rte-toolbar-button svg,
    ${h} .editora-toolbar-group-items.${$} .editora-toolbar-button svg
    {
      fill: none;
    }
    ${h} .rte-toolbar-group-items.${y} .rte-toolbar-button,
    ${h} .editora-toolbar-group-items.${y} .editora-toolbar-button
    {
      border-color: #566275;
    }

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

    .${u} {
      position: fixed;
      z-index: 12000;
      display: none;
      width: min(520px, calc(100vw - 20px));
      max-height: calc(100vh - 20px);
      border: 1px solid #d1d5db;
      border-radius: 14px;
      background: #ffffff;
      color: #0f172a;
      box-shadow: 0 24px 48px rgba(15, 23, 42, 0.24);
      overflow: hidden;
    }

    .${u}.show {
      display: flex;
      flex-direction: column;
    }

    .${u}.rte-translation-workflow-theme-dark {
      border-color: #334155;
      background: #0f172a;
      color: #e2e8f0;
      box-shadow: 0 24px 52px rgba(2, 6, 23, 0.68);
    }

    .rte-translation-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 12px 14px;
      border-bottom: 1px solid #e2e8f0;
      background: linear-gradient(180deg, #eff6ff 0%, #e2e8f0 100%);
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-header {
      border-color: #1e293b;
      background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    }

    .rte-translation-title {
      margin: 0;
      font-size: 15px;
      line-height: 1.2;
      font-weight: 700;
    }

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

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

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

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

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

    .rte-translation-locales {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 8px;
    }

    .rte-translation-locale-field {
      display: grid;
      gap: 4px;
    }

    .rte-translation-source-label,
    .rte-translation-target-label {
      font-size: 12px;
      font-weight: 700;
      color: #334155;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-source-label,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-target-label {
      color: #cbd5e1;
    }

    .rte-translation-select {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      min-height: 34px;
      padding: 0 10px;
      font-size: 13px;
      background: #ffffff;
      color: inherit;
    }

    .rte-translation-select:focus-visible {
      border-color: #0e7490;
      box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.18);
      outline: none;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-select {
      border-color: #334155;
      background: #0b1220;
      color: #e2e8f0;
    }

    .rte-translation-summary,
    .rte-translation-helper,
    .rte-translation-shortcut {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #475569;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-summary,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-helper,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-shortcut {
      color: #94a3b8;
    }

    .rte-translation-actions {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 8px;
    }

    .rte-translation-btn {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      min-height: 34px;
      padding: 0 8px;
      background: #ffffff;
      color: inherit;
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
    }

    .rte-translation-btn:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }

    .rte-translation-btn-primary {
      border-color: #0e7490;
      background: #0e7490;
      color: #f8fafc;
    }

    .rte-translation-btn:hover,
    .rte-translation-btn:focus-visible {
      border-color: #94a3b8;
      outline: none;
    }

    .rte-translation-btn-primary:hover,
    .rte-translation-btn-primary:focus-visible {
      border-color: #155e75;
      background: #155e75;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-btn {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-btn-primary {
      border-color: #22d3ee;
      background: #0e7490;
      color: #ecfeff;
    }

    .rte-translation-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .rte-translation-segments-wrap,
    .rte-translation-preview-wrap,
    .rte-translation-issues-wrap {
      border: 1px solid #e2e8f0;
      border-radius: 10px;
      background: #f8fafc;
      padding: 8px;
      min-height: 120px;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segments-wrap,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-preview-wrap,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-issues-wrap {
      border-color: #334155;
      background: #0b1220;
    }

    .rte-translation-subtitle {
      margin: 0 0 6px;
      font-size: 12px;
      font-weight: 700;
      color: #334155;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-subtitle {
      color: #cbd5e1;
    }

    .rte-translation-segments {
      margin: 0;
      padding: 0;
      list-style: none;
      display: grid;
      gap: 6px;
      max-height: 220px;
      overflow: auto;
      outline: none;
    }

    .rte-translation-segment-item {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 6px;
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      background: #ffffff;
      padding: 6px;
    }

    .rte-translation-segment-item.selected {
      border-color: #0e7490;
      box-shadow: 0 0 0 2px rgba(14, 116, 144, 0.16);
    }

    .rte-translation-segment-item.locked {
      border-color: #f59e0b;
      background: #fffbeb;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segment-item {
      border-color: #334155;
      background: #111827;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segment-item.locked {
      border-color: rgba(245, 158, 11, 0.72);
      background: rgba(120, 53, 15, 0.28);
    }

    .rte-translation-segment-select {
      border: none;
      background: transparent;
      color: inherit;
      text-align: left;
      padding: 0;
      cursor: pointer;
      display: grid;
      gap: 2px;
    }

    .rte-translation-segment-meta {
      font-size: 11px;
      color: #64748b;
      font-weight: 700;
    }

    .rte-translation-segment-text {
      font-size: 12px;
      color: #334155;
      line-height: 1.3;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segment-meta {
      color: #94a3b8;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segment-text {
      color: #e2e8f0;
    }

    .rte-translation-segment-lock {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      width: 28px;
      min-height: 28px;
      background: #ffffff;
      cursor: pointer;
      position: relative;
      color: inherit;
      font-size: 0;
    }

    .rte-translation-segment-lock::before {
      content: '🔒';
      font-size: 14px;
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      opacity: 0.35;
    }

    .rte-translation-segment-lock[aria-pressed="true"]::before {
      opacity: 1;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-segment-lock {
      border-color: #334155;
      background: #111827;
    }

    .rte-translation-preview-block {
      display: grid;
      gap: 4px;
      margin-bottom: 8px;
    }

    .rte-translation-preview-label {
      margin: 0;
      font-size: 11px;
      color: #64748b;
      font-weight: 700;
    }

    .rte-translation-source-preview,
    .rte-translation-target-preview {
      margin: 0;
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      background: #ffffff;
      padding: 8px;
      font-size: 12px;
      min-height: 56px;
      white-space: pre-wrap;
      line-height: 1.35;
      color: #1f2937;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-preview-label {
      color: #94a3b8;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-source-preview,
    .${u}.rte-translation-workflow-theme-dark .rte-translation-target-preview {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .rte-translation-issues {
      margin: 0;
      padding: 0;
      list-style: none;
      display: grid;
      gap: 6px;
      max-height: 200px;
      overflow: auto;
    }

    .rte-translation-issue {
      border: 1px solid #cbd5e1;
      border-radius: 8px;
      background: #ffffff;
      padding: 8px;
      display: grid;
      gap: 4px;
      cursor: pointer;
    }

    .rte-translation-issue.error {
      border-color: #ef4444;
      background: #fef2f2;
    }

    .rte-translation-issue.warning {
      border-color: #f59e0b;
      background: #fffbeb;
    }

    .rte-translation-issue.info {
      border-color: #0ea5e9;
      background: #f0f9ff;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue {
      border-color: #334155;
      background: #111827;
      color: #e2e8f0;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue.error {
      border-color: rgba(239, 68, 68, 0.7);
      background: rgba(127, 29, 29, 0.28);
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue.warning {
      border-color: rgba(245, 158, 11, 0.72);
      background: rgba(120, 53, 15, 0.28);
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue.info {
      border-color: rgba(14, 165, 233, 0.7);
      background: rgba(7, 89, 133, 0.28);
    }

    .rte-translation-issue-message,
    .rte-translation-issue-suggestion {
      margin: 0;
      font-size: 12px;
      line-height: 1.35;
      color: #1f2937;
    }

    .rte-translation-issue-suggestion {
      color: #475569;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue-message {
      color: #e2e8f0;
    }

    .${u}.rte-translation-workflow-theme-dark .rte-translation-issue-suggestion {
      color: #cbd5e1;
    }

    .rte-translation-empty {
      margin: 8px;
      font-size: 12px;
      color: #64748b;
    }

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

    [data-translation-locked="true"].rte-translation-segment-locked {
      outline: 2px dashed rgba(245, 158, 11, 0.65);
      outline-offset: 2px;
      background: rgba(255, 251, 235, 0.8);
      border-radius: 4px;
    }

    ${h} [data-translation-locked="true"].rte-translation-segment-locked {
      outline-color: rgba(245, 158, 11, 0.75);
      background: rgba(120, 53, 15, 0.22);
    }

    @media (max-width: 920px) {
      .${u} {
        left: 10px !important;
        right: 10px;
        top: 10px !important;
        width: auto !important;
        max-height: calc(100vh - 20px);
      }

      .rte-translation-locales,
      .rte-translation-actions,
      .rte-translation-grid {
        grid-template-columns: 1fr;
      }
    }
  `, document.head.appendChild(e);
}
const bt = (e = {}) => {
  const t = oe(e), r = /* @__PURE__ */ new Set();
  return mt(), {
    name: "translationWorkflow",
    toolbar: [
      {
        id: "translationWorkflowGroup",
        label: "Translation Workflow",
        type: "group",
        command: "translationWorkflow",
        items: [
          {
            id: "toggleTranslationWorkflowPanel",
            label: "Translation Workflow",
            command: "toggleTranslationWorkflowPanel",
            shortcut: "Mod-Alt-Shift-l",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4 6.5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H8l-4 3V6.5Z" stroke="currentColor" stroke-width="1.6"/><path d="M20 17.5a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-1.5" stroke="currentColor" stroke-width="1.6"/><path d="m13 8 2 2m0 0 2-2m-2 2V4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          },
          {
            id: "runTranslationLocaleValidation",
            label: "Run Locale Validation",
            command: "runTranslationLocaleValidation",
            shortcut: "Mod-Alt-Shift-v",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="4.5" y="4" width="12" height="16" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M8 8h5.5M8 11h4M8 14h3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="m15.5 15.5 1.7 1.7 3.3-3.3" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          },
          {
            id: "toggleTranslationSegmentLock",
            label: "Toggle Segment Lock",
            command: "toggleTranslationSegmentLock",
            shortcut: "Mod-Alt-Shift-k",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><rect x="5" y="10" width="14" height="10" rx="2" stroke="currentColor" stroke-width="1.6"/><path d="M8.5 10V7.5a3.5 3.5 0 1 1 7 0V10" stroke="currentColor" stroke-width="1.6"/><circle cx="12" cy="15" r="1.2" fill="currentColor"/></svg>'
          },
          {
            id: "toggleTranslationRealtime",
            label: "Toggle Translation Realtime",
            command: "toggleTranslationRealtime",
            icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M4.5 12a7.5 7.5 0 1 1 7.5 7.5" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/><path d="M9.5 19.5H5.5v-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M12 8v4l2.5 2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          }
        ]
      }
    ],
    commands: {
      translationWorkflow: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, he(o), !0;
      },
      openTranslationWorkflowPanel: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, he(o), !0;
      },
      toggleTranslationWorkflowPanel: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, Ne(o, typeof n == "boolean" ? n : void 0);
      },
      runTranslationLocaleValidation: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, L(o, "command", !0), !0;
      },
      toggleTranslationRealtime: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, ze(o, typeof n == "boolean" ? n : void 0);
      },
      toggleTranslationSegmentLock: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        b(o, l), c.set(o, l), x = o;
        const s = typeof n == "boolean" ? n : n?.locked, i = typeof n == "object" ? n?.segmentId : void 0;
        return se(o, i, s);
      },
      setTranslationLocales: (n, a) => {
        const o = T(a, !1, !1);
        if (!o || !n || typeof n != "object") return !1;
        const l = c.get(o) || t, s = b(o, l);
        return c.set(o, l), typeof n.sourceLocale == "string" && n.sourceLocale.trim() && (s.sourceLocale = A(n.sourceLocale)), typeof n.targetLocale == "string" && n.targetLocale.trim() && (s.targetLocale = A(n.targetLocale)), s.snapshot = "", L(o, "set-locales", !0), !0;
      },
      captureTranslationSourceSnapshot: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        return b(o, l), c.set(o, l), x = o, De(o);
      },
      setTranslationWorkflowOptions: (n, a) => {
        const o = T(a, !1, !1);
        if (!o || !n || typeof n != "object") return !1;
        const l = c.get(o) || t, s = re.get(o) || Ye(l), i = {
          ...s,
          ...n,
          labels: {
            ...s.labels || {},
            ...n.labels || {}
          },
          localeRules: Array.isArray(n.localeRules) ? n.localeRules : s.localeRules,
          locales: Array.isArray(n.locales) ? n.locales : s.locales,
          normalizeText: n.normalizeText || l.normalizeText
        }, d = oe(i);
        c.set(o, d), re.set(o, i);
        const g = b(o, d);
        return typeof n.enableRealtime == "boolean" && (g.realtimeEnabled = n.enableRealtime), typeof n.sourceLocale == "string" && n.sourceLocale.trim() && (g.sourceLocale = A(n.sourceLocale)), typeof n.targetLocale == "string" && n.targetLocale.trim() && (g.targetLocale = A(n.targetLocale)), g.snapshot = "", L(o, "set-options", !0), R(o), E(o), !0;
      },
      getTranslationWorkflowState: (n, a) => {
        const o = T(a, !1, !1);
        if (!o) return !1;
        const l = c.get(o) || t;
        b(o, l);
        const s = Be(o);
        if (typeof n == "function")
          try {
            n(s);
          } catch {
          }
        return o.__translationWorkflowState = s, o.dispatchEvent(
          new CustomEvent("editora:translation-workflow-state", {
            bubbles: !0,
            detail: s
          })
        ), !0;
      }
    },
    keymap: {
      "Mod-Alt-Shift-l": "toggleTranslationWorkflowPanel",
      "Mod-Alt-Shift-L": "toggleTranslationWorkflowPanel",
      "Mod-Alt-Shift-v": "runTranslationLocaleValidation",
      "Mod-Alt-Shift-V": "runTranslationLocaleValidation",
      "Mod-Alt-Shift-k": "toggleTranslationSegmentLock",
      "Mod-Alt-Shift-K": "toggleTranslationSegmentLock"
    },
    init: function(a) {
      X += 1;
      const o = this && typeof this.__pluginConfig == "object" ? { ...e, ...this.__pluginConfig } : e, l = oe(o);
      ft(l);
      const s = T(
        a?.editorElement ? { editorElement: a.editorElement } : void 0,
        !1,
        !1
      );
      if (!s) return;
      x = s, r.add(s);
      const i = b(s, l);
      c.set(s, l), re.set(s, o), i.segments = M(s, l, i), L(s, "init", !0), E(s);
    },
    destroy: () => {
      r.forEach((n) => Se(n)), r.clear(), X = Math.max(0, X - 1), !(X > 0) && gt();
    }
  };
};
export {
  bt as TranslationWorkflowPlugin
};
