"use strict";
"use client";
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);

// src/components/Slider/Slider.tsx
var Slider_exports = {};
__export(Slider_exports, {
  Slider: () => Slider
});
module.exports = __toCommonJS(Slider_exports);
var import_dedupe2 = __toESM(require("classnames/dedupe"));
var import_react3 = require("react");

// src/hooks/useLabel/useLabel.tsx
var import_react = require("react");
function useLabel({
  id: providedId,
  label,
  "aria-label": ariaLabel,
  "aria-labelledby": ariaLabelledby,
  labelElementType = "label"
}) {
  let labelProps = {};
  let fieldProps = {};
  const hasWarnedAboutMissingLabels = (0, import_react.useRef)(false);
  const fallbackId = (0, import_react.useId)();
  const id = providedId || fallbackId;
  const labelId = (0, import_react.useId)();
  if (label) {
    ariaLabelledby = ariaLabelledby ? `${labelId} ${ariaLabelledby}` : labelId;
    labelProps = {
      id: labelId,
      htmlFor: labelElementType === "label" ? id : void 0
    };
  } else if (!ariaLabelledby && !ariaLabel && !hasWarnedAboutMissingLabels.current) {
    hasWarnedAboutMissingLabels.current = true;
    console.warn(
      "If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility"
    );
  }
  fieldProps = {
    id,
    "aria-label": ariaLabel,
    "aria-labelledby": ariaLabelledby
  };
  return {
    labelProps,
    fieldProps
  };
}

// src/components/Label/Label.tsx
var import_dedupe = __toESM(require("classnames/dedupe"));
var import_Label = require("@simplybusiness/mobius/src/components/Label/Label.css");
var import_jsx_runtime = require("react/jsx-runtime");
var Label = ({ ref, ...props }) => {
  const { elementType: Element = "label", children, ...otherProps } = props;
  const classes = (0, import_dedupe.default)("mobius", "mobius-label", props.className);
  otherProps.className = classes;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Element, { ref, ...otherProps, className: classes, children });
};
Label.displayName = "Label";

// src/components/Slider/helpers.ts
var import_react2 = require("react");
function numberFormatter(value, formatOptions, locale = navigator.languages?.[0] || "en-GB") {
  if (!formatOptions) {
    return value?.toString() || "";
  }
  return new Intl.NumberFormat(locale, formatOptions).format(+(value || 0));
}

// src/components/Slider/Slider.tsx
var import_Slider = require("@simplybusiness/mobius/src/components/Slider/Slider.css");
var import_jsx_runtime2 = require("react/jsx-runtime");
var Slider = (props) => {
  const {
    id,
    className,
    label,
    "aria-label": ariaLabel,
    "aria-labelledby": ariaLabelledBy,
    minValue,
    maxValue,
    step = 1,
    defaultValue = 0,
    value,
    onChange,
    onChangeEnd,
    variant = "primary",
    minLabel,
    maxLabel,
    formatOptions,
    isDisabled = false
  } = props;
  const trackRef = (0, import_react3.useRef)(null);
  const [currentValue, setCurrentValue] = (0, import_react3.useState)(
    value || defaultValue || 0
  );
  const [isDragging, setIsDraggging] = (0, import_react3.useState)(false);
  const { labelProps, fieldProps } = useLabel({
    id,
    label,
    "aria-label": ariaLabel,
    "aria-labelledby": ariaLabelledBy
  });
  const formattedValue = numberFormatter(currentValue, formatOptions);
  const classes = (0, import_dedupe2.default)("mobius", "mobius-slider", className, {
    "--is-disabled": isDisabled,
    "--is-primary": variant === "primary",
    "--is-secondary": variant === "secondary",
    "--is-dragging": isDragging
  });
  const handleChange = (e) => {
    const val = +e.target.value;
    setCurrentValue(val);
    if (onChange) {
      onChange(val);
    }
  };
  const handleChangeStart = () => {
    setIsDraggging(true);
  };
  const handleChangeEnd = () => {
    setIsDraggging(false);
    if (onChangeEnd) {
      onChangeEnd(currentValue);
    }
  };
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: classes, children: [
    /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mobius-slider__label-wrapper", children: [
      label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { ...labelProps, children: label }),
      label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("output", { style: { flex: "1 0 auto", textAlign: "end" }, children: formattedValue })
    ] }),
    /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: trackRef, className: "mobius-slider__track-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
      "input",
      {
        className: "mobius-slider__track",
        type: "range",
        min: minValue,
        max: maxValue,
        value: currentValue,
        step,
        onChange: handleChange,
        autoComplete: "off",
        disabled: isDisabled,
        onMouseDown: handleChangeStart,
        onMouseUp: handleChangeEnd,
        onKeyDown: handleChangeStart,
        onKeyUp: handleChangeEnd,
        ...fieldProps
      }
    ) }),
    /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mobius-slider__labels", children: [
      /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mobius-slider__min-label", "data-testid": "min-label", children: minLabel }),
      /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mobius-slider__max-label", "data-testid": "max-label", children: maxLabel })
    ] })
  ] });
};
//# sourceMappingURL=Slider.js.map
