import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useEffect, useState } from "react";
import { Checkbox } from "../../../../../checkbox";
import { Label } from "../../../../../label";
import { useSessionStorage } from "@orderly.network/hooks";
import { useTabContext } from "../../../../../tab/tabContext";
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
import { Divider } from "../../../../../divider";
import { DecimalPrecisionCheckbox, DecimalPrecisionType } from "./decimalPrecisionCheckBox";
import { UnPnlPriceBasisCheckBox, UnPnlPriceBasisType } from "./unPnlPriceBasisCheckBox";
import { SettingsIcon } from "../../../../../icon";
export const TabBarExtraNode = (props)=>{
    const [showAllSymbol, setShowAllSymbol] = useSessionStorage("showAllSymbol_position", true);
    const { updateData } = useTabContext();
    // const [symbol, setSymbol] = useState(() =>
    //   showAllSymbol ? "" : context.symbol
    // );
    const onShowAllSymbolChange = (isAll)=>{
        // setSymbol(isAll ? "" : context.symbol);
        setShowAllSymbol(isAll);
        updateData("showAllSymbol", isAll);
    };
    useEffect(()=>updateData("showAllSymbol", showAllSymbol), []);
    // const onChecked = (checked: boolean) => {
    //   console.log(checked);
    // };
    return /*#__PURE__*/ _jsxs("div", {
        className: "orderly-flex orderly-items-center orderly-gap-2",
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: "orderly-flex orderly-items-center orderly-gap-2",
                children: [
                    /*#__PURE__*/ _jsx(Checkbox, {
                        id: "showAll",
                        checked: showAllSymbol,
                        onCheckedChange: onShowAllSymbolChange
                    }),
                    /*#__PURE__*/ _jsx(Label, {
                        htmlFor: "showAll",
                        className: "orderly-text-base-contrast-54 orderly-text-3xs",
                        children: "Show all instruments"
                    })
                ]
            }),
            /*#__PURE__*/ _jsx(SettingIcon, {
                ...props
            })
        ]
    });
};
const SettingIcon = (props)=>{
    const [open, setOpen] = useState(false);
    const { updateData } = useTabContext();
    const onDecimalPrecisionChanged = useCallback((type)=>{
        var value = 0;
        switch(type){
            case DecimalPrecisionType.ZERO:
                value = 0;
                break;
            case DecimalPrecisionType.ONE:
                value = 1;
                break;
            case DecimalPrecisionType.TWO:
                value = 2;
                break;
        }
        updateData("pnlNotionalDecimalPrecision", value);
        props.setDecimalPrecision(type);
    }, [
        props.decimalPrecision
    ]);
    const onUnPnlPriceBasisChanged = useCallback((type)=>{
        var value = 0;
        switch(type){
            case UnPnlPriceBasisType.MARKET_PRICE:
                value = 0;
                break;
            case UnPnlPriceBasisType.LAST_PRICE:
                value = 1;
                break;
        }
        updateData("unPnlPriceBasis", value);
        props.setUnPnlPriceBasic(type);
    }, [
        props.unPnlPriceBasis
    ]);
    return /*#__PURE__*/ _jsxs(DropdownMenu, {
        open: open,
        onOpenChange: setOpen,
        children: [
            /*#__PURE__*/ _jsx(DropdownMenuTrigger, {
                children: /*#__PURE__*/ _jsx("button", {
                    className: "orderly-pb-[1px] orderly-h-[48px] orderly-text-base-contrast-80 orderly-cursor-pointer orderly-fill-base-contrast-54 hover:orderly-fill-base-contrast",
                    children: /*#__PURE__*/ _jsx(SettingsIcon, {
                        fill: "currnet",
                        fillOpacity: 1
                    })
                })
            }),
            /*#__PURE__*/ _jsx(DropdownMenuContent, {
                align: "end",
                className: "orderly-bg-base-800 orderly-rounded orderly-rounded-borderRadius orderly-w-[280px] orderly-p-4 orderly-rounded-borderRadius orderly-shadow-[0px_12px_20px_0px_rgba(0,0,0,0.25)] orderly-z-40",
                onCloseAutoFocus: (e)=>e.preventDefault(),
                children: /*#__PURE__*/ _jsxs("div", {
                    className: "orderly-flex orderly-flex-col orderly-text-3xs",
                    children: [
                        /*#__PURE__*/ _jsx("span", {
                            className: "orderly-text-xs orderly-pb-3",
                            children: "Portfolio Settings"
                        }),
                        /*#__PURE__*/ _jsx(Divider, {}),
                        /*#__PURE__*/ _jsx("span", {
                            className: "orderly-pb-3 orderly-text-base-contrast-54 orderly-mt-2",
                            children: "Decimal Precision for PnL & Notional"
                        }),
                        /*#__PURE__*/ _jsx(DecimalPrecisionCheckbox, {
                            value: props.decimalPrecision,
                            onValueChange: onDecimalPrecisionChanged
                        }),
                        /*#__PURE__*/ _jsx(Divider, {
                            className: "orderly-my-3"
                        }),
                        /*#__PURE__*/ _jsx("span", {
                            className: "orderly-pb-3 orderly-text-base-contrast-54 orderly-mt-2",
                            children: "Unrealized PnL Price Basis"
                        }),
                        /*#__PURE__*/ _jsx(UnPnlPriceBasisCheckBox, {
                            value: props.unPnlPriceBasis,
                            onValueChange: onUnPnlPriceBasisChanged
                        })
                    ]
                })
            })
        ]
    });
};

//# sourceMappingURL=tabbarExtraNode.js.map