"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/hooks/elements.js
var elements_exports = {};
__export(elements_exports, {
  ElementsEdit: () => ElementsEdit
});
module.exports = __toCommonJS(elements_exports);
var import_blocks = require("@wordpress/blocks");
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_i18n = require("@wordpress/i18n");
var import_inspector_controls = __toESM(require("../components/inspector-controls/index.cjs"));
var import_color_panel = __toESM(require("../components/global-styles/color-panel.cjs"));
var import_utils = require("./utils.cjs");
var import_store = require("../store/index.cjs");
var import_color = require("./color.cjs");
var import_contrast_checker = __toESM(require("./contrast-checker.cjs"));
var import_block_style_state = require("./block-style-state.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function ElementsInspectorControl({ children, resetAllFilter }) {
  const attributesResetAllFilter = (0, import_element.useCallback)(
    (attributes) => {
      const updatedStyle = resetAllFilter(attributes.style);
      return {
        ...attributes,
        style: (0, import_utils.cleanEmptyObject)(updatedStyle)
      };
    },
    [resetAllFilter]
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_inspector_controls.default,
    {
      group: "elements",
      resetAllFilter: attributesResetAllFilter,
      children
    }
  );
}
function ElementsEdit({
  clientId,
  name,
  setAttributes,
  settings,
  asWrapper,
  label,
  defaultControls
}) {
  const selectedState = (0, import_block_style_state.useBlockStyleState)();
  const isEnabled = (0, import_color_panel.useHasColorPanel)(settings);
  const style = (0, import_data.useSelect)(
    (select) => {
      if (!isEnabled) {
        return void 0;
      }
      const attributes = select(import_store.store).getBlockAttributes(clientId);
      return attributes?.style;
    },
    [clientId, isEnabled]
  );
  const isStateSelected = !(0, import_block_style_state.isDefaultBlockStyleState)(selectedState);
  const value = (0, import_element.useMemo)(() => {
    if (isStateSelected) {
      return (0, import_block_style_state.getStyleForState)(style, selectedState);
    }
    return style;
  }, [isStateSelected, selectedState, style]);
  const onChange = isStateSelected ? (newStyle) => {
    setAttributes({
      style: (0, import_block_style_state.setStyleForState)(style, selectedState, newStyle)
    });
  } : (newStyle) => {
    setAttributes({ style: (0, import_utils.cleanEmptyObject)(newStyle) });
  };
  const enableContrastChecking = !isStateSelected && !!value?.elements?.link?.color?.text && settings?.color?.link && false !== (0, import_blocks.getBlockSupport)(name, [
    import_color.COLOR_SUPPORT_KEY,
    "enableContrastChecker"
  ]);
  const contrastWarning = (0, import_contrast_checker.default)({
    clientId,
    name,
    enabled: !!enableContrastChecking,
    checkTextColor: false,
    messageOverride: (0, import_i18n.__)(
      "This link color has poor contrast against the background. Consider increasing contrast."
    )
  });
  if (!isEnabled) {
    return null;
  }
  defaultControls = defaultControls ? defaultControls : (0, import_blocks.getBlockSupport)(name, [
    import_color.COLOR_SUPPORT_KEY,
    "__experimentalDefaultControls"
  ]);
  const Wrapper = asWrapper || ElementsInspectorControl;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_color_panel.default,
    {
      as: Wrapper,
      panelId: clientId,
      settings,
      value,
      onChange,
      defaultControls,
      label,
      contrastWarning
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ElementsEdit
});
//# sourceMappingURL=elements.cjs.map
