"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 single_color_swatch_exports = {};
__export(single_color_swatch_exports, {
  SingleColorSwatch: () => SingleColorSwatch
});
module.exports = __toCommonJS(single_color_swatch_exports);
var import_design_system = require("@wix/design-system");
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../../../ricos-context/index.js");
var import_colors = require("./../../../../../_shared/colors.js");
var import_data_hooks = require("../../data-hooks.js");
var import_single_color_swatch_scss = __toESM(require("./single-color-swatch-scss.js"));
const SingleColorSwatch = ({
  fill,
  selectedColor,
  onClick,
  onMouseEnter,
  onMouseLeave,
  onDelete,
  className,
  onFocus,
  setRef,
  index
}) => {
  const { t, portal } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const [isHovered, setIsHovered] = (0, import_react.useState)(false);
  const isTransparent = fill === import_colors.TRANSPARENT_HEX_COLOR;
  const tooltipContent = isTransparent ? t("ColorPicker_RemoveColor_Tooltip") : fill;
  const showDeleteButton = Boolean(onDelete) && !isTransparent && isHovered;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: import_single_color_swatch_scss.default.container,
      ref: setRef,
      onMouseEnter: () => setIsHovered(true),
      onMouseLeave: () => setIsHovered(false)
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Tooltip,
      {
        appendTo: portal,
        fixed: true,
        content: tooltipContent,
        dataHook: import_data_hooks.SWATCH_TOOLTIP,
        enterDelay: 1e3,
        size: "small",
        placement: "top",
        moveBy: { y: 10 },
        className
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_design_system.FillPreview,
        {
          id: index,
          selected: selectedColor?.toUpperCase() === fill.toUpperCase(),
          "aria-selected": selectedColor?.toUpperCase() === fill.toUpperCase(),
          onClick: (e) => {
            e.preventDefault();
            e.stopPropagation();
            onClick(fill);
          },
          onMouseEnter: () => onMouseEnter?.(fill),
          onMouseLeave,
          fill: isTransparent ? void 0 : fill,
          dataHook: import_data_hooks.SWATCH,
          onFocus,
          "aria-label": `${fill} color swatch`,
          tabIndex: -1,
          role: "option"
        }
      )
    ),
    showDeleteButton && /* @__PURE__ */ import_react.default.createElement(
      import_design_system.CloseButton,
      {
        className: import_single_color_swatch_scss.default.deleteButton,
        dataHook: import_data_hooks.DELETE_SWATCH_BUTTON,
        "aria-label": t("DeleteButton_Tooltip"),
        skin: "standardFilled",
        size: "small",
        onMouseDown: (event) => {
          event.stopPropagation();
        },
        onClick: (event) => {
          event.preventDefault();
          event.stopPropagation();
          onMouseLeave?.();
          onDelete?.(fill);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.DismissSmall, null)
    )
  );
};
//# sourceMappingURL=single-color-swatch.js.map
