import { gD as s, V as h, bk as F, d as k, f as x, c as Y, o as _, l as u, w as P, j as C, cZ as I, ac as R, __tla as __tla_0 } from "./index-9PRMimni.js";
import { _ as S } 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 B } from "./useModal-CO65vga3.js";
import { B as E } from "./BasicForm-dL_oCSPM.js";
import { u as O } from "./useForm-CKmgcynv.js";
import { e as z } from "./victualingDetail-CLhgLkA4.js";
import { f as n, __tla as __tla_1 } from "./helper-DMSByp-X.js";
let Q;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    function L({ data: l, standardInfo: r, startDate: t, endDate: i }) {
        if (!l) return {};
        const e = l.days ? Number(l.days) : s(i).diff(s(t), "day") + 1;
        return {
            ...l,
            days: e,
            standard: l.standard ? Number(l.standard) : void 0,
            monthlyCost: e && r.crewStandard ? Number((e * r.crewStandard).toFixed(2)) : void 0
        };
    }
    const m = F(), { t: a } = h();
    function T({ startDate: l, endDate: r }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "crewName",
                component: "NInput",
                hidden: m.getLocale !== "zh_CN",
                label: a("victualingDetail.crewGuestDetails.editModal.crewName"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.crewName")
                }
            },
            {
                field: "crewNameEn",
                component: "NInput",
                hidden: m.getLocale === "zh_CN",
                label: a("victualingDetail.crewGuestDetails.editModal.crewNameEn"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.crewNameEn")
                }
            },
            {
                field: "rankName",
                component: "NInput",
                hidden: m.getLocale !== "zh_CN",
                label: a("victualingDetail.crewGuestDetails.editModal.rankName"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.rankName")
                }
            },
            {
                field: "rankNameEn",
                component: "NInput",
                hidden: m.getLocale === "zh_CN",
                label: a("victualingDetail.crewGuestDetails.editModal.rankNameEn"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.rankNameEn")
                }
            },
            {
                field: "startDate",
                component: "NDatePicker",
                label: a("victualingDetail.crewGuestDetails.editModal.from"),
                defaultValue: l ? n(l) : void 0,
                componentProps: ({ model: t, formAction: i })=>({
                        type: "date",
                        valueFormat: "yyyy-MM-dd",
                        placeholder: a("victualingDetail.crewGuestDetails.editModal.from"),
                        isDateDisabled: (e)=>{
                            if (l && r) {
                                const o = s(n(l)), c = s(n(r));
                                return e < o.toDate() || e > c.toDate();
                            }
                        },
                        onUpdateValue: (e)=>{
                            if (e && t.endDate && s(e).isAfter(s(t.endDate)) && i?.setFieldsValue({
                                startDate: s(e).format("YYYY-MM-DD"),
                                endDate: s(e).format("YYYY-MM-DD")
                            }), t.endDate && e) {
                                const o = s(t.endDate).diff(s(e), "day") + 1;
                                i?.setFieldsValue({
                                    days: o
                                });
                            } else i?.setFieldsValue({
                                days: null
                            });
                            if (t.standard && t.days) {
                                const o = Number((t.standard * t.days).toFixed(2));
                                i?.setFieldsValue({
                                    monthlyCost: o
                                });
                            }
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: a("victualingDetail.crewGuestDetails.editModal.fromRequired")
                    }
                ]
            },
            {
                field: "endDate",
                component: "NDatePicker",
                label: a("victualingDetail.crewGuestDetails.editModal.to"),
                defaultValue: r ? n(r) : void 0,
                componentProps: ({ model: t, formAction: i })=>({
                        type: "date",
                        valueFormat: "yyyy-MM-dd",
                        placeholder: a("victualingDetail.crewGuestDetails.editModal.to"),
                        isDateDisabled: (e)=>{
                            if (l && r) {
                                const o = s(n(l)), c = s(n(r));
                                return e < o.toDate() || e > c.toDate();
                            }
                        },
                        onUpdateValue: (e)=>{
                            if (e && t.startDate && s(e).isBefore(s(t.startDate)) && i?.setFieldsValue({
                                startDate: s(e).format("YYYY-MM-DD"),
                                endDate: s(e).format("YYYY-MM-DD")
                            }), t.startDate && e) {
                                const o = s(e).diff(s(t.startDate), "day") + 1;
                                i?.setFieldsValue({
                                    days: o
                                });
                            } else i?.setFieldsValue({
                                days: null
                            });
                            if (t.standard && t.days) {
                                const o = Number((t.standard * t.days).toFixed(2));
                                i?.setFieldsValue({
                                    monthlyCost: o
                                });
                            }
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: a("victualingDetail.crewGuestDetails.editModal.toRequired")
                    }
                ]
            },
            {
                field: "days",
                component: "NInputNumber",
                label: a("victualingDetail.crewGuestDetails.editModal.days"),
                defaultValue: l && r ? s(n(r)).diff(s(n(l)), "day") + 1 : 0,
                componentProps: ({ model: t, formAction: i })=>({
                        disabled: !0,
                        placeholder: a("victualingDetail.crewGuestDetails.editModal.days"),
                        style: {
                            width: "100%"
                        },
                        precision: 0,
                        step: 1,
                        min: 1,
                        onUpdateValue: (e)=>{
                            if (t.standard && e) {
                                const o = Number((t.standard * e).toFixed(2));
                                i?.setFieldsValue({
                                    monthlyCost: o
                                });
                            }
                        }
                    })
            },
            {
                field: "standard",
                component: "NInputNumber",
                label: a("victualingDetail.crewGuestDetails.editModal.standardOneDay"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.standardOneDay"),
                    style: {
                        width: "100%"
                    },
                    precision: 2,
                    step: 1,
                    min: 1
                }
            },
            {
                field: "monthlyCost",
                component: "NInputNumber",
                label: a("victualingDetail.crewGuestDetails.editModal.ttl"),
                componentProps: {
                    disabled: !0,
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.ttl"),
                    style: {
                        width: "100%"
                    },
                    precision: 2,
                    step: .01,
                    min: 0
                }
            },
            {
                field: "remark",
                component: "NInput",
                giProps: {
                    span: 4
                },
                label: a("victualingDetail.crewGuestDetails.editModal.remark"),
                componentProps: {
                    placeholder: a("victualingDetail.crewGuestDetails.editModal.remark"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                }
            }
        ];
    }
    Q = k({
        __name: "index",
        props: {
            standardInfo: {}
        },
        emits: [
            "refresh",
            "refreshSummary"
        ],
        setup (l, { expose: r, emit: t }) {
            const { t: i } = h(), e = I(), o = x(), c = l, D = t, { startDate: f, endDate: y } = o.query, [w, { openModal: g, closeModal: M, setSubLoading: p }] = B({
                title: i("victualingDetail.crewGuestDetails.editModal.title"),
                subBtuText: i("common.okText"),
                cancelText: i("common.cancelText"),
                width: 1e3
            }), [N, { submit: b, setFieldsValue: G }] = O({
                schemas: T({
                    startDate: f,
                    endDate: y
                }),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 4
                },
                showActionButtonGroup: !1
            });
            async function V() {
                try {
                    const d = await b();
                    if (!d) {
                        p(!1);
                        return;
                    }
                    await z({
                        ...d
                    }), e.success(i("common.saveSuccessText")), p(!1), D("refresh"), D("refreshSummary"), M();
                } catch (d) {
                    console.error(d), p(!1);
                }
            }
            async function v(d) {
                g(), R(()=>{
                    G(L({
                        data: d,
                        standardInfo: c.standardInfo,
                        startDate: f,
                        endDate: y
                    }));
                });
            }
            return r({
                handleOpenModal: v
            }), (d, q)=>(_(), Y(u(S), {
                    onRegister: u(w),
                    onOnOk: V
                }, {
                    default: P(()=>[
                            C(u(E), {
                                onRegister: u(N)
                            }, null, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]));
        }
    });
});
export { Q as _, __tla };
