import { jsxs, jsx } from "react/jsx-runtime";
/* empty css                   */
import FormControl from "../../node_modules/@mui/material/FormControl/FormControl.js";
import OutlinedInput from "../../node_modules/@mui/material/OutlinedInput/OutlinedInput.js";
import Slider$1 from "../../node_modules/@mui/material/Slider/Slider.js";
function isRangedValue(value) {
  return Array.isArray(value) && value.length === 2;
}
function Slider({
  headerOrientation = "top",
  header,
  label,
  value = 0,
  onChange,
  required,
  disabled,
  min = 0,
  max = 100,
  variant = "default",
  inputPosition = "inline",
  className,
  "data-testid": dataTestId,
  ...sliderProps
}) {
  const isRanged = variant === "ranged" && isRangedValue(value);
  const primaryValue = isRangedValue(value) ? value[0] : value;
  const secondaryValue = isRangedValue(value) ? value[1] : value;
  const handleInputChange = (e, key) => {
    const inputVal = e.target.value;
    if (inputVal === "" || Number.isNaN(Number(inputVal))) return;
    const num = Number(inputVal);
    if (key === "min") {
      if (num < min || isRanged && num > secondaryValue) return;
      onChange == null ? void 0 : onChange(e, isRanged ? [num, secondaryValue] : num, 0);
    } else if (key === "max") {
      if (num > max || isRanged && num < primaryValue) return;
      onChange == null ? void 0 : onChange(e, isRanged ? [primaryValue, num] : num, 1);
    } else {
      onChange == null ? void 0 : onChange(e, num);
    }
  };
  const layoutClass = [
    "impact_slider_layout",
    "slider-container",
    headerOrientation === "top" ? "header-top" : "header-left",
    `input-position-${inputPosition}`,
    className ?? ""
  ].filter(Boolean).join(" ");
  return /* @__PURE__ */ jsxs("div", { className: layoutClass, "data-testid": dataTestId, children: [
    isRanged && inputPosition === "inline" && /* @__PURE__ */ jsx("div", { className: "input_layout_style ranged ranged-start", children: /* @__PURE__ */ jsx("form", { noValidate: true, autoComplete: "off", children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
      OutlinedInput,
      {
        disabled,
        inputProps: { "aria-label": "Minimum value", "data-testid": "slider-input-min" },
        value: isRanged ? primaryValue : value,
        onChange: (e) => {
          handleInputChange(e, isRanged ? "min" : "");
        }
      }
    ) }) }) }),
    /* @__PURE__ */ jsxs("div", { className: "impact_slider_container", children: [
      header != null && /* @__PURE__ */ jsx("div", { className: "impact_slider_layout_heading", children: header }),
      label != null && /* @__PURE__ */ jsxs("label", { className: "impact_slider_labelname", children: [
        label,
        " ",
        required && /* @__PURE__ */ jsx("span", { style: { color: "red" }, children: "*" })
      ] }),
      /* @__PURE__ */ jsx("div", { className: `impact_slider_main_container ${disabled ? "impact_slider_disabled" : ""}`, children: /* @__PURE__ */ jsx(
        Slider$1,
        {
          ...sliderProps,
          disabled,
          max,
          min,
          value,
          onChange: (_, val, activeThumb) => onChange == null ? void 0 : onChange(_, val, activeThumb),
          ...isRanged ? { getAriaLabel: (i) => i === 0 ? "Minimum" : "Maximum" } : { "aria-label": "Slider" },
          valueLabelDisplay: "auto"
        }
      ) })
    ] }),
    /* @__PURE__ */ jsx("div", { className: `input_layout_style ${isRanged ? "ranged" : "single"}`, children: /* @__PURE__ */ jsx("form", { noValidate: true, autoComplete: "off", children: /* @__PURE__ */ jsxs(FormControl, { children: [
      (!isRanged || inputPosition === "bottom") && /* @__PURE__ */ jsx(
        OutlinedInput,
        {
          disabled,
          inputProps: {
            "aria-label": isRanged ? "Minimum value" : "Value",
            "data-testid": "slider-input-value"
          },
          value: isRanged ? primaryValue : value,
          onChange: (e) => {
            handleInputChange(e, isRanged ? "min" : "");
          }
        }
      ),
      isRanged && /* @__PURE__ */ jsx(
        OutlinedInput,
        {
          disabled,
          inputProps: { "aria-label": "Maximum value", "data-testid": "slider-input-max" },
          value: secondaryValue,
          onChange: (e) => {
            handleInputChange(e, "max");
          }
        }
      )
    ] }) }) })
  ] });
}
Slider.displayName = "Slider";
export {
  Slider
};
