"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);
var shape_colors_modal_exports = {};
__export(shape_colors_modal_exports, {
  ShapeColorsModal: () => ShapeColorsModal
});
module.exports = __toCommonJS(shape_colors_modal_exports);
var import_design_system = require("@wix/design-system");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_resolve_color_to_display_hex = require("./../resolve-color-to-display-hex.js");
var import_ui_components = require("./../../ui-components/index.js");
const ShapeColorsModal = ({
  colorMap,
  onClose,
  isColorPickerOpen,
  openColorPickerFor,
  closeColorPicker
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const containerEl = (0, import_ui_components.usePanelContainerElement)();
  const colorEntries = (0, import_react.useMemo)(
    () => Object.entries(colorMap).map(([originalColor, customColor]) => ({
      originalColor,
      displayedColor: customColor || originalColor
    })),
    [colorMap]
  );
  (0, import_ui_components.useClickOutside)({
    containerRef: { current: containerEl },
    onClickOutside: () => {
      if (isColorPickerOpen()) {
        return;
      }
      onClose();
    }
  });
  const onColorClick = (entry) => {
    if (isColorPickerOpen()) {
      closeColorPicker();
      setTimeout(() => openColorPickerFor(entry, containerEl), 0);
    } else {
      openColorPickerFor(entry, containerEl);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(import_ui_components.Panel, { closeButtonProps: { onClick: onClose } }, /* @__PURE__ */ import_react.default.createElement(import_ui_components.PanelHeader, { title: t("Layout_SettingsModal_Tab_Design_Fill_Color") }), /* @__PURE__ */ import_react.default.createElement(
    import_design_system.Box,
    {
      paddingLeft: "SP3",
      paddingRight: "SP3",
      paddingTop: "SP2",
      paddingBottom: "SP2",
      direction: "horizontal",
      gap: "SP2",
      flexWrap: "wrap"
    },
    colorEntries.map((entry) => /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { key: entry.originalColor, height: "32px", width: "32px" }, /* @__PURE__ */ import_react.default.createElement(
      import_design_system.FillPreview,
      {
        fill: (0, import_resolve_color_to_display_hex.resolveColorToDisplayHex)(entry.displayedColor, containerEl, {
          preserveAlpha: true
        }) ?? entry.displayedColor,
        onClick: () => onColorClick(entry)
      }
    )))
  ));
};
//# sourceMappingURL=shape-colors-modal.js.map
