'use client';

import { c as _c } from "react/compiler-runtime";
import { jsx as _jsx } from "react/jsx-runtime";
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
import { TabIndentationPlugin } from '@lexical/react/LexicalTabIndentationPlugin';
import { mergeRegister } from '@lexical/utils';
import { COMMAND_PRIORITY_NORMAL, FOCUS_COMMAND, KEY_ESCAPE_COMMAND } from 'lexical';
import { useEffect, useState } from 'react';
export const IndentPlugin = () => {
  const $ = _c(8);
  const [editor] = useLexicalComposerContext();
  const [firefoxFlag, setFirefoxFlag] = useState(false);
  let t0;
  let t1;
  if ($[0] !== editor) {
    t0 = () => mergeRegister(editor.registerCommand(FOCUS_COMMAND, () => {
      setFirefoxFlag(false);
      return true;
    }, COMMAND_PRIORITY_NORMAL), editor.registerCommand(KEY_ESCAPE_COMMAND, () => {
      setFirefoxFlag(true);
      editor.getRootElement()?.blur();
      return true;
    }, COMMAND_PRIORITY_NORMAL));
    t1 = [editor, setFirefoxFlag];
    $[0] = editor;
    $[1] = t0;
    $[2] = t1;
  } else {
    t0 = $[1];
    t1 = $[2];
  }
  useEffect(t0, t1);
  let t2;
  let t3;
  if ($[3] !== editor || $[4] !== firefoxFlag) {
    t2 = () => {
      if (!firefoxFlag) {
        return;
      }
      const handleKeyDown = e => {
        if (!["Escape", "Shift"].includes(e.key)) {
          setFirefoxFlag(false);
        }
        if (e.shiftKey && e.key === "Tab") {
          editor.getRootElement()?.parentElement?.focus();
        }
      };
      document.addEventListener("keydown", handleKeyDown);
      return () => {
        document.removeEventListener("keydown", handleKeyDown);
      };
    };
    t3 = [editor, firefoxFlag];
    $[3] = editor;
    $[4] = firefoxFlag;
    $[5] = t2;
    $[6] = t3;
  } else {
    t2 = $[5];
    t3 = $[6];
  }
  useEffect(t2, t3);
  let t4;
  if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = _jsx(TabIndentationPlugin, {});
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  return t4;
};
//# sourceMappingURL=index.js.map