"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return TimeInterval;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _css = require("../../../../../../utils/css");
const _expland = require("../../../../../../icon/icons/expland");
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 timeIntervalMap = [
    [
        {
            value: "3",
            label: "3m"
        },
        {
            value: "5",
            label: "5m"
        },
        {
            value: "30",
            label: "30m"
        },
        {
            value: "120",
            label: "2h"
        }
    ],
    [
        {
            value: "360",
            label: "6h"
        },
        {
            value: "720",
            label: "12h"
        },
        {
            value: "3d",
            label: "3D"
        },
        {
            value: "1M",
            label: "1M"
        }
    ]
];
function TimeInterval({ changeTimeInterval, timeInterval }) {
    const [open, setOpen] = (0, _react.useState)(false);
    const containerRef = _react.default.useRef(null);
    (0, _react.useEffect)(()=>{
        const onTouchStart = (event)=>{
            if (containerRef.current === event.target || containerRef.current?.contains(event.target)) {
                return;
            }
            setOpen(false);
        //   document.removeEventListener("click", onClick);
        };
        const onClick = (event)=>{
            if (containerRef.current === event.target || containerRef.current?.contains(event.target)) {
                return;
            }
            //   event.stopPropagation();
            setOpen(false);
        };
        if (open) {
            //   const onTouchMove = () => {};
            setTimeout(()=>{
                document.addEventListener("touchstart", onTouchStart, {
                    capture: true
                });
                document.addEventListener("click", onClick, {
                    capture: true
                });
            }, 100);
            return ()=>{
                //
                document.removeEventListener("touchstart", onTouchStart);
                document.removeEventListener("click", onClick);
            };
        } else {
            document.removeEventListener("touchstart", onTouchStart);
            document.removeEventListener("click", onClick);
        }
    }, [
        open
    ]);
    const currentIntervalIsInExpand = (0, _react.useMemo)(()=>{
        for (const row of timeIntervalMap){
            for (const item of row){
                if (item.value === timeInterval) {
                    return item.label;
                }
            }
        }
        return null;
    }, [
        timeInterval
    ]);
    (0, _react.useEffect)(()=>{}, [
        timeInterval
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        ref: containerRef,
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("button", {
                className: (0, _css.cn)("orderly-flex orderly-items-center ", (open || currentIntervalIsInExpand) && "orderly-text-base-contrast"),
                onClick: ()=>setOpen((open)=>!open),
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                        children: currentIntervalIsInExpand ?? "More"
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)(_expland.ExpandIcon, {
                        size: 16,
                        className: (0, _css.cn)("orderly-transition-transform", open && "orderly-rotate-180")
                    })
                ]
            }),
            open && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                "data-state": open ? "open" : "closed",
                className: (0, _css.cn)("orderly-z-50 orderly-min-w-[8rem] orderly-overflow-hidden orderly-rounded orderly-bg-base-800 orderly-px-4 orderly-py-3 orderly-text-popover-foreground orderly-shadow-md orderly-absolute orderly-left-0 orderly-top-full orderly-w-full orderly-space-y-1", "data-[state=open]:orderly-animate-in data-[state=closed]:orderly-animate-out data-[state=closed]:orderly-fade-out-0 data-[state=open]:orderly-fade-in-0 data-[state=closed]:orderly-zoom-out-95 data-[state=open]:orderly-zoom-in-95 data-[side=bottom]:orderly-slide-in-from-top-2 data-[side=left]:orderly-slide-in-from-right-2 data-[side=right]:orderly-slide-in-from-left-2 data-[side=top]:orderly-slide-in-from-bottom-2"),
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                    className: "orderly-flex orderly-flex-col orderly-gap-3",
                    children: timeIntervalMap.map((row, id)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                            className: "orderly-flex orderly-flex-row orderly-gap-3",
                            children: row.map((item)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                    className: (0, _css.cn)("orderly-text-3xs orderly-relative orderly-flex orderly-items-center orderly-justify-center orderly-w-[50%] orderly-bg-base-600 orderly-h-8 orderly-text-base-contrast-36 orderly-rounded-md", item.value === timeInterval && "orderly-text-base-contrast orderly-border orderly-border-base-contrast"),
                                    onClick: ()=>{
                                        changeTimeInterval(item.value);
                                    },
                                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                                        children: item.label
                                    })
                                }, item.value))
                        }, id))
                })
            })
        ]
    });
}

//# sourceMappingURL=timeInterval.js.map