"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BlockRemovalWarningModal = BlockRemovalWarningModal;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function BlockRemovalWarningModal({
  rules
}) {
  const {
    clientIds,
    selectPrevious,
    message
  } = (0, _data.useSelect)(select => (0, _lockUnlock.unlock)(select(_store.store)).getRemovalPromptData());
  const {
    clearBlockRemovalPrompt,
    setBlockRemovalRules,
    privateRemoveBlocks
  } = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));

  // Load block removal rules, simultaneously signalling that the block
  // removal prompt is in place.
  (0, _element.useEffect)(() => {
    setBlockRemovalRules(rules);
    return () => {
      setBlockRemovalRules();
    };
  }, [rules, setBlockRemovalRules]);
  if (!message) {
    return;
  }
  const onConfirmRemoval = () => {
    privateRemoveBlocks(clientIds, selectPrevious, /* force */true);
    clearBlockRemovalPrompt();
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Modal, {
    title: (0, _i18n.__)('Be careful!'),
    onRequestClose: clearBlockRemovalPrompt,
    size: "medium",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
      children: message
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
      justify: "right",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
        variant: "tertiary",
        onClick: clearBlockRemovalPrompt,
        __next40pxDefaultSize: true,
        children: (0, _i18n.__)('Cancel')
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
        variant: "primary",
        onClick: onConfirmRemoval,
        __next40pxDefaultSize: true,
        children: (0, _i18n.__)('Delete')
      })]
    })]
  });
}
//# sourceMappingURL=index.js.map