"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "OrderOptions", {
    enumerable: true,
    get: function() {
        return OrderOptions;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _checkbox = require("../../../checkbox");
const _collapsible = require("../../../collapsible");
const _label = require("../../../label");
const _switch = require("../../../switch");
const _css = require("../../../utils/css");
const _types = require("@orderly.network/types");
const _lucidereact = require("lucide-react");
const _react = require("react");
const _orderTypes = require("./orderTypes");
const _hooks = require("@orderly.network/hooks");
const _hiddenLabel = require("./hiddenLabel");
const _reduceOnly = require("./reduceOnly");
const OrderOptions = (props)=>{
    const { reduceOnly, formattedOrder, onFieldChange } = props;
    const [optionsOpen, setOptionsOpen] = (0, _hooks.useLocalStorage)("order_entry_options_open", false);
    const [open, setOpen] = (0, _react.useState)(optionsOpen);
    // const { control, getValues, setValue } = useFormContext();
    const { order_type } = formattedOrder;
    const isTable = (0, _hooks.useMediaQuery)(_types.MEDIA_TABLET);
    // console.log("------", formattedOrder);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                className: "orderly-flex orderly-items-center orderly-py-[2px] orderly-justify-between orderly-text-base-contrast-54",
                children: [
                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        className: "orderly-flex orderly-gap-2 orderly-items-center",
                        children: [
                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_switch.Switch, {
                                id: "orderly-reduce-only-switch",
                                color: "primary",
                                checked: formattedOrder.reduce_only ?? reduceOnly,
                                onCheckedChange: (checked)=>{
                                    // onReduceOnlyChange?.(checked);
                                    onFieldChange("reduce_only", checked);
                                // field.onChange(checked);
                                }
                            }),
                            isTable ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_reduceOnly.MobileReduceOnlyLabel, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_reduceOnly.DesktopReduceOnlyLabel, {
                                reduceOnly: formattedOrder.reduce_only ?? reduceOnly,
                                onFieldChange: onFieldChange
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
                        id: "orderly-order-entry-expand-icon",
                        type: "button",
                        className: "orderly-w-[18px] orderly-h-[18px] orderly-px-5 orderly-text-base-contrast/60",
                        onClick: ()=>{
                            setOpen((open)=>!open);
                            setOptionsOpen(!open);
                        },
                        children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_lucidereact.ChevronDown, {
                            size: 18,
                            className: (0, _css.cn)("orderly-transition-transform orderly-text-base-contrast/50", open && "orderly-rotate-180")
                        })
                    })
                ]
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_collapsible.Collapsible, {
                open: open,
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_collapsible.CollapsibleContent, {
                    children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                        id: "orderly-order-entry-expand-content",
                        className: "orderly-pb-2 orderly-space-y-4",
                        children: [
                            order_type === _types.OrderType.LIMIT && /*#__PURE__*/ (0, _jsxruntime.jsx)(_orderTypes.OrderTypesCheckbox, {
                                value: formattedOrder.order_type_ext,
                                onValueChange: (value)=>{
                                    // field.onChange(value);
                                    onFieldChange("order_type_ext", value);
                                }
                            }),
                            /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                className: "orderly-flex orderly-gap-5",
                                children: [
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                        id: "orderly-order-entry-expand-content-order-confirm",
                                        className: "orderly-flex orderly-gap-1 first-letter:orderly-items-center",
                                        children: [
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_checkbox.Checkbox, {
                                                id: "orderConfirm",
                                                checked: props.showConfirm,
                                                onCheckedChange: (checked)=>{
                                                    props.onConfirmChange?.(!!checked);
                                                }
                                            }),
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_label.Label, {
                                                htmlFor: "orderConfirm",
                                                className: "orderly-text-base-contrast-54",
                                                children: "Order confirm"
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                                        id: "orderly-order-entry-expand-content-hidden",
                                        className: "orderly-flex orderly-gap-1 orderly-items-center",
                                        children: [
                                            /*#__PURE__*/ (0, _jsxruntime.jsx)(_checkbox.Checkbox, {
                                                id: "hidden",
                                                checked: formattedOrder.visible_quantity === 0,
                                                onCheckedChange: (checked)=>{
                                                    // props.setValue?.("visible_quantity", checked ? 0 : 1);
                                                    // field.onChange(checked ? 0 : 1);
                                                    onFieldChange("visible_quantity", checked ? 0 : 1);
                                                }
                                            }),
                                            isTable ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_hiddenLabel.MobileHideenLabel, {}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_hiddenLabel.DesktopHiddenLabel, {})
                                        ]
                                    })
                                ]
                            })
                        ]
                    })
                })
            })
        ]
    });
};

//# sourceMappingURL=orderOptions.js.map