import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { KChartIcon } from "../../../../../../icon/icons/kchart";
import React, { useEffect, useState } from "react";
import { cn } from "../../../../../../utils/css";
import { CheckSmallIcon } from "../../../../../../icon/icons/checkSmall";
import { ExpandIcon } from "../../../../../../icon/icons/expland";
const DisplayControlMap = [
    [
        {
            label: "Position",
            id: "position"
        },
        {
            label: "Limit Orders",
            id: "limitOrders"
        }
    ],
    [
        {
            label: "Stop orders",
            id: "stopOrders"
        },
        {
            label: "TP/SL",
            id: "tpsl"
        }
    ],
    [
        {
            label: "Position TP/SL",
            id: "positionTpsl"
        },
        {
            label: "Buy/Sell",
            id: "buySell"
        }
    ]
];
export default function DisplayControl({ displayControlState, changeDisplayControlState }) {
    const [open, setOpen] = useState(false);
    const containerRef = React.useRef(null);
    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
    ]);
    return /*#__PURE__*/ _jsxs("div", {
        ref: containerRef,
        children: [
            /*#__PURE__*/ _jsx("div", {
                className: cn("orderly-flex orderly-items-center orderly-justify-center orderly-w-[44px] orderly-h-[36px] orderly-rounded orderly-text-base-contrast-54", open && "orderly-text-base-contrast"),
                children: /*#__PURE__*/ _jsxs("button", {
                    className: "orderly-flex orderly-items-center ",
                    onClick: ()=>setOpen((open)=>!open),
                    children: [
                        /*#__PURE__*/ _jsx(KChartIcon, {
                            size: 20,
                            fill: "currentColor"
                        }),
                        /*#__PURE__*/ _jsx(ExpandIcon, {
                            size: 16,
                            className: cn("orderly-transition-transform", open && "orderly-rotate-180")
                        })
                    ]
                })
            }),
            open && /*#__PURE__*/ _jsxs("div", {
                "data-state": open ? "open" : "closed",
                className: 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__*/ _jsx("div", {
                        className: "orderly-text-base-contrast-54 orderly-text-3xs orderly-pb-3",
                        children: "Display settings"
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: "orderly-flex orderly-flex-col orderly-gap-3",
                        children: DisplayControlMap.map((row, index)=>/*#__PURE__*/ _jsx("div", {
                                className: "orderly-flex orderly-flex-row orderly-gap-3",
                                children: row.map((item)=>item.id !== "buySell" ? /*#__PURE__*/ _jsxs("div", {
                                        className: 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", displayControlState[item.id] && "orderly-text-base-contrast orderly-border orderly-border-base-contrast"),
                                        onClick: ()=>{
                                            changeDisplayControlState({
                                                ...displayControlState,
                                                [item.id]: !displayControlState[item.id]
                                            });
                                        },
                                        children: [
                                            displayControlState[item.id] && /*#__PURE__*/ _jsx("div", {
                                                className: "orderly-absolute -orderly-top-[1px] -orderly-right-[1px]",
                                                children: /*#__PURE__*/ _jsx(CheckSmallIcon, {
                                                    size: 12
                                                })
                                            }),
                                            /*#__PURE__*/ _jsx("div", {
                                                children: item.label
                                            })
                                        ]
                                    }, item.id) : /*#__PURE__*/ _jsx("div", {
                                        className: "orderly-w-[50%]"
                                    }, item.id))
                            }, index))
                    })
                ]
            })
        ]
    });
}

//# sourceMappingURL=displayControl.js.map