"use client";
import { jsxs as f, jsx as o } from "react/jsx-runtime";
import { useLexicalComposerContext as u } from "../../../../node_modules/@lexical/react/LexicalComposerContext.prod.js";
import { mergeRegister as N } from "../../../../node_modules/@lexical/utils/LexicalUtils.prod.js";
import { CAN_REDO_COMMAND as b, COMMAND_PRIORITY_CRITICAL as n, CAN_UNDO_COMMAND as R, UNDO_COMMAND as M, REDO_COMMAND as O } from "../../../../node_modules/lexical/Lexical.prod.js";
import { useState as s, useEffect as D } from "react";
import { useToolbarContext as g } from "../../context/toolbar-context.js";
import { Button as d } from "../../../ui/button.js";
import x from "../../../../node_modules/lucide-react/dist/esm/icons/undo.js";
import A from "../../../../node_modules/lucide-react/dist/esm/icons/redo.js";
function j() {
  const [i] = u(), { activeEditor: t, $updateToolbar: a } = g(), [r, l] = s(i.isEditable()), [m, c] = s(!1), [C, p] = s(!1);
  return D(() => N(
    i.registerEditableListener((e) => {
      l(e);
    }),
    t.registerUpdateListener(({ editorState: e }) => {
      e.read(() => {
        a();
      });
    }),
    t.registerCommand(
      R,
      (e) => (c(e), !1),
      n
    ),
    t.registerCommand(
      b,
      (e) => (p(e), !1),
      n
    )
  ), [a, t, i]), /* @__PURE__ */ f("div", { className: "flex items-center gap-1", children: [
    /* @__PURE__ */ o(
      d,
      {
        disabled: !m || !r,
        onClick: () => {
          t.dispatchCommand(M, void 0);
        },
        title: "Undo (⌘Z)",
        type: "button",
        "aria-label": "Undo",
        size: "icon",
        className: "!h-8 !w-8",
        variant: "outline",
        children: /* @__PURE__ */ o(x, { className: "size-4" })
      }
    ),
    /* @__PURE__ */ o(
      d,
      {
        disabled: !C || !r,
        onClick: () => {
          t.dispatchCommand(O, void 0);
        },
        title: "Redo (⇧⌘Z)",
        type: "button",
        "aria-label": "Redo",
        variant: "outline",
        size: "icon",
        className: "!h-8 !w-8",
        children: /* @__PURE__ */ o(A, { className: "size-4" })
      }
    )
  ] });
}
export {
  j as HistoryToolbarPlugin
};
