"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    Default: function() {
        return Default;
    },
    WithHook: function() {
        return WithHook;
    },
    default: function() {
        return _default;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _ = require(".");
const _hooks = require("@orderly.network/hooks");
const _types = require("@orderly.network/types");
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 meta = {
    title: "Block/OrderEntry",
    component: _.OrderEntry,
    argTypes: {
        onSubmit: {
            action: "submit"
        },
        onDeposit: {
            action: "deposit"
        }
    },
    args: {
        symbol: "PERP_NEAR_USDC",
        showConfirm: true,
        freeCollateral: 100,
        maxQty: 0,
        errors: {
        },
        symbolConfig: {
            symbol: "PERP_ETH_USDC",
            quote_min: 0,
            quote_max: 100000,
            quote_tick: 0.1,
            base_min: 0.0001,
            base_max: 260,
            base_tick: 0.0001,
            min_notional: 1,
            price_range: 0.03,
            price_scope: 0.4,
            std_liquidation_fee: 0.025,
            liquidator_fee: 0.0125,
            claim_insurance_fund_discount: 0.0075,
            funding_period: 8,
            cap_funding: 0.00375,
            floor_funding: -0.00375,
            interest_rate: 0.0001,
            created_time: 1692272828010,
            updated_time: 1692272828010,
            base_mmr: 0.0275,
            base_imr: 0.05,
            base: "ETH",
            quote: "USDC",
            type: "PERP"
        }
    }
};
const _default = meta;
const Default = {};
const WithHook = {
    render: (args, { globals })=>{
        const { symbol } = globals;
        const [side, setSide] = (0, _react.useState)(_types.OrderSide.BUY);
        const [order, setOrder] = (0, _react.useState)({
            reduce_only: false,
            side: _types.OrderSide.BUY,
            order_type: _types.OrderType.LIMIT,
            symbol: symbol
        });
        // const [reduceOnly, setReduceOnly] = useState(false);
        const formState = (0, _hooks.useOrderEntry)(order);
        ;
        // console.log(formState.errors);
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_.OrderEntry, {
            ...args,
            ...formState,
            symbol: symbol,
            // onSideChange={setSide}
            // reduceOnly={reduceOnly}
            onFieldChange: (field, value)=>{
                if (field === "side") {
                    setOrder((order)=>({
                            ...order,
                            [field]: value,
                            order_price: undefined,
                            order_quantity: undefined
                        }));
                } else {
                    setOrder((order)=>({
                            ...order,
                            [field]: value
                        }));
                }
            },
            setValues: (values)=>{
                setOrder((order)=>({
                        ...order,
                        ...values
                    }));
            }
        });
    }
};

//# sourceMappingURL=orderEntry._stories.js.map