"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 gradient_stop_editor_exports = {};
__export(gradient_stop_editor_exports, {
  GradientStopEditor: () => GradientStopEditor
});
module.exports = __toCommonJS(gradient_stop_editor_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_resolve_color_to_display_hex = require("./../../../../../_shared/resolve-color-to-display-hex.js");
var import_wix_rich_content_common = require("./../../../../../wix-rich-content-common/index.js");
var import_ui_components_provider = require("./../../../../ui-components-provider.js");
const GradientStopEditor = ({
  value,
  stop,
  onChange,
  originalIndex,
  onColorPickerOpen
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const panelContainerEl = (0, import_ui_components_provider.usePanelContainerElement)();
  const [containerElement, setContainerElement] = (0, import_react.useState)(null);
  const colorResolverElement = panelContainerEl ?? containerElement;
  const displayColor = (0, import_react.useMemo)(
    () => (0, import_resolve_color_to_display_hex.resolveColorToDisplayHex)(stop.color, colorResolverElement),
    [stop.color, colorResolverElement]
  );
  const previewColor = (0, import_react.useMemo)(
    () => (0, import_resolve_color_to_display_hex.resolveColorToDisplayHex)(stop.color, colorResolverElement, { preserveAlpha: true }),
    [stop.color, colorResolverElement]
  );
  const stopOpacity = (0, import_wix_rich_content_common.getOpacityFromHex)(stop.color);
  return /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { key: originalIndex, direction: "horizontal", gap: "SP2", ref: setContainerElement }, /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { width: "100%", marginRight: "SP2" }, /* @__PURE__ */ import_react.default.createElement(
    import_design_system.Slider,
    {
      displayMarks: false,
      gradientColor: displayColor,
      min: 0,
      max: 100,
      value: stopOpacity,
      onChange: (newOpacity) => {
        const opacityValue = Array.isArray(newOpacity) ? newOpacity[0] : newOpacity;
        onChange({
          ...value,
          stops: value.stops?.map(
            (s, i) => i === originalIndex ? {
              ...s,
              color: (0, import_wix_rich_content_common.combineHexWithOpacity)((0, import_wix_rich_content_common.getHexColorFromAlpha)(s.color), opacityValue)
            } : s
          )
        });
      }
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { flexShrink: "0", width: "70px" }, /* @__PURE__ */ import_react.default.createElement(
    import_design_system.NumberInput,
    {
      value: stopOpacity,
      suffix: /* @__PURE__ */ import_react.default.createElement(import_design_system.Input.Affix, null, "%"),
      size: "small",
      min: 0,
      max: 100,
      hideStepper: true,
      onChange: (newOpacity) => {
        const opacityValue = Math.max(0, Math.min(100, Number(newOpacity)));
        onChange({
          ...value,
          stops: value.stops?.map(
            (s, i) => i === originalIndex ? {
              ...s,
              color: (0, import_wix_rich_content_common.combineHexWithOpacity)((0, import_wix_rich_content_common.getHexColorFromAlpha)(s.color), opacityValue)
            } : s
          )
        });
      }
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { flexShrink: "0" }, /* @__PURE__ */ import_react.default.createElement(
    import_design_system.FillPreview,
    {
      dataHook: `gradient-fill-preview-${originalIndex}`,
      size: "small",
      onClick: () => {
        onColorPickerOpen?.({
          originalIndex,
          stop,
          referenceElement: containerElement
        });
      },
      fill: previewColor
    }
  )), /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { flexShrink: "0" }, /* @__PURE__ */ import_react.default.createElement(
    import_design_system.IconButton,
    {
      ariaLabel: t("GradientPicker_RemoveStop_Tooltip"),
      disabled: value.stops?.length === 1,
      priority: "secondary",
      size: "small",
      onClick: () => {
        onChange({
          ...value,
          stops: value.stops?.filter((_, i) => i !== originalIndex)
        });
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.DeleteSmall, null)
  )));
};
//# sourceMappingURL=gradient-stop-editor.js.map
