import { Box, FieldSet, FormField } from "@wix/design-system";
import React, { useContext } from "react";
import { ZIndexContext } from "./../../ricos-context/index.js";
import { InputWithSlider } from "./../input-with-slider/input-with-slider.js";
const NumberInputWithLabel = ({
  label,
  infoContent,
  dataHook,
  suffix,
  onChange,
  onChangeCommit,
  commitUnchanged,
  min,
  max,
  value,
  logBi,
  zIndex,
  ...props
}) => {
  const zIndexService = useContext(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 = React.useMemo(() => {
    return max > 999 ? "auto 78px" : "auto 72px";
  }, [max]);
  return /* @__PURE__ */ React.createElement(Box, { direction: "vertical" }, /* @__PURE__ */ React.createElement(FormField, { inputWidth: "100%" }, /* @__PURE__ */ React.createElement(
    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__ */ React.createElement("div", null),
    /* @__PURE__ */ React.createElement(
      InputWithSlider,
      {
        value,
        onChange: handleInput,
        onChangeCommit: handleInputCommit,
        commitUnchanged,
        zIndex,
        suffix,
        min,
        max,
        dataHook
      }
    )
  )));
};
export {
  NumberInputWithLabel
};
//# sourceMappingURL=number-input-with-label.js.map
