import { V as g, gD as S, bk as I, d as M, f as T, r as h, c as B, o as F, l as s, w as O, j as C, cZ as z, ac as A, __tla as __tla_0 } from "./index-9PRMimni.js";
import { _ as L } 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 j } from "./useModal-CO65vga3.js";
import { B as W } from "./BasicForm-dL_oCSPM.js";
import { u as E } from "./useForm-CKmgcynv.js";
import { f as b, e as G, a as Z, __tla as __tla_1 } from "./helper-Ba6EWhr_.js";
import { i as n } from "./isNumber-D5aBrEhN.js";
let te;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    function $(e) {
        return e ? {
            id: e.id,
            date: e.date,
            details: e.details,
            invoiceNo: e.invoiceNo,
            consumed: n(+e.consumed) ? +e.consumed : e.consumed,
            purchased: n(+e.purchased) ? +e.purchased : e.purchased,
            approver: e.approver,
            remark: e.remark
        } : {};
    }
    I();
    const { t: o } = g();
    function H({ startDate: e, endDate: i, consumedValidator: u }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "date",
                component: "NDatePicker",
                label: o("bondStoreDetail.bondStoreDetails.date"),
                defaultValue: b(e),
                componentProps: {
                    type: "date",
                    valueFormat: "yyyy-MM-dd",
                    placeholder: o("bondStoreDetail.bondStoreDetails.date"),
                    isDateDisabled: (a)=>{
                        if (e && i) {
                            const c = S(b(e)), m = S(b(i));
                            return a < c.toDate() || a > m.toDate();
                        }
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreDetails.dateRequired")
                    }
                ]
            },
            {
                field: "",
                giProps: {
                    span: 3
                }
            },
            {
                field: "invoiceNo",
                component: "NInput",
                label: o("bondStoreDetail.bondStoreDetails.invoiceNum"),
                componentProps: {
                    placeholder: o("bondStoreDetail.bondStoreDetails.invoiceNum")
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreDetails.invoiceNumRequired")
                    }
                ]
            },
            {
                field: "consumed",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreDetails.consumed"),
                defaultValue: 0,
                componentProps: {
                    min: 0,
                    step: 1,
                    precision: 2,
                    style: {
                        width: "100%"
                    },
                    placeholder: o("bondStoreDetail.bondStoreDetails.consumed")
                },
                rules: u()
            },
            {
                field: "purchased",
                component: "NInputNumber",
                label: o("bondStoreDetail.bondStoreDetails.purchased"),
                defaultValue: 0,
                componentProps: {
                    min: 0,
                    step: 1,
                    precision: 2,
                    style: {
                        width: "100%"
                    },
                    placeholder: o("bondStoreDetail.bondStoreDetails.purchased")
                }
            },
            {
                field: "approver",
                component: "NInput",
                label: o("bondStoreDetail.bondStoreDetails.approval"),
                componentProps: {
                    placeholder: o("bondStoreDetail.bondStoreDetails.approval")
                }
            },
            {
                field: "details",
                component: "NInput",
                giProps: {
                    span: 2
                },
                label: o("bondStoreDetail.bondStoreDetails.details"),
                componentProps: {
                    placeholder: o("bondStoreDetail.bondStoreDetails.details"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: o("bondStoreDetail.bondStoreDetails.detailsRequired")
                    }
                ]
            },
            {
                field: "remark",
                component: "NInput",
                giProps: {
                    span: 2
                },
                label: o("bondStoreDetail.bondStoreDetails.remark"),
                componentProps: {
                    placeholder: o("bondStoreDetail.bondStoreDetails.remark"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                }
            }
        ];
    }
    te = M({
        __name: "index",
        props: {
            summaryData: {}
        },
        emits: [
            "refresh",
            "refreshSummary"
        ],
        setup (e, { expose: i, emit: u }) {
            const { t: a } = g(), c = z(), m = T(), f = u, l = h(!1), { startDate: v, endDate: y } = m.query, d = h("add"), [w, { openModal: x, closeModal: N, setSubLoading: p }] = j({
                title: a("bondStoreDetail.detailsModal.title"),
                subBtuText: a("common.okText"),
                cancelText: a("common.cancelText"),
                width: 1200
            }), [R, { submit: k, getFieldsValue: D, setFieldsValue: P }] = E({
                schemas: H({
                    startDate: v,
                    endDate: y,
                    consumedValidator: q
                }),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 4
                },
                showActionButtonGroup: !1
            });
            async function _() {
                try {
                    const t = await k();
                    if (!t) {
                        l.value = !1, p(!1);
                        return;
                    }
                    l.value = !0;
                    const r = {
                        add: Z,
                        edit: G
                    }[d.value];
                    await r({
                        ...t
                    }), c.success(a("common.saveSuccessText")), l.value = !1, p(!1), f("refresh"), f("refreshSummary"), N();
                } catch (t) {
                    console.error(t), l.value = !1, p(!1);
                }
            }
            async function V(t, r) {
                d.value = t ?? "add", x(), A(()=>{
                    P($(r));
                });
            }
            function q() {
                return [
                    {
                        validator: ()=>{
                            const { consumed: t, purchased: r } = D();
                            return !!(n(+t) && +t > 0 || n(+r) && +r > 0);
                        },
                        message: a("bondStoreDetail.bondStoreDetails.consumedRequired")
                    },
                    {
                        validator: ()=>{
                            const { consumed: t, purchased: r } = D();
                            return !(n(+t) && +t > 0 && n(+r) && +r > 0);
                        },
                        message: a("bondStoreDetail.bondStoreDetails.consumedOrPurchasedRequired")
                    }
                ];
            }
            return i({
                handleOpenModal: V
            }), (t, r)=>(F(), B(s(L), {
                    onRegister: s(w),
                    showAction: s(d) !== "view",
                    onOnOk: _
                }, {
                    default: O(()=>[
                            C(s(W), {
                                onRegister: s(R),
                                disabled: s(d) === "view"
                            }, null, 8, [
                                "onRegister",
                                "disabled"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]));
        }
    });
});
export { te as _, __tla };
