// packages/block-editor/src/components/inspector-controls/block-support-tools-panel.js
import { __experimentalToolsPanel as ToolsPanel } from "@wordpress/components";
import { useDispatch, useSelect } from "@wordpress/data";
import { useCallback } from "@wordpress/element";
import { store as blockEditorStore } from "../../store/index.mjs";
import { cleanEmptyObject } from "../../hooks/utils.mjs";
import { useToolsPanelDropdownMenuProps } from "../global-styles/utils.mjs";
import { jsx } from "react/jsx-runtime";
function BlockSupportToolsPanel({ children, group, label }) {
  const { updateBlockAttributes } = useDispatch(blockEditorStore);
  const {
    getBlockAttributes,
    getBlockName,
    getMultiSelectedBlockClientIds,
    getSelectedBlockClientId,
    hasMultiSelection
  } = useSelect(blockEditorStore);
  const dropdownMenuProps = useToolsPanelDropdownMenuProps();
  const panelId = getSelectedBlockClientId();
  const resetAll = useCallback(
    (resetFilters = []) => {
      const newAttributes = {};
      const clientIds = hasMultiSelection() ? getMultiSelectedBlockClientIds() : [panelId];
      clientIds.forEach((clientId) => {
        const blockAttributes = getBlockAttributes(clientId) || {};
        const { style } = blockAttributes;
        let newBlockAttributes = { style };
        const resetContext = {
          attributes: blockAttributes,
          clientId,
          name: getBlockName(clientId)
        };
        resetFilters.forEach((resetFilter) => {
          newBlockAttributes = {
            ...newBlockAttributes,
            ...resetFilter(newBlockAttributes, resetContext)
          };
        });
        newBlockAttributes = {
          ...newBlockAttributes,
          style: cleanEmptyObject(newBlockAttributes.style)
        };
        newAttributes[clientId] = newBlockAttributes;
      });
      updateBlockAttributes(clientIds, newAttributes, true);
    },
    [
      getBlockAttributes,
      getBlockName,
      getMultiSelectedBlockClientIds,
      hasMultiSelection,
      panelId,
      updateBlockAttributes
    ]
  );
  return /* @__PURE__ */ jsx(
    ToolsPanel,
    {
      className: `${group}-block-support-panel`,
      label,
      resetAll,
      panelId,
      hasInnerWrapper: true,
      shouldRenderPlaceholderItems: true,
      __experimentalFirstVisibleItemClass: "first",
      __experimentalLastVisibleItemClass: "last",
      dropdownMenuProps,
      children
    },
    panelId
  );
}
export {
  BlockSupportToolsPanel as default
};
//# sourceMappingURL=block-support-tools-panel.mjs.map
