// packages/block-editor/src/components/block-removal-warning-modal/index.js
import { useEffect } from "@wordpress/element";
import { useDispatch, useSelect } from "@wordpress/data";
import {
  Modal,
  Button,
  __experimentalHStack as HStack
} from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { store as blockEditorStore } from "../../store";
import { unlock } from "../../lock-unlock";
import { jsx, jsxs } from "react/jsx-runtime";
function BlockRemovalWarningModal({ rules }) {
  const { clientIds, selectPrevious, message } = useSelect(
    (select) => unlock(select(blockEditorStore)).getRemovalPromptData()
  );
  const {
    clearBlockRemovalPrompt,
    setBlockRemovalRules,
    privateRemoveBlocks
  } = unlock(useDispatch(blockEditorStore));
  useEffect(() => {
    setBlockRemovalRules(rules);
    return () => {
      setBlockRemovalRules();
    };
  }, [rules, setBlockRemovalRules]);
  if (!message) {
    return;
  }
  const onConfirmRemoval = () => {
    privateRemoveBlocks(
      clientIds,
      selectPrevious,
      /* force */
      true
    );
    clearBlockRemovalPrompt();
  };
  return /* @__PURE__ */ jsxs(
    Modal,
    {
      title: __("Be careful!"),
      onRequestClose: clearBlockRemovalPrompt,
      size: "medium",
      children: [
        /* @__PURE__ */ jsx("p", { children: message }),
        /* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
          /* @__PURE__ */ jsx(
            Button,
            {
              variant: "tertiary",
              onClick: clearBlockRemovalPrompt,
              __next40pxDefaultSize: true,
              children: __("Cancel")
            }
          ),
          /* @__PURE__ */ jsx(
            Button,
            {
              variant: "primary",
              onClick: onConfirmRemoval,
              __next40pxDefaultSize: true,
              children: __("Delete")
            }
          )
        ] })
      ]
    }
  );
}
export {
  BlockRemovalWarningModal
};
//# sourceMappingURL=index.js.map
