import { _ as G } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { B as W } from "./BasicForm-dL_oCSPM.js";
import { q as $, r as j } from "./victualingDetail-CLhgLkA4.js";
import { g as z } from "./equipmentMainLibrary-bJTzj5mC.js";
import { eF as K, V as D, l as m, bk as L, d as Z, r as g, c as H, o as J, w as X, j as Y, cZ as ee, ac as ne, __tla as __tla_0 } from "./index-9PRMimni.js";
import { m as F, s as V } from "./subtract-Dj32RAiL.js";
import { u as te } from "./useForm-CKmgcynv.js";
import { u as oe } from "./useModal-CO65vga3.js";
let be;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    var ie = K.isFinite;
    function y(i) {
        return typeof i == "number" && ie(i);
    }
    function le({ id: i, provisionPortId: a, currency: u, data: n }) {
        return !i && !a ? {} : {
            id: i,
            provisionPortId: a,
            ...n,
            currency: u,
            price: n?.price ? +n.price : null,
            beginQuantity: n?.beginQuantity ? +n.beginQuantity : null,
            beginTotalAmount: n?.beginTotalAmount ? +n.beginTotalAmount : null,
            endQuantity: n?.endQuantity ? +n.endQuantity : null,
            endTotalAmount: n?.endTotalAmount ? +n.endTotalAmount : null,
            consumedQuantity: n?.consumedQuantity ? +n.consumedQuantity : null,
            consumedTotalAmount: n?.consumedTotalAmount ? +n.consumedTotalAmount : null
        };
    }
    function Q(i = 0, a = 0) {
        const u = i ? +i : 0, n = a ? +a : 0;
        return F(u, n) ?? 0;
    }
    function M(i = 0, a = 0) {
        const u = i ? +i : 0, n = a ? +a : 0;
        return V(u, n) ?? 0;
    }
    function b(i = 0, a = 0) {
        const u = i ? +i : 0, n = a ? +a : 0;
        return V(u, n) ?? 0;
    }
    function N(i = 0, a = 0) {
        const u = i ? +i : 0, n = a ? +a : 0;
        return F(u, n) ?? 0;
    }
    const se = L(), { t } = D(), ae = await z("currency");
    function A({ isLastMonthBalance: i, endQuantityRequired: a, hiddenMonthEndInfo: u, nameValidator: n }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "provisionPortId",
                hidden: !0
            },
            {
                field: "productName",
                component: "NInput",
                label: t("victualingDetail.provisionInventory.provisionItemModal.nameEn"),
                componentProps: {
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.nameEn"),
                    disabled: i
                },
                rules: n()
            },
            {
                field: "productNameCn",
                component: "NInput",
                label: t("victualingDetail.provisionInventory.provisionItemModal.name"),
                componentProps: {
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.name"),
                    disabled: i
                }
            },
            {
                field: "currency",
                component: "NSelect",
                label: t("victualingDetail.provisionInventory.provisionItemModal.currency"),
                componentProps: {
                    labelField: se.getLocale === "en" ? "labelEn" : "label",
                    disabled: !0,
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.currency"),
                    options: ae
                },
                rules: [
                    {
                        required: !0,
                        message: t("victualingDetail.provisionInventory.provisionItemModal.currencyRequired")
                    }
                ]
            },
            {
                field: "price",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.price"),
                componentProps: ({ model: e, formAction: o })=>({
                        placeholder: t("victualingDetail.provisionInventory.provisionItemModal.price"),
                        disabled: i?.value,
                        style: {
                            width: "100%"
                        },
                        precision: 2,
                        step: 1,
                        min: .01,
                        onUpdateValue: (l)=>{
                            if (e.endQuantity >= 0 && l >= 0) {
                                const s = Q(l, e.endQuantity);
                                o.setFieldsValue({
                                    endTotalAmount: s
                                });
                            } else o.setFieldsValue({
                                endTotalAmount: null
                            });
                            if (e.beginQuantity >= 0 && l >= 0) {
                                const s = N(l, e.beginQuantity), v = b(s, e.endTotalAmount);
                                o.setFieldsValue({
                                    beginTotalAmount: s,
                                    consumedTotalAmount: v
                                });
                            } else o.setFieldsValue({
                                beginTotalAmount: null
                            });
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        type: "number",
                        message: t("victualingDetail.provisionInventory.provisionItemModal.priceRequired")
                    }
                ]
            },
            {
                field: "unit",
                component: "NInput",
                label: t("victualingDetail.provisionInventory.provisionItemModal.unit"),
                componentProps: {
                    disabled: i,
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.unit")
                },
                rules: [
                    {
                        required: !0,
                        message: t("victualingDetail.provisionInventory.provisionItemModal.unitRequired")
                    }
                ]
            },
            {
                field: "beginQuantity",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.beginQuantity"),
                componentProps: ({ model: e, formAction: o })=>({
                        min: e?.endQuantity ?? 0,
                        step: 1,
                        precision: 0,
                        style: {
                            width: "100%"
                        },
                        disabled: i?.value,
                        placeholder: t("victualingDetail.provisionInventory.provisionItemModal.beginQuantity"),
                        onUpdateValue: (l)=>{
                            if (e.endQuantity >= 0 && l >= 0) {
                                const s = M(l, e.endQuantity);
                                o.setFieldsValue({
                                    consumedQuantity: s
                                });
                            } else o.setFieldsValue({
                                consumedQuantity: null
                            });
                            if (e.price >= 0 && l >= 0) {
                                const s = N(e.price, l);
                                o.setFieldsValue({
                                    beginTotalAmount: s
                                });
                            } else o.setFieldsValue({
                                beginTotalAmount: null
                            });
                            if (e.beginTotalAmount >= 0 && e.endTotalAmount >= 0) {
                                const s = b(e.beginTotalAmount, e.endTotalAmount);
                                o.setFieldsValue({
                                    consumedTotalAmount: s
                                });
                            }
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        type: "number",
                        message: t("victualingDetail.provisionInventory.provisionItemModal.beginQuantityRequired")
                    }
                ]
            },
            {
                field: "beginTotalAmount",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.subtotal"),
                componentProps: ({ model: e, formAction: o })=>({
                        min: .01,
                        step: 1,
                        precision: 2,
                        style: {
                            width: "100%"
                        },
                        disabled: !0,
                        placeholder: t("victualingDetail.provisionInventory.provisionItemModal.subtotal")
                    })
            },
            {
                field: "endQuantity",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.endQuantity"),
                componentProps: ({ model: e, formAction: o })=>({
                        min: 0,
                        max: e?.beginQuantity ?? void 0,
                        step: 1,
                        precision: 0,
                        style: {
                            width: "100%"
                        },
                        disabled: !1,
                        placeholder: t("victualingDetail.provisionInventory.provisionItemModal.endQuantity"),
                        onUpdateValue: (l)=>{
                            if (o.updateSchema({
                                field: "endTotalAmount",
                                hidden: !y(l)
                            }), o.updateSchema({
                                field: "consumedQuantity",
                                hidden: !y(l)
                            }), o.updateSchema({
                                field: "consumedTotalAmount",
                                hidden: !y(l)
                            }), e.price >= 0 && l >= 0) {
                                const s = Q(e.price, l);
                                o.setFieldsValue({
                                    endTotalAmount: s
                                });
                            } else o.setFieldsValue({
                                endTotalAmount: null
                            });
                            if (e.beginQuantity >= 0 && l >= 0) {
                                const s = M(e.beginQuantity, l);
                                o.setFieldsValue({
                                    consumedQuantity: s
                                });
                            } else o.setFieldsValue({
                                consumedQuantity: null
                            });
                            if (e.beginTotalAmount >= 0 && e.endTotalAmount >= 0) {
                                const s = b(e.beginTotalAmount, e.endTotalAmount);
                                o.setFieldsValue({
                                    consumedTotalAmount: s
                                });
                            } else o.setFieldsValue({
                                consumedTotalAmount: null
                            });
                        }
                    }),
                rules: [
                    {
                        required: m(a),
                        type: "number",
                        message: t("victualingDetail.provisionInventory.provisionItemModal.endQuantityRequired")
                    }
                ]
            },
            {
                field: "endTotalAmount",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.endSubtotal"),
                hidden: m(u),
                componentProps: ({ model: e, formAction: o })=>({
                        min: 0,
                        step: 1,
                        precision: 2,
                        style: {
                            width: "100%"
                        },
                        disabled: !0,
                        placeholder: t("victualingDetail.provisionInventory.provisionItemModal.endSubtotal"),
                        onUpdateValue: (l)=>{
                            if (e.beginTotalAmount >= 0 && l >= 0) {
                                const s = b(e.beginTotalAmount, l);
                                o.setFieldsValue({
                                    consumedTotalAmount: s
                                });
                            } else o.setFieldsValue({
                                consumedTotalAmount: null
                            });
                        }
                    })
            },
            {
                field: "consumedQuantity",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.consumption"),
                hidden: m(u),
                componentProps: {
                    min: 0,
                    step: 1,
                    precision: 0,
                    style: {
                        width: "100%"
                    },
                    disabled: !0,
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.consumption")
                }
            },
            {
                field: "consumedTotalAmount",
                component: "NInputNumber",
                label: t("victualingDetail.provisionInventory.provisionItemModal.consumptionSubtotal"),
                hidden: m(u),
                componentProps: {
                    min: 0,
                    step: 1,
                    precision: 2,
                    style: {
                        width: "100%"
                    },
                    disabled: !0,
                    placeholder: t("victualingDetail.provisionInventory.provisionItemModal.consumptionSubtotal")
                }
            }
        ];
    }
    be = Z({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (i, { expose: a, emit: u }) {
            const { t: n } = D(), e = ee(), o = u, l = g("add"), s = g(!1), v = g(!0), I = g(!0), [_, { submit: P, setProps: w, setSchema: S, getFieldsValue: q, setFieldsValue: x }] = te({
                schemas: A({
                    isLastMonthBalance: s,
                    endQuantityRequired: v,
                    hiddenMonthEndInfo: I,
                    nameValidator: f
                }),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 4
                },
                showActionButtonGroup: !1
            }), [R, { openModal: k, closeModal: B, setSubLoading: T }] = oe({
                title: n("victualingDetail.provisionInventory.provisionItemModal.title"),
                subBtuText: n("common.okText"),
                cancelText: n("common.cancelText"),
                width: 1200
            });
            async function C() {
                try {
                    const r = await P();
                    if (!r) {
                        T(!1);
                        return;
                    }
                    const c = {
                        add: j,
                        edit: $
                    }[l.value], { endTotalAmount: d, consumedQuantity: p, consumedTotalAmount: E, ...h } = r;
                    await c({
                        ...y(h.endQuantity) && {
                            endTotalAmount: d,
                            consumedQuantity: p,
                            consumedTotalAmount: E
                        },
                        ...h
                    });
                    const U = l.value === "add" ? "optionsAddSuccessText" : "optionsEditSuccessText";
                    e.success(n(`common.${U}`)), T(!1), o("refresh"), B();
                } catch (r) {
                    console.error(r), T(!1);
                }
            }
            function O({ type: r, record: c, item: d }) {
                l.value = r, s.value = c?.isLastMonthBalance === 1, v.value = r !== "add", I.value = d?.endQuantity ? !y(+d?.endQuantity) : !0;
                const p = A({
                    isLastMonthBalance: s,
                    endQuantityRequired: v,
                    hiddenMonthEndInfo: I,
                    nameValidator: f
                });
                k(), ne(()=>{
                    w({
                        schemas: p
                    }), S(p), x(le({
                        id: d?.id,
                        provisionPortId: c?.id,
                        currency: c?.currency,
                        data: d
                    }));
                });
            }
            function f() {
                return [
                    {
                        validator: ()=>{
                            const { productName: r, productNameCn: c } = q();
                            return !!(r || c);
                        },
                        message: n("victualingDetail.provisionInventory.provisionItemModal.nameAndNameCnRequired")
                    }
                ];
            }
            return a({
                handleOpenModal: O
            }), (r, c)=>{
                const d = W, p = G;
                return J(), H(p, {
                    onRegister: m(R),
                    onOnOk: C
                }, {
                    default: X(()=>[
                            Y(d, {
                                onRegister: m(_),
                                showActionButtonGroup: !1
                            }, null, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { be as _, __tla };
