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