import { V as Q, l as c, gD as v, bk as U, d as M, f as O, r as f, c as C, o as Y, w as j, j as z, cZ as W, ac as B, __tla as __tla_0 } from "./index-9PRMimni.js";
import { _ as E } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { u as G } from "./useModal-CO65vga3.js";
import { B as Z } from "./BasicForm-dL_oCSPM.js";
import { u as $ } from "./useForm-CKmgcynv.js";
import { f as S, b as H, c as J, __tla as __tla_1 } from "./helper-Ba6EWhr_.js";
import { i as l } from "./isNumber-D5aBrEhN.js";
import { s as g, m as K } from "./subtract-Dj32RAiL.js";
let ue;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    function X(e = 0, a = 0) {
        const r = l(+e) ? +e : 0, t = l(+a) ? +a : 0;
        return g(r, t) ?? 0;
    }
    function I(e = 0, a = 0) {
        const r = l(+e) ? +e : 0, t = l(+a) ? +a : 0;
        return g(r, t) ?? 0;
    }
    function b(e = 0, a = 0) {
        const r = l(+e) ? +e : 0, t = l(+a) ? +a : 0;
        return K(r, t) ?? 0;
    }
    function L(e) {
        return e ? {
            id: e.id,
            rcvdDate: e.rcvdDate,
            expiryDate: e.expiryDate,
            unit: e.unit,
            initialQuantity: l(+e.initialQuantity) ? +e.initialQuantity : e.initialQuantity,
            consumedQuantity: l(+e.consumedQuantity) ? +e.consumedQuantity : e.consumedQuantity,
            remainingQuantity: l(+e.remainingQuantity) ? +e.remainingQuantity : e.remainingQuantity,
            unitPrice: l(+e.unitPrice) ? +e.unitPrice : e.unitPrice,
            subtotal: l(+e.subtotal) ? +e.subtotal : e.subtotal,
            description: e.description
        } : {};
    }
    U();
    const { t: o } = Q();
    function A({ startDate: e, endDate: a, isLastMonthBalance: r }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "rcvdDate",
                component: "NDatePicker",
                label: o("bondStoreDetail.bondStoreInventory.rcvdDate"),
                defaultValue: S(e),
                componentProps: {
                    disabled: r,
                    type: "date",
                    valueFormat: "yyyy-MM-dd",
                    placeholder: o("bondStoreDetail.bondStoreInventory.rcvdDate"),
                    isDateDisabled: (t)=>{
                        if (e && a && c(r) === !1) {
                            const n = v(S(e)), i = v(S(a));
                            return t < n.toDate() || t > i.toDate();
                        }
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreInventory.rcvdDateRequired")
                    }
                ]
            },
            {
                field: "expiryDate",
                component: "NDatePicker",
                label: o("bondStoreDetail.bondStoreInventory.expiryDate"),
                componentProps: {
                    disabled: r,
                    type: "date",
                    valueFormat: "yyyy-MM-dd",
                    placeholder: o("bondStoreDetail.bondStoreInventory.expiryDate")
                }
            },
            {
                field: "unit",
                component: "NInput",
                label: o("bondStoreDetail.bondStoreInventory.unit"),
                componentProps: {
                    disabled: r,
                    placeholder: o("bondStoreDetail.bondStoreInventory.unit")
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreInventory.unitRequired")
                    }
                ]
            },
            {
                field: "initialQuantity",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreInventory.initialQtty"),
                componentProps: ({ model: t, formAction: n })=>({
                        min: 0,
                        step: 1,
                        precision: 0,
                        style: {
                            width: "100%"
                        },
                        disabled: r?.value,
                        placeholder: o("bondStoreDetail.bondStoreInventory.initialQtty"),
                        onUpdateValue: (i)=>{
                            if (t.consumedQuantity >= 0 && i >= 0) {
                                const s = I(i, t.consumedQuantity);
                                if (n.setFieldsValue({
                                    remainingQuantity: s
                                }), t.unitPrice >= 0 && s >= 0) {
                                    const u = b(s, t.unitPrice);
                                    n.setFieldsValue({
                                        subtotal: u
                                    });
                                }
                            } else n.setFieldsValue({
                                remainingQuantity: null
                            }), n.setFieldsValue({
                                subtotal: null
                            });
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreInventory.initialQttyRequired")
                    }
                ]
            },
            {
                field: "consumedQuantity",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreInventory.consumed"),
                defaultValue: 0,
                componentProps: ({ model: t, formAction: n })=>({
                        min: 0,
                        max: t.initialQuantity ?? 0,
                        step: 1,
                        precision: 0,
                        style: {
                            width: "100%"
                        },
                        placeholder: o("bondStoreDetail.bondStoreInventory.consumed"),
                        onUpdateValue: (i)=>{
                            if (t.initialQuantity >= 0 && i >= 0) {
                                const s = I(t.initialQuantity, i);
                                if (n.setFieldsValue({
                                    remainingQuantity: s
                                }), t.unitPrice >= 0 && s >= 0) {
                                    const u = b(s, t.unitPrice);
                                    n.setFieldsValue({
                                        subtotal: u
                                    });
                                }
                            } else n.setFieldsValue({
                                remainingQuantity: null
                            }), n.setFieldsValue({
                                subtotal: null
                            });
                        }
                    })
            },
            {
                field: "remainingQuantity",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreInventory.qtty"),
                defaultValue: 0,
                componentProps: ({ model: t, formAction: n })=>({
                        min: 0,
                        max: t.initialQuantity ?? 0,
                        step: 1,
                        precision: 0,
                        style: {
                            width: "100%"
                        },
                        disabled: r?.value,
                        placeholder: o("bondStoreDetail.bondStoreInventory.qtty"),
                        onUpdateValue: (i)=>{
                            if (t.unitPrice >= 0 && i >= 0) {
                                const s = b(i, t.unitPrice);
                                n.setFieldsValue({
                                    subtotal: s
                                });
                            } else n.setFieldsValue({
                                subtotal: null
                            });
                            if (t.initialQuantity >= 0 && i >= 0) {
                                const s = X(t.initialQuantity, i);
                                n.setFieldsValue({
                                    consumedQuantity: s
                                });
                            } else n.setFieldsValue({
                                consumedQuantity: null
                            });
                        }
                    })
            },
            {
                field: "unitPrice",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreInventory.priceUsd"),
                componentProps: ({ model: t, formAction: n })=>({
                        min: 0,
                        step: 1,
                        precision: 2,
                        style: {
                            width: "100%"
                        },
                        disabled: r?.value,
                        placeholder: o("bondStoreDetail.bondStoreInventory.priceUsd"),
                        onUpdateValue: (i)=>{
                            if (t.remainingQuantity >= 0 && i >= 0) {
                                const s = b(t.remainingQuantity, i);
                                n.setFieldsValue({
                                    subtotal: s
                                });
                            } else n.setFieldsValue({
                                subtotal: null
                            });
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreInventory.priceUsdRequired")
                    }
                ]
            },
            {
                field: "subtotal",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreInventory.ttlUsd"),
                componentProps: {
                    min: 0,
                    step: 1,
                    precision: 2,
                    style: {
                        width: "100%"
                    },
                    disabled: !0,
                    placeholder: o("bondStoreDetail.bondStoreInventory.ttlUsd")
                }
            },
            {
                field: "description",
                component: "NInput",
                label: o("bondStoreDetail.bondStoreInventory.description"),
                giProps: {
                    span: 2
                },
                componentProps: {
                    disabled: r,
                    placeholder: o("bondStoreDetail.bondStoreInventory.description"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreInventory.descriptionRequired")
                    }
                ]
            }
        ];
    }
    ue = M({
        __name: "index",
        props: {
            summaryData: {}
        },
        emits: [
            "refresh",
            "refreshSummary"
        ],
        setup (e, { expose: a, emit: r }) {
            const { t } = Q(), n = W(), i = O(), s = r, u = f(!1), { year: h, month: V, startDate: P, endDate: N } = i.query, m = f("add"), D = f(!1), [x, { openModal: F, closeModal: w, setSubLoading: y }] = G({
                title: t("bondStoreDetail.inventoryModal.title"),
                subBtuText: t("common.okText"),
                cancelText: t("common.cancelText"),
                width: 1200
            }), [T, { submit: q, setFieldsValue: R }] = $({
                schemas: A({
                    startDate: P,
                    endDate: N,
                    isLastMonthBalance: D
                }),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 4
                },
                showActionButtonGroup: !1
            });
            async function _() {
                try {
                    const d = await q();
                    if (!d) {
                        u.value = !1, y(!1);
                        return;
                    }
                    u.value = !0;
                    const p = {
                        add: J,
                        edit: H
                    }[m.value];
                    await p({
                        ...d,
                        year: h,
                        month: V
                    }), n.success(t("common.saveSuccessText")), u.value = !1, y(!1), s("refresh"), s("refreshSummary"), w();
                } catch (d) {
                    console.error(d), u.value = !1, y(!1);
                }
            }
            async function k(d, p) {
                D.value = p?.isLastMonthBalance === 1, m.value = d ?? "add", F(), B(()=>{
                    R(L(p));
                });
            }
            return a({
                handleOpenModal: k
            }), (d, p)=>(Y(), C(c(E), {
                    onRegister: c(x),
                    showAction: c(m) !== "view",
                    onOnOk: _
                }, {
                    default: j(()=>[
                            z(c(Z), {
                                onRegister: c(T),
                                disabled: c(m) === "view"
                            }, null, 8, [
                                "onRegister",
                                "disabled"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]));
        }
    });
});
export { ue as _, __tla };
