"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/inspector-controls/fill.js
var fill_exports = {};
__export(fill_exports, {
  default: () => InspectorControlsFill
});
module.exports = __toCommonJS(fill_exports);
var import_components = require("@wordpress/components");
var import_warning = __toESM(require("@wordpress/warning"));
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_element = require("@wordpress/element");
var import_context = require("../block-edit/context.cjs");
var import_groups = __toESM(require("./groups.cjs"));
var import_block_style_state = require("../../hooks/block-style-state.cjs");
var import_list_view_content_popover = require("./list-view-content-popover.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var PATTERN_EDITING_GROUPS = ["content", "list"];
function InspectorControlsFill({
  children,
  group = "default",
  __experimentalGroup,
  resetAllFilter
}) {
  if (__experimentalGroup) {
    (0, import_deprecated.default)(
      "`__experimentalGroup` property in `InspectorControlsFill`",
      {
        since: "6.2",
        version: "6.4",
        alternative: "`group`"
      }
    );
    group = __experimentalGroup;
  }
  const context = (0, import_context.useBlockEditContext)();
  const Fill = import_groups.default[group]?.Fill;
  if (!Fill) {
    (0, import_warning.default)(`Unknown InspectorControls group "${group}" provided.`);
    return null;
  }
  if (context[import_context.mayDisplayPatternEditingControlsKey]) {
    const isTemplatePart = context.name === "core/template-part";
    const isPatternEditingGroup = PATTERN_EDITING_GROUPS.includes(group);
    const canShowGroup = isTemplatePart || isPatternEditingGroup;
    if (!canShowGroup) {
      return null;
    }
  }
  if (!context[import_context.mayDisplayPatternEditingControlsKey] && !context[import_context.mayDisplayControlsKey]) {
    return null;
  }
  if (group === "content" && !!context[import_context.isInListViewBlockSupportTreeKey] && !!context[import_context.mayDisplayPatternEditingControlsKey]) {
    if (context[import_context.mayDisplayControlsKey]) {
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalStyleProvider, { document, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_list_view_content_popover.ListViewContentFill, { children }) });
    }
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalStyleProvider, { document, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Fill, { children: (fillProps) => {
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      ToolsPanelInspectorControl,
      {
        fillProps,
        children,
        resetAllFilter
      }
    );
  } }) });
}
function RegisterResetAll({ resetAllFilter, children }) {
  const { registerResetAllFilter, deregisterResetAllFilter } = (0, import_element.useContext)(import_components.__experimentalToolsPanelContext);
  const selectedState = (0, import_block_style_state.useBlockStyleState)();
  const scopedResetAllFilter = (0, import_element.useMemo)(
    () => (0, import_block_style_state.scopeResetAllFilterToState)(selectedState, resetAllFilter),
    [resetAllFilter, selectedState]
  );
  (0, import_element.useEffect)(() => {
    if (scopedResetAllFilter && registerResetAllFilter && deregisterResetAllFilter) {
      registerResetAllFilter(scopedResetAllFilter);
      return () => {
        deregisterResetAllFilter(scopedResetAllFilter);
      };
    }
  }, [
    scopedResetAllFilter,
    registerResetAllFilter,
    deregisterResetAllFilter
  ]);
  return children;
}
function ToolsPanelInspectorControl({ children, resetAllFilter, fillProps }) {
  const { forwardedContext = [] } = fillProps;
  const innerMarkup = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RegisterResetAll, { resetAllFilter, children });
  return forwardedContext.reduce(
    (inner, [Provider, props]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { ...props, children: inner }),
    innerMarkup
  );
}
//# sourceMappingURL=fill.cjs.map
