import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useMemo } from "react";
import * as SliderPrimitive from "@radix-ui/react-slider";
import { cn } from "../utils/css";
import { SliderMarks } from "./marks";
import { SliderTip } from "./sliderTip";
const Slider = /*#__PURE__*/ React.forwardRef(({ className, marks, markCount, markLabelVisible, color = "primary", showTip = true, onValueChange, ...props }, ref)=>{
    const { min = 0, max = 100, step, value = 0 } = props;
    // const spanRef = useRef<HTMLSpanElement | null>(null);
    // const size = useSize(spanRef.current);
    const innerMasks = useMemo(()=>{
        let _max = max;
        if (_max === 0) {
            _max = 1;
        }
        if (Array.isArray(marks) && marks.length > 0) {
            return marks;
        }
        if (typeof markCount !== "undefined") {
            const marks = [];
            // if(max === 0){
            // }
            const piece = _max / markCount;
            const len = markCount - 1;
            for(let i = 0; i <= len; i++){
                const value = i * piece;
                marks.push({
                    value,
                    label: `${value}`
                });
            }
            marks.push({
                value: _max,
                label: `100`
            });
            return marks;
        }
    }, [
        marks,
        markCount,
        max
    ]);
    //
    const onValueChangeInner = (value)=>{
        onValueChange?.(value);
    };
    const bgClassName = useMemo(()=>{
        return cn({
            "orderly-bg-primary orderly-border-primary": color === "primary",
            "orderly-bg-primary-light orderly-border-primary-light": color === "primary-light",
            "orderly-bg-trade-profit orderly-border-trade-profit": color === "buy",
            "orderly-bg-trade-loss orderly-border-trade-loss": color === "sell"
        }, props.disabled && "orderly-bg-base-200", "orderly-text-base-600");
    }, [
        color,
        props.disabled
    ]);
    return /*#__PURE__*/ _jsx("div", {
        className: cn("orderly-relative"),
        children: /*#__PURE__*/ _jsxs(SliderPrimitive.Root, {
            ref: ref,
            className: cn("orderly-relative orderly-flex orderly-items-center orderly-select-none orderly-touch-none orderly-w-full orderly-h-[20px] orderly-cursor-pointer", className),
            onValueChange: onValueChangeInner,
            ...props,
            children: [
                /*#__PURE__*/ _jsx(SliderPrimitive.Track, {
                    className: "orderly-bg-base-200 orderly-relative orderly-grow orderly-rounded-full orderly-h-[2px] orderly-z-0",
                    children: /*#__PURE__*/ _jsx(SliderPrimitive.Range, {
                        className: cn("orderly-absolute orderly-bg-base-200 orderly-rounded-full orderly-h-full", bgClassName)
                    })
                }),
                Array.isArray(innerMasks) && innerMasks.length > 0 && /*#__PURE__*/ _jsx(SliderMarks, {
                    value: props.value,
                    color: color,
                    marks: innerMasks,
                    isInnerMask: !Array.isArray(marks) || marks.length === 0,
                    min: min,
                    max: max,
                    markLabelVisible: markLabelVisible,
                    disabled: props.disabled
                }),
                /*#__PURE__*/ _jsx(SliderPrimitive.Thumb, {
                    className: cn("orderly-block orderly-w-[10px] orderly-h-[10px] orderly-bg-base-700 orderly-border-[2px] orderly-border-base-200 orderly-rounded-[10px] focus:orderly-outline-none focus:orderly-w-[16px] focus:orderly-h-[16px] focus:orderly-shadow-[0_0_0_8px] focus:orderly-shadow-base-contrast/20 orderly-z-20 disabled:orderly-pointer-events-none orderly-group data-[disabled]:orderly-hidden", {
                        "orderly-border-primary": color === "primary",
                        "orderly-border-primary-light": color === "primary-light",
                        "orderly-border-trade-profit": color === "buy",
                        "orderly-border-trade-loss": color === "sell"
                    }, props.disabled && "orderly-border-transparent orderly-bg-base-200"),
                    "aria-label": "Volume",
                    children: showTip && /*#__PURE__*/ _jsx(SliderTip, {
                        value: props.value,
                        className: bgClassName,
                        max: max,
                        min: 0
                    })
                })
            ]
        })
    });
});
Slider.displayName = SliderPrimitive.Root.displayName;
export { Slider };

//# sourceMappingURL=slider.js.map