// packages/block-editor/src/hooks/states.js
import { getBlockType } from "@wordpress/blocks";
import { __ } from "@wordpress/i18n";
import StateControl from "../components/global-styles/state-control.mjs";
import StateControlBadges from "../components/global-styles/state-control-badges.mjs";
import { useToolsPanelDropdownMenuProps } from "../components/global-styles/utils.mjs";
import { jsx } from "react/jsx-runtime";
var PSEUDO_STATE_LABELS = {
  ":hover": __("Hover"),
  ":focus": __("Focus"),
  ":focus-visible": __("Focus-visible"),
  ":active": __("Active")
};
var RESPONSIVE_STATE_LABELS = {
  "@tablet": __("Tablet"),
  "@mobile": __("Mobile")
};
var VALID_BLOCK_PSEUDO_STATES = {
  "core/button": [":hover", ":focus", ":focus-visible", ":active"],
  "core/navigation-link": [":hover", ":focus", ":focus-visible", ":active"]
};
function getPseudoStateOptions(name) {
  const validStates = VALID_BLOCK_PSEUDO_STATES[name] ?? [];
  return validStates.filter((state) => PSEUDO_STATE_LABELS[state]).map((state) => ({
    value: state,
    label: PSEUDO_STATE_LABELS[state]
  }));
}
var DEFAULT_STATE_VALUE = "default";
function getViewportStateOptions(name) {
  if (!getBlockType(name)?.attributes?.style) {
    return [];
  }
  return Object.entries(RESPONSIVE_STATE_LABELS).map(
    ([value, label]) => ({
      value,
      label
    })
  );
}
function BlockStatesControl({ name, value, onChange }) {
  const viewportStateOptions = getViewportStateOptions(name);
  const pseudoStateOptions = getPseudoStateOptions(name);
  const dropdownMenuProps = useToolsPanelDropdownMenuProps();
  if (!viewportStateOptions.length && !pseudoStateOptions.length) {
    return null;
  }
  return /* @__PURE__ */ jsx(
    StateControl,
    {
      viewportStates: viewportStateOptions,
      pseudoStates: pseudoStateOptions,
      viewportValue: value?.viewport ?? DEFAULT_STATE_VALUE,
      pseudoStateValue: value?.pseudo ?? DEFAULT_STATE_VALUE,
      onChangeViewport: (viewport) => onChange({ viewport }),
      onChangePseudoState: (pseudo) => onChange({ pseudo }),
      popoverProps: dropdownMenuProps.popoverProps,
      showText: false
    }
  );
}
function BlockStateBadges({ name, value }) {
  const viewportStateOptions = getViewportStateOptions(name);
  const pseudoStateOptions = getPseudoStateOptions(name);
  if (!viewportStateOptions.length && !pseudoStateOptions.length) {
    return null;
  }
  return /* @__PURE__ */ jsx(
    StateControlBadges,
    {
      viewportStates: viewportStateOptions,
      pseudoStates: pseudoStateOptions,
      viewportValue: value?.viewport ?? DEFAULT_STATE_VALUE,
      pseudoStateValue: value?.pseudo ?? DEFAULT_STATE_VALUE
    }
  );
}
export {
  BlockStateBadges,
  BlockStatesControl,
  PSEUDO_STATE_LABELS,
  RESPONSIVE_STATE_LABELS,
  VALID_BLOCK_PSEUDO_STATES
};
//# sourceMappingURL=states.mjs.map
