"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/background-panel.js
var background_panel_exports = {};
__export(background_panel_exports, {
  default: () => BackgroundImagePanel,
  hasBackgroundImageValue: () => hasBackgroundImageValue,
  hasBackgroundSizeValue: () => hasBackgroundSizeValue,
  useHasBackgroundPanel: () => useHasBackgroundPanel
});
module.exports = __toCommonJS(background_panel_exports);
var import_components = require("@wordpress/components");
var import_element = require("@wordpress/element");
var import_background_image_control = __toESM(require("../background-image-control"));
var import_utils = require("./utils");
var import_object = require("../../utils/object");
var import_i18n = require("@wordpress/i18n");
var import_jsx_runtime = require("react/jsx-runtime");
var DEFAULT_CONTROLS = {
  backgroundImage: true
};
function useHasBackgroundPanel(settings) {
  return import_element.Platform.OS === "web" && settings?.background?.backgroundImage;
}
function hasBackgroundSizeValue(style) {
  return style?.background?.backgroundPosition !== void 0 || style?.background?.backgroundSize !== void 0;
}
function hasBackgroundImageValue(style) {
  return !!style?.background?.backgroundImage?.id || // Supports url() string values in theme.json.
  "string" === typeof style?.background?.backgroundImage || !!style?.background?.backgroundImage?.url;
}
function BackgroundToolsPanel({
  resetAllFilter,
  onChange,
  value,
  panelId,
  children,
  headerLabel
}) {
  const dropdownMenuProps = (0, import_utils.useToolsPanelDropdownMenuProps)();
  const resetAll = () => {
    const updatedValue = resetAllFilter(value);
    onChange(updatedValue);
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.__experimentalToolsPanel,
    {
      label: headerLabel,
      resetAll,
      panelId,
      dropdownMenuProps,
      children
    }
  );
}
function BackgroundImagePanel({
  as: Wrapper = BackgroundToolsPanel,
  value,
  onChange,
  inheritedValue,
  settings,
  panelId,
  defaultControls = DEFAULT_CONTROLS,
  defaultValues = {},
  headerLabel = (0, import_i18n.__)("Background image")
}) {
  const showBackgroundImageControl = useHasBackgroundPanel(settings);
  const resetBackground = () => onChange((0, import_object.setImmutably)(value, ["background"], {}));
  const resetAllFilter = (0, import_element.useCallback)((previousValue) => {
    return {
      ...previousValue,
      background: {}
    };
  }, []);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    Wrapper,
    {
      resetAllFilter,
      value,
      onChange,
      panelId,
      headerLabel,
      children: showBackgroundImageControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_components.__experimentalToolsPanelItem,
        {
          hasValue: () => !!value?.background,
          label: (0, import_i18n.__)("Image"),
          onDeselect: resetBackground,
          isShownByDefault: defaultControls.backgroundImage,
          panelId,
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_background_image_control.default,
            {
              value,
              onChange,
              settings,
              inheritedValue,
              defaultControls,
              defaultValues
            }
          )
        }
      )
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  hasBackgroundImageValue,
  hasBackgroundSizeValue,
  useHasBackgroundPanel
});
//# sourceMappingURL=background-panel.js.map
