// packages/block-editor/src/components/inspector-controls/fill.js
import {
  __experimentalStyleProvider as StyleProvider,
  __experimentalToolsPanelContext as ToolsPanelContext
} from "@wordpress/components";
import warning from "@wordpress/warning";
import deprecated from "@wordpress/deprecated";
import { useEffect, useContext } from "@wordpress/element";
import {
  useBlockEditContext,
  mayDisplayControlsKey
} from "../block-edit/context.mjs";
import groups from "./groups.mjs";
import { jsx } from "react/jsx-runtime";
function PrivateInspectorControlsFill({
  children,
  group = "default",
  __experimentalGroup,
  resetAllFilter,
  forceDisplayControls
}) {
  if (__experimentalGroup) {
    deprecated(
      "`__experimentalGroup` property in `InspectorControlsFill`",
      {
        since: "6.2",
        version: "6.4",
        alternative: "`group`"
      }
    );
    group = __experimentalGroup;
  }
  const context = useBlockEditContext();
  const Fill = groups[group]?.Fill;
  if (!Fill) {
    warning(`Unknown InspectorControls group "${group}" provided.`);
    return null;
  }
  if (!forceDisplayControls && !context[mayDisplayControlsKey]) {
    return null;
  }
  return /* @__PURE__ */ jsx(StyleProvider, { document, children: /* @__PURE__ */ jsx(Fill, { children: (fillProps) => {
    return /* @__PURE__ */ jsx(
      ToolsPanelInspectorControl,
      {
        fillProps,
        children,
        resetAllFilter
      }
    );
  } }) });
}
function InspectorControlsFill({
  children,
  group = "default",
  __experimentalGroup,
  resetAllFilter
}) {
  return /* @__PURE__ */ jsx(
    PrivateInspectorControlsFill,
    {
      group,
      __experimentalGroup,
      resetAllFilter,
      children
    }
  );
}
function RegisterResetAll({ resetAllFilter, children }) {
  const { registerResetAllFilter, deregisterResetAllFilter } = useContext(ToolsPanelContext);
  useEffect(() => {
    if (resetAllFilter && registerResetAllFilter && deregisterResetAllFilter) {
      registerResetAllFilter(resetAllFilter);
      return () => {
        deregisterResetAllFilter(resetAllFilter);
      };
    }
  }, [resetAllFilter, registerResetAllFilter, deregisterResetAllFilter]);
  return children;
}
function ToolsPanelInspectorControl({ children, resetAllFilter, fillProps }) {
  const { forwardedContext = [] } = fillProps;
  const innerMarkup = /* @__PURE__ */ jsx(RegisterResetAll, { resetAllFilter, children });
  return forwardedContext.reduce(
    (inner, [Provider, props]) => /* @__PURE__ */ jsx(Provider, { ...props, children: inner }),
    innerMarkup
  );
}
export {
  PrivateInspectorControlsFill,
  InspectorControlsFill as default
};
//# sourceMappingURL=fill.mjs.map
