"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/colors-gradients/dropdown.js
var dropdown_exports = {};
__export(dropdown_exports, {
  default: () => ColorGradientSettingsDropdown
});
module.exports = __toCommonJS(dropdown_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("./control"));
var import_jsx_runtime = require("react/jsx-runtime");
var WithToolsPanelItem = ({ setting, children, panelId, ...props }) => {
  const clearValue = () => {
    if (setting.colorValue) {
      setting.onColorChange();
    } else if (setting.gradientValue) {
      setting.onGradientChange();
    }
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.__experimentalToolsPanelItem,
    {
      hasValue: () => {
        return !!setting.colorValue || !!setting.gradientValue;
      },
      label: setting.label,
      onDeselect: clearValue,
      isShownByDefault: setting.isShownByDefault !== void 0 ? setting.isShownByDefault : true,
      ...props,
      className: "block-editor-tools-panel-color-gradient-settings__item",
      panelId,
      resetAllFilter: setting.resetAllFilter,
      children
    }
  );
};
var LabeledColorIndicator = ({ colorValue, label }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "flex-start", children: [
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.ColorIndicator,
    {
      className: "block-editor-panel-color-gradient-settings__color-indicator",
      colorValue
    }
  ),
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.FlexItem,
    {
      className: "block-editor-panel-color-gradient-settings__color-name",
      title: label,
      children: label
    }
  )
] });
var renderToggle = (settings) => ({ onToggle, isOpen }) => {
  const {
    clearable,
    colorValue,
    gradientValue,
    onColorChange,
    onGradientChange,
    label
  } = settings;
  const colorButtonRef = (0, import_element.useRef)(void 0);
  const toggleProps = {
    onClick: onToggle,
    className: (0, import_clsx.default)(
      "block-editor-panel-color-gradient-settings__dropdown",
      { "is-open": isOpen }
    ),
    "aria-expanded": isOpen,
    ref: colorButtonRef
  };
  const clearValue = () => {
    if (colorValue) {
      onColorChange();
    } else if (gradientValue) {
      onGradientChange();
    }
  };
  const value = colorValue ?? gradientValue;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, { __next40pxDefaultSize: true, ...toggleProps, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      LabeledColorIndicator,
      {
        colorValue: value,
        label
      }
    ) }),
    clearable && value && /* @__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: () => {
          clearValue();
          if (isOpen) {
            onToggle();
          }
          colorButtonRef.current?.focus();
        }
      }
    )
  ] });
};
function ColorGradientSettingsDropdown({
  colors,
  disableCustomColors,
  disableCustomGradients,
  enableAlpha,
  gradients,
  settings,
  __experimentalIsRenderedInSidebar,
  ...props
}) {
  let popoverProps;
  if (__experimentalIsRenderedInSidebar) {
    popoverProps = {
      placement: "left-start",
      offset: 36,
      shift: true
    };
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: settings.map((setting, index) => {
    const controlProps = {
      clearable: false,
      colorValue: setting.colorValue,
      colors,
      disableCustomColors,
      disableCustomGradients,
      enableAlpha,
      gradientValue: setting.gradientValue,
      gradients,
      label: setting.label,
      onColorChange: setting.onColorChange,
      onGradientChange: setting.onGradientChange,
      showTitle: false,
      __experimentalIsRenderedInSidebar,
      ...setting
    };
    const toggleSettings = {
      clearable: setting.clearable,
      label: setting.label,
      colorValue: setting.colorValue,
      gradientValue: setting.gradientValue,
      onColorChange: setting.onColorChange,
      onGradientChange: setting.onGradientChange
    };
    return setting && // If not in an `ItemGroup` wrap the dropdown in a
    // `ToolsPanelItem`
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      WithToolsPanelItem,
      {
        setting,
        ...props,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.Dropdown,
          {
            popoverProps,
            className: "block-editor-tools-panel-color-gradient-settings__dropdown",
            renderToggle: renderToggle(toggleSettings),
            renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalDropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-panel-color-gradient-settings__dropdown-content", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_control.default,
              {
                ...controlProps
              }
            ) }) })
          }
        )
      },
      index
    );
  }) });
}
//# sourceMappingURL=dropdown.js.map
