"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 number_input_with_label_exports = {};
__export(number_input_with_label_exports, {
  NumberInputWithLabel: () => NumberInputWithLabel
});
module.exports = __toCommonJS(number_input_with_label_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_input_with_slider = require("./../input-with-slider/input-with-slider.js");
const NumberInputWithLabel = ({
  label,
  infoContent,
  dataHook,
  suffix,
  onChange,
  onChangeCommit,
  commitUnchanged,
  min,
  max,
  value,
  logBi,
  zIndex,
  ...props
}) => {
  const zIndexService = (0, import_react.useContext)(import_ricos_context.ZIndexContext);
  const handleInput = (numberValue) => {
    const valueWithinBounds = isNaN(numberValue) || numberValue < min ? min : numberValue > max ? max : numberValue;
    logBi?.({ dataHook, value: valueWithinBounds });
    return onChange(valueWithinBounds);
  };
  const handleInputCommit = (finalValue, originalValue) => {
    const finalWithinBounds = isNaN(finalValue) || finalValue < min ? min : finalValue > max ? max : finalValue;
    const originalWithinBounds = isNaN(originalValue) || originalValue < min ? min : originalValue > max ? max : originalValue;
    onChangeCommit?.(finalWithinBounds, originalWithinBounds);
  };
  const columnWidth = import_react.default.useMemo(() => {
    return max > 999 ? "auto 78px" : "auto 72px";
  }, [max]);
  return /* @__PURE__ */ import_react.default.createElement(import_design_system.Box, { direction: "vertical" }, /* @__PURE__ */ import_react.default.createElement(import_design_system.FormField, { inputWidth: "100%" }, /* @__PURE__ */ import_react.default.createElement(
    import_design_system.FieldSet,
    {
      columns: columnWidth,
      alignment: "center",
      legendPlacement: "left",
      legend: label,
      infoContent: typeof infoContent === "string" ? infoContent : void 0,
      infoTooltipProps: {
        appendTo: "tooltipAppendTo" in props ? props.tooltipAppendTo : (el) => Boolean(el.getAttribute("data-hook")?.includes("ricos-portal")),
        zIndex: zIndexService.getZIndex("TOOLTIP")
      },
      ellipsis: true
    },
    /* @__PURE__ */ import_react.default.createElement("div", null),
    /* @__PURE__ */ import_react.default.createElement(
      import_input_with_slider.InputWithSlider,
      {
        value,
        onChange: handleInput,
        onChangeCommit: handleInputCommit,
        commitUnchanged,
        zIndex,
        suffix,
        min,
        max,
        dataHook
      }
    )
  )));
};
//# sourceMappingURL=number-input-with-label.js.map
