import { j as jsxRuntimeExports } from '../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js';
import * as React from 'react';
import { Root, Track, Range, Thumb } from '../../node_modules/.pnpm/@radix-ui_react-slider@1.2.2_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-slider/dist/index.js';
import { cva } from '../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js';
import { ThumbIcon } from './thumb.js';
import styles from './slider.module.css.js';

const slider = cva(styles.slider, {
    variants: {
        variant: {
            single: styles['slider-variant-single'],
            range: styles['slider-variant-range'],
        },
    },
    defaultVariants: {
        variant: 'single',
    },
});
const Slider = React.forwardRef(({ className, variant = 'single', value, defaultValue, min = 0, max = 100, step = 1, label, onChange, 'aria-label': ariaLabel, 'aria-valuetext': ariaValueText, ...props }, ref) => {
    const isRange = variant === 'range';
    const defaultVal = isRange
        ? defaultValue || [min, max]
        : [defaultValue || min];
    const currentValue = value ? (isRange ? value : [value]) : defaultVal;
    const getLabel = (index) => {
        if (!label)
            return undefined;
        if (typeof label === 'string')
            return label;
        return label[index];
    };
    const getAriaValueText = (index) => {
        if (ariaValueText)
            return ariaValueText;
        const labelText = getLabel(index);
        const val = currentValue[index];
        return labelText ? `${labelText}: ${val}` : `${val}`;
    };
    return (jsxRuntimeExports.jsxs(Root, { ref: ref, className: `${slider({ variant })} ${className || ''}`, value: value ? currentValue : undefined, defaultValue: defaultVal, min: min, max: max, step: step, onValueChange: (val) => onChange?.(isRange ? val : val[0]), "aria-label": ariaLabel || (isRange ? 'Range slider' : 'Slider'), ...props, children: [jsxRuntimeExports.jsx(Track, { className: styles.track, children: jsxRuntimeExports.jsx(Range, { className: styles.range }) }), defaultVal.map((_, i) => (jsxRuntimeExports.jsx(Thumb, { className: styles.thumb, asChild: true, "aria-label": getLabel(i) || `Thumb ${i + 1}`, "aria-valuetext": getAriaValueText(i), children: jsxRuntimeExports.jsxs("div", { children: [jsxRuntimeExports.jsx(ThumbIcon, {}), getLabel(i) && jsxRuntimeExports.jsx("div", { className: styles.label, children: getLabel(i) })] }) }, i)))] }));
});
Slider.displayName = 'Slider';

export { Slider };
//# sourceMappingURL=slider.js.map
