"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/hooks/states.js
var states_exports = {};
__export(states_exports, {
  BlockStateBadges: () => BlockStateBadges,
  BlockStatesControl: () => BlockStatesControl,
  PSEUDO_STATE_LABELS: () => PSEUDO_STATE_LABELS,
  RESPONSIVE_STATE_LABELS: () => RESPONSIVE_STATE_LABELS,
  VALID_BLOCK_PSEUDO_STATES: () => VALID_BLOCK_PSEUDO_STATES
});
module.exports = __toCommonJS(states_exports);
var import_blocks = require("@wordpress/blocks");
var import_i18n = require("@wordpress/i18n");
var import_state_control = __toESM(require("../components/global-styles/state-control.cjs"));
var import_state_control_badges = __toESM(require("../components/global-styles/state-control-badges.cjs"));
var import_utils = require("../components/global-styles/utils.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var PSEUDO_STATE_LABELS = {
  ":hover": (0, import_i18n.__)("Hover"),
  ":focus": (0, import_i18n.__)("Focus"),
  ":focus-visible": (0, import_i18n.__)("Focus-visible"),
  ":active": (0, import_i18n.__)("Active")
};
var RESPONSIVE_STATE_LABELS = {
  "@tablet": (0, import_i18n.__)("Tablet"),
  "@mobile": (0, import_i18n.__)("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 (!(0, import_blocks.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 = (0, import_utils.useToolsPanelDropdownMenuProps)();
  if (!viewportStateOptions.length && !pseudoStateOptions.length) {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_state_control.default,
    {
      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__ */ (0, import_jsx_runtime.jsx)(
    import_state_control_badges.default,
    {
      viewportStates: viewportStateOptions,
      pseudoStates: pseudoStateOptions,
      viewportValue: value?.viewport ?? DEFAULT_STATE_VALUE,
      pseudoStateValue: value?.pseudo ?? DEFAULT_STATE_VALUE
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BlockStateBadges,
  BlockStatesControl,
  PSEUDO_STATE_LABELS,
  RESPONSIVE_STATE_LABELS,
  VALID_BLOCK_PSEUDO_STATES
});
//# sourceMappingURL=states.cjs.map
