"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Slider", {
    enumerable: true,
    get: function() {
        return Slider;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _reactslider = /*#__PURE__*/ _interop_require_wildcard(require("@radix-ui/react-slider"));
const _css = require("../utils/css");
const _marks = require("./marks");
const _sliderTip = require("./sliderTip");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const Slider = /*#__PURE__*/ _react.default.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 = (0, _react.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 = (0, _react.useMemo)(()=>{
        return (0, _css.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__*/ (0, _jsxruntime.jsx)("div", {
        className: (0, _css.cn)("orderly-relative"),
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_reactslider.Root, {
            ref: ref,
            className: (0, _css.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__*/ (0, _jsxruntime.jsx)(_reactslider.Track, {
                    className: "orderly-bg-base-200 orderly-relative orderly-grow orderly-rounded-full orderly-h-[2px] orderly-z-0",
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactslider.Range, {
                        className: (0, _css.cn)("orderly-absolute orderly-bg-base-200 orderly-rounded-full orderly-h-full", bgClassName)
                    })
                }),
                Array.isArray(innerMasks) && innerMasks.length > 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_marks.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__*/ (0, _jsxruntime.jsx)(_reactslider.Thumb, {
                    className: (0, _css.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__*/ (0, _jsxruntime.jsx)(_sliderTip.SliderTip, {
                        value: props.value,
                        className: bgClassName,
                        max: max,
                        min: 0
                    })
                })
            ]
        })
    });
});
Slider.displayName = _reactslider.Root.displayName;

//# sourceMappingURL=slider.js.map