"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/global-styles/state-control.js
var state_control_exports = {};
__export(state_control_exports, {
  default: () => StateControl
});
module.exports = __toCommonJS(state_control_exports);
var import_i18n = require("@wordpress/i18n");
var import_icons = require("@wordpress/icons");
var import_components = require("@wordpress/components");
var import_ui = require("@wordpress/ui");
var import_lock_unlock = require("../../lock-unlock.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var { Badge: WCBadge } = (0, import_lock_unlock.unlock)(import_components.privateApis);
function StateControl({
  viewportStates = [],
  pseudoStates = [],
  viewportValue = "default",
  pseudoStateValue = "default",
  onChangeViewport,
  onChangePseudoState
}) {
  if (!viewportStates.length && !pseudoStates.length) {
    return null;
  }
  const viewportOptions = [
    { label: (0, import_i18n.__)("Default"), value: "default" },
    ...viewportStates.map((state) => ({
      label: state.label,
      value: state.value
    }))
  ];
  const pseudoStateOptions = [
    { label: (0, import_i18n.__)("Default"), value: "default" },
    ...pseudoStates.map((state) => ({
      label: state.label,
      value: state.value
    }))
  ];
  const hasViewportOptions = viewportStates.length > 0;
  const hasPseudoStateOptions = pseudoStates.length > 0;
  const triggerLabel = (0, import_i18n.__)("States");
  const activeStates = [];
  if (hasViewportOptions && viewportValue !== "default") {
    const selectedViewport = viewportOptions.find(
      (option) => option.value === viewportValue
    );
    if (selectedViewport) {
      activeStates.push({
        key: `viewport-${selectedViewport.value}`,
        label: selectedViewport.label
      });
    }
  }
  if (hasPseudoStateOptions && pseudoStateValue !== "default") {
    const selectedPseudoState = pseudoStateOptions.find(
      (option) => option.value === pseudoStateValue
    );
    if (selectedPseudoState) {
      activeStates.push({
        key: `pseudo-${selectedPseudoState.value}`,
        label: selectedPseudoState.label
      });
    }
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    import_ui.Stack,
    {
      direction: "column",
      gap: "sm",
      align: "flex-end",
      className: "block-editor-global-styles-state-control",
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.DropdownMenu,
          {
            icon: import_icons.chevronDown,
            label: triggerLabel,
            popoverProps: {
              placement: "right-start"
            },
            text: triggerLabel,
            toggleProps: {
              size: "compact",
              variant: "tertiary",
              iconPosition: "right"
            },
            children: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
              hasViewportOptions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Viewport"), children: viewportOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_components.MenuItem,
                {
                  onClick: () => {
                    onChangeViewport?.(option.value);
                    if (!hasPseudoStateOptions) {
                      onClose();
                    }
                  },
                  icon: viewportValue === option.value ? import_icons.check : null,
                  children: option.label
                },
                `viewport-${option.value}`
              )) }),
              hasPseudoStateOptions && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Pseudo state"), children: pseudoStateOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_components.MenuItem,
                {
                  onClick: () => {
                    onChangePseudoState?.(
                      option.value
                    );
                    if (!hasViewportOptions) {
                      onClose();
                    }
                  },
                  icon: pseudoStateValue === option.value ? import_icons.check : null,
                  children: option.label
                },
                `pseudo-${option.value}`
              )) })
            ] })
          }
        ),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_ui.Stack,
          {
            className: "block-editor-global-styles-state-control__badges",
            direction: "row",
            justify: "flex-start",
            gap: "xs",
            wrap: "wrap",
            children: activeStates.map((activeState) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WCBadge, { intent: "info", children: activeState.label }, activeState.key))
          }
        )
      ]
    }
  );
}
//# sourceMappingURL=state-control.cjs.map
