"use client";
import { jsxs as o } from "react/jsx-runtime";
import { useLexicalComposerContext as a } from "../../../../node_modules/@lexical/react/LexicalComposerContext.prod.js";
import { $rootTextContent as u } from "../../../../node_modules/@lexical/text/LexicalText.prod.js";
import { useState as d, useEffect as f } from "react";
let s = null;
function h() {
  return window.TextEncoder === void 0 ? null : (s === null && (s = new window.TextEncoder()), s);
}
function g(t) {
  const e = h();
  if (e === null) {
    const n = encodeURIComponent(t).match(/%[89ABab]/g);
    return t.length + (n ? n.length : 0);
  }
  return e.encode(t).length;
}
const c = (t, e) => {
  if (e === "UTF-8")
    return g(t);
  if (e === "UTF-16")
    return t.length;
}, i = (t) => t.split(/\s+/).filter((e) => e.length > 0).length;
function T({
  charset: t = "UTF-16"
}) {
  const [e] = a(), [n, l] = d(() => {
    const r = e.getEditorState().read(u);
    return {
      characters: c(r, t),
      words: i(r)
    };
  });
  return f(() => e.registerTextContentListener((r) => {
    l({
      characters: c(r, t),
      words: i(r)
    });
  }), [e, t]), /* @__PURE__ */ o("div", { className: "flex gap-2 text-xs whitespace-nowrap text-gray-500", children: [
    /* @__PURE__ */ o("p", { children: [
      n.characters,
      " characters"
    ] }),
    "|",
    /* @__PURE__ */ o("p", { children: [
      n.words,
      " words"
    ] })
  ] });
}
export {
  T as CounterCharacterPlugin
};
