"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/components/global-styles/color-gradient-dropdown-item.js
var color_gradient_dropdown_item_exports = {};
__export(color_gradient_dropdown_item_exports, {
  default: () => ColorGradientDropdownItem
});
module.exports = __toCommonJS(color_gradient_dropdown_item_exports);
var import_clsx = __toESM(require("clsx"));
var import_components = require("@wordpress/components");
var import_element = require("@wordpress/element");
var import_i18n = require("@wordpress/i18n");
var import_icons = require("@wordpress/icons");
var import_control = __toESM(require("../colors-gradients/control.cjs"));
var import_lock_unlock = require("../../lock-unlock.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
function DropdownContent({
  tabs,
  colorGradientControlSettings,
  contrastWarning
}) {
  const { key: firstTabKey, ...firstTab } = tabs[0] ?? {};
  const defaultTabId = tabs.find(
    (tab) => tab.userValue !== void 0
  )?.key;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "block-editor-panel-color-gradient-settings__dropdown-content", children: [
    tabs.length === 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      ColorGradientTab,
      {
        ...firstTab,
        colorGradientControlSettings,
        contrastWarning
      },
      firstTabKey
    ),
    tabs.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tabs, { defaultTabId, children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.TabList, { children: tabs.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Tab, { tabId: tab.key, children: tab.label }, tab.key)) }),
      tabs.map((tab) => {
        const { key: tabKey, ...restTabProps } = tab;
        return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          Tabs.TabPanel,
          {
            tabId: tabKey,
            focusable: false,
            children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              ColorGradientTab,
              {
                ...restTabProps,
                colorGradientControlSettings,
                contrastWarning
              },
              tabKey
            )
          },
          tabKey
        );
      })
    ] })
  ] }) });
}
var popoverProps = {
  placement: "left-start",
  offset: 36,
  shift: true
};
var LabeledColorIndicators = ({ indicators, label }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "flex-start", children: [
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalZStack, { isLayered: false, offset: -8, children: indicators.map((indicator, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Flex, { expanded: false, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ColorIndicator, { colorValue: indicator }) }, index)) }),
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.FlexItem, { className: "block-editor-panel-color-gradient-settings__color-name", children: label })
] });
function ColorGradientTab({
  isGradient,
  inheritedValue,
  inheritedSlug,
  userValue,
  setValue,
  colorGradientControlSettings,
  contrastWarning
}) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_control.default,
    {
      ...colorGradientControlSettings,
      showTitle: false,
      enableAlpha: true,
      __experimentalIsRenderedInSidebar: true,
      colorValue: isGradient ? void 0 : inheritedValue,
      colorSlug: isGradient ? void 0 : inheritedSlug,
      gradientValue: isGradient ? inheritedValue : void 0,
      onColorChange: isGradient ? void 0 : setValue,
      onGradientChange: isGradient ? setValue : void 0,
      clearable: inheritedValue === userValue,
      headingLevel: 3,
      noticeProps: !isGradient && contrastWarning ? {
        children: contrastWarning,
        status: "warning",
        spokenMessage: null,
        className: "block-editor-panel-color-gradient-settings__contrast-notice"
      } : void 0
    }
  );
}
function ColorGradientDropdownItem({
  label,
  hasValue,
  resetValue,
  isShownByDefault,
  indicators,
  tabs,
  colorGradientControlSettings,
  panelId,
  contrastWarning,
  className = "block-editor-tools-panel-color-gradient-settings__item"
}) {
  const colorGradientDropdownButtonRef = (0, import_element.useRef)(void 0);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.__experimentalToolsPanelItem,
    {
      className: (0, import_clsx.default)("block-editor-color-gradient-item", className),
      hasValue,
      label,
      onDeselect: resetValue,
      isShownByDefault,
      panelId,
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_components.Dropdown,
        {
          popoverProps,
          className: "block-editor-tools-panel-color-gradient-settings__dropdown",
          renderToggle: ({ onToggle, isOpen }) => {
            const toggleProps = {
              onClick: onToggle,
              className: (0, import_clsx.default)(
                "block-editor-panel-color-gradient-settings__dropdown",
                {
                  "is-open": isOpen,
                  "has-contrast-warning": !!contrastWarning
                }
              ),
              "aria-expanded": isOpen,
              ref: colorGradientDropdownButtonRef
            };
            return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, { ...toggleProps, __next40pxDefaultSize: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                LabeledColorIndicators,
                {
                  indicators,
                  label
                }
              ) }),
              hasValue() && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_components.Button,
                {
                  __next40pxDefaultSize: true,
                  label: (0, import_i18n.__)("Reset"),
                  className: "block-editor-panel-color-gradient-settings__reset",
                  size: "small",
                  icon: import_icons.reset,
                  onClick: () => {
                    resetValue();
                    if (isOpen) {
                      onToggle();
                    }
                    colorGradientDropdownButtonRef.current?.focus();
                  }
                }
              ),
              contrastWarning && // An icon-only warning that stays visible while a
              // contrast warning is in effect. It is not a menu;
              // activating it opens the color picker popover where
              // the full warning notice is shown, so the indicator
              // doubles as a shortcut to where the issue is fixed.
              /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_components.Button,
                {
                  __next40pxDefaultSize: true,
                  size: "small",
                  icon: import_icons.caution,
                  label: (0, import_i18n.__)("Low contrast"),
                  className: "block-editor-panel-color-gradient-settings__contrast-warning",
                  "aria-expanded": isOpen,
                  onClick: onToggle
                }
              )
            ] });
          },
          renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            DropdownContent,
            {
              tabs,
              colorGradientControlSettings,
              contrastWarning
            }
          )
        }
      )
    }
  );
}
//# sourceMappingURL=color-gradient-dropdown-item.cjs.map
