"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/panel-color-gradient-settings.js
var panel_color_gradient_settings_exports = {};
__export(panel_color_gradient_settings_exports, {
  PanelColorGradientSettingsInner: () => PanelColorGradientSettingsInner,
  default: () => panel_color_gradient_settings_default
});
module.exports = __toCommonJS(panel_color_gradient_settings_exports);
var import_clsx = __toESM(require("clsx"));
var import_components = require("@wordpress/components");
var import_data = require("@wordpress/data");
var import_compose = require("@wordpress/compose");
var import_dropdown = __toESM(require("./dropdown"));
var import_use_multiple_origin_colors_and_gradients = __toESM(require("./use-multiple-origin-colors-and-gradients"));
var import_jsx_runtime = require("react/jsx-runtime");
var colorsAndGradientKeys = [
  "colors",
  "disableCustomColors",
  "gradients",
  "disableCustomGradients"
];
var PanelColorGradientSettingsInner = ({
  className,
  colors,
  gradients,
  disableCustomColors,
  disableCustomGradients,
  children,
  settings,
  title,
  showTitle = true,
  __experimentalIsRenderedInSidebar,
  enableAlpha
}) => {
  const panelId = (0, import_compose.useInstanceId)(PanelColorGradientSettingsInner);
  const { batch } = (0, import_data.useRegistry)();
  if ((!colors || colors.length === 0) && (!gradients || gradients.length === 0) && disableCustomColors && disableCustomGradients && settings?.every(
    (setting) => (!setting.colors || setting.colors.length === 0) && (!setting.gradients || setting.gradients.length === 0) && (setting.disableCustomColors === void 0 || setting.disableCustomColors) && (setting.disableCustomGradients === void 0 || setting.disableCustomGradients)
  )) {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    import_components.__experimentalToolsPanel,
    {
      className: (0, import_clsx.default)(
        "block-editor-panel-color-gradient-settings",
        className
      ),
      label: showTitle ? title : void 0,
      resetAll: () => {
        batch(() => {
          settings.forEach(
            ({
              colorValue,
              gradientValue,
              onColorChange,
              onGradientChange
            }) => {
              if (colorValue) {
                onColorChange();
              } else if (gradientValue) {
                onGradientChange();
              }
            }
          );
        });
      },
      panelId,
      __experimentalFirstVisibleItemClass: "first",
      __experimentalLastVisibleItemClass: "last",
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_dropdown.default,
          {
            settings,
            panelId,
            ...{
              colors,
              gradients,
              disableCustomColors,
              disableCustomGradients,
              __experimentalIsRenderedInSidebar,
              enableAlpha
            }
          }
        ),
        !!children && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalSpacer, { marginY: 4 }),
          " ",
          children
        ] })
      ]
    }
  );
};
var PanelColorGradientSettingsSelect = (props) => {
  const colorGradientSettings = (0, import_use_multiple_origin_colors_and_gradients.default)();
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    PanelColorGradientSettingsInner,
    {
      ...{ ...colorGradientSettings, ...props }
    }
  );
};
var PanelColorGradientSettings = (props) => {
  if (colorsAndGradientKeys.every((key) => props.hasOwnProperty(key))) {
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PanelColorGradientSettingsInner, { ...props });
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PanelColorGradientSettingsSelect, { ...props });
};
var panel_color_gradient_settings_default = PanelColorGradientSettings;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PanelColorGradientSettingsInner
});
//# sourceMappingURL=panel-color-gradient-settings.js.map
