// packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js
import { __experimentalUseSlotFills as useSlotFills } from "@wordpress/components";
import { useSelect } from "@wordpress/data";
import InspectorControlsGroups from "../inspector-controls/groups";
import useIsListViewTabDisabled from "./use-is-list-view-tab-disabled";
import { InspectorAdvancedControls } from "../inspector-controls";
import { TAB_LIST_VIEW, TAB_SETTINGS, TAB_STYLES, TAB_CONTENT } from "./utils";
import { store as blockEditorStore } from "../../store";
var EMPTY_ARRAY = [];
function getShowTabs(blockName, tabSettings = {}) {
  if (tabSettings[blockName] !== void 0) {
    return tabSettings[blockName];
  }
  if (tabSettings.default !== void 0) {
    return tabSettings.default;
  }
  return true;
}
function useInspectorControlsTabs(blockName, contentClientIds, isSectionBlock, hasBlockStyles) {
  const tabs = [];
  const {
    bindings: bindingsGroup,
    border: borderGroup,
    color: colorGroup,
    default: defaultGroup,
    dimensions: dimensionsGroup,
    list: listGroup,
    position: positionGroup,
    styles: stylesGroup,
    typography: typographyGroup,
    effects: effectsGroup
  } = InspectorControlsGroups;
  const listViewDisabled = useIsListViewTabDisabled(blockName);
  const listFills = useSlotFills(listGroup.name);
  const hasListFills = !listViewDisabled && !!listFills && listFills.length;
  const styleFills = [
    ...useSlotFills(borderGroup.name) || [],
    ...useSlotFills(colorGroup.name) || [],
    ...useSlotFills(dimensionsGroup.name) || [],
    ...useSlotFills(stylesGroup.name) || [],
    ...useSlotFills(typographyGroup.name) || [],
    ...useSlotFills(effectsGroup.name) || []
  ];
  const hasStyleFills = styleFills.length;
  const advancedFills = [
    ...useSlotFills(InspectorAdvancedControls.slotName) || [],
    ...useSlotFills(bindingsGroup.name) || []
  ];
  const settingsFills = [
    ...useSlotFills(defaultGroup.name) || [],
    ...useSlotFills(positionGroup.name) || [],
    ...hasListFills && hasStyleFills > 1 ? advancedFills : []
  ];
  const hasContentTab = !!(contentClientIds && contentClientIds.length > 0);
  if (hasListFills && !isSectionBlock) {
    tabs.push(TAB_LIST_VIEW);
  }
  if (hasContentTab) {
    tabs.push(TAB_CONTENT);
  }
  if (settingsFills.length && !isSectionBlock) {
    tabs.push(TAB_SETTINGS);
  }
  if (hasBlockStyles || hasStyleFills) {
    tabs.push(TAB_STYLES);
  }
  const tabSettings = useSelect((select) => {
    return select(blockEditorStore).getSettings().blockInspectorTabs;
  }, []);
  const showTabs = getShowTabs(blockName, tabSettings);
  return showTabs ? tabs : EMPTY_ARRAY;
}
export {
  useInspectorControlsTabs as default
};
//# sourceMappingURL=use-inspector-controls-tabs.js.map
