import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useRef } from 'react';
import { TemperatureAddIcon } from '../../../lib/icons/TemperatureAdd.js';
import { TemperatureSubtractIcon } from '../../../lib/icons/TemperatureSubtract.js';
export function TemperatureControl({ variant, value, onChange, min = 50, max = 90, unit = 'fahrenheit', }) {
    const increment = () => {
        onChange(Math.min(value + 1, max));
    };
    const decrement = () => {
        onChange(Math.max(value - 1, min));
    };
    return (_jsxs("div", { className: 'seam-temperature-control', children: [_jsx("button", { className: 'seam-temperature-stepper-button', onClick: decrement, children: _jsx(TemperatureSubtractIcon, {}) }), _jsx(RangeSlider, { variant: variant, min: min, max: max, value: value, onChange: (temperature) => {
                    onChange(temperature);
                }, unit: unit }), _jsx("button", { className: 'seam-temperature-stepper-button', onClick: increment, children: _jsx(TemperatureAddIcon, {}) })] }));
}
function RangeSlider({ variant, value, onChange, min, max, unit, }) {
    const wrapRef = useRef(null);
    useEffect(() => {
        if (wrapRef.current == null)
            return;
        const wrap = wrapRef.current;
        wrap.style.setProperty('--temperature-current', value.toString());
        wrap.style.setProperty('--temperature-min', min.toString());
        wrap.style.setProperty('--temperature-max', max.toString());
    }, [value, min, max]);
    const handleRangeChange = (event) => {
        onChange(Number(event.target.value));
    };
    return (_jsxs("div", { ref: wrapRef, className: 'seam-temperature-range-wrap', children: [_jsx("input", { type: 'range', min: min, max: max, value: value, onChange: handleRangeChange, className: 'seam-temperature-range', "data-variant": variant }), _jsxs("div", { className: 'seam-floating-temperature', children: [_jsx("span", { className: 'seam-floating-temperature-value', children: value }), _jsx("span", { className: 'seam-floating-temperature-unit', children: unit === 'fahrenheit' ? t.degreeFahrenheit : t.degreeCelsius })] })] }));
}
const t = {
    degreeFahrenheit: 'ºF',
    degreeCelsius: 'ºC',
};
//# sourceMappingURL=TemperatureControl.js.map