import { r as f, V as N, d as C, bk as B, c$ as k, f as I, a4 as V, ay as j, ac as A, c as L, o as U, X as W, w, j as _, l as r, ds as M, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as $ } from "./BasicForm-dL_oCSPM.js";
import { r as z, __tla as __tla_1 } from "./helper-CNwA55dE.js";
import { c as G } from "./columns-Cv1qVJFZ.js";
import { _ as K } from "./TableSelect.vue_vue_type_script_setup_true_lang-BAU5mgvB.js";
import "./Table.vue_vue_type_style_index_0_scoped_7b9e6ece_lang-BoW2DV_e.js";
import "./print-CT_2hrjP.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import "./vuedraggable.umd-Co2xEC3p.js";
import { g as X } from "./goodsReceiptNoteDetail-DWFnSNrx.js";
import { u as H } from "./useForm-CKmgcynv.js";
let ie;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    const { t: e } = N();
    function J(P = !1, c) {
        const a = f(P);
        return {
            formSchemas: [
                {
                    field: "vesselName",
                    component: "NInput",
                    label: e("pms.VoyagePlanOffice.vessel"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        placeholder: e("common.inputText"),
                        disabled: !0
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("common.RequireTips")
                        }
                    ]
                },
                {
                    field: "voyageNo",
                    component: "NInput",
                    label: e("pms.VoyagePlanOffice.voyageNo"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        placeholder: e("common.inputText"),
                        disabled: a.value
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("common.RequireTips"),
                            trigger: "blur"
                        }
                    ]
                },
                {
                    field: "originPort",
                    label: e("pms.VoyagePlanOfficeDetail.originPort"),
                    slot: "receivePortSlot",
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("requisitionOrder.detailsTab.expectedPlace")
                    }
                },
                {
                    field: "etd",
                    component: "NDatePicker",
                    label: e("pms.VoyagePlanOfficeDetail.ETD"),
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("pms.VoyagePlanOfficeDetail.ETD"),
                        type: "datetime"
                    },
                    rules: [
                        {
                            required: !0,
                            type: "number",
                            message: e("common.RequireTips"),
                            trigger: [
                                "change"
                            ],
                            validator: (g, t)=>{
                                const { getFieldsValue: m } = c.value, { eta: s } = m();
                                return !t || isNaN(new Date(t).getTime()) ? Promise.reject(new Error(e("common.RequireTips"))) : s && t && new Date(t) >= new Date(s) ? Promise.reject(new Error("ETA must be later than ETD")) : Promise.resolve();
                            }
                        }
                    ]
                },
                {
                    field: "destinationPort",
                    label: e("pms.VoyagePlanOfficeDetail.destinationPort"),
                    slot: "receivePortSlot",
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("requisitionOrder.detailsTab.expectedPlace")
                    }
                },
                {
                    field: "eta",
                    component: "NDatePicker",
                    label: e("pms.VoyagePlanOfficeDetail.ETA"),
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("pms.VoyagePlanOfficeDetail.ETA"),
                        type: "datetime"
                    },
                    rules: [
                        {
                            required: !0,
                            type: "number",
                            trigger: [
                                "change"
                            ],
                            validator: (g, t)=>{
                                const { getFieldsValue: m } = c.value, { etd: s } = m();
                                return !t || isNaN(new Date(t).getTime()) ? Promise.reject(new Error(e("common.RequireTips"))) : s && t && new Date(t) <= new Date(s) ? Promise.reject(new Error("ETA must be later than ETD")) : Promise.resolve();
                            }
                        }
                    ]
                },
                {
                    field: "days",
                    component: "NInput",
                    label: e("pms.VoyagePlanOfficeDetail.days"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        disabled: !0,
                        placeholder: e("common.inputText")
                    }
                },
                {
                    field: "totalSeaDistance",
                    component: "NInput",
                    label: e("pms.VoyagePlanOfficeDetail.totalSeaDistance"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("common.inputText")
                    },
                    rules: [
                        {
                            required: !0,
                            message: e("common.RequireTips"),
                            trigger: "blur"
                        }
                    ]
                },
                {
                    field: "voyagePlan",
                    component: "NInput",
                    label: e("pms.VoyagePlanOfficeDetail.voyagePlan"),
                    giProps: {
                        span: 1
                    },
                    componentProps: {
                        disabled: a.value,
                        placeholder: e("common.inputText")
                    }
                }
            ]
        };
    }
    ie = C({
        __name: "index",
        props: {
            sourceData: {
                default: null,
                type: Object
            },
            isView: {
                default: !1,
                type: Boolean
            }
        },
        setup (P, { expose: c }) {
            const a = B(), v = P, { t: g } = N(), t = k(), s = I().query, D = V(()=>s.status === "view"), y = f(), p = f({}), O = f({}), q = V(()=>{
                const { formSchemas: o } = J(D.value, y);
                return o;
            }), [S, h, F] = H({
                gridProps: {
                    cols: 5
                },
                layout: "horizontal",
                schemas: q,
                showActionButtonGroup: !1,
                validateOnMount: !1
            }), { setFieldsValue: T } = h;
            function x(o) {
                O.value = o;
            }
            function E(o) {
                return X({
                    ...o,
                    ...r(p)
                });
            }
            function R(o) {
                const { eta: n, etd: u } = o;
                if (n && u) {
                    const b = new Date(n), d = new Date(u), i = b.getTime() - d.getTime(), l = Math.floor(i / (1e3 * 60 * 60 * 24));
                    T({
                        days: l
                    });
                }
            }
            return c({
                validate () {
                    return new Promise((o, n)=>{
                        h.validate().then(()=>{
                            o(!0);
                        }).catch(()=>{
                            n("1");
                        });
                    });
                },
                getFieldsValue: h.getFieldsValue
            }), j(()=>v.sourceData, (o)=>{
                A(()=>{
                    T({
                        vesselName: o?.vesselName || a.getLocale === "en" ? t.shipList[0]?.shipNameEn : t.shipList[0]?.shipName,
                        ...o
                    });
                });
            }, {
                immediate: !0
            }), (o, n)=>{
                const u = $, b = W;
                return U(), L(b, null, {
                    default: w(()=>[
                            _(u, {
                                ref_key: "formRef",
                                ref: y,
                                onRegister: r(S),
                                onChange: R
                            }, {
                                receivePortSlot: w(({ model: d, field: i })=>[
                                        _(r(K), {
                                            class: "w-full",
                                            labelField: "port",
                                            valueField: "id",
                                            value: d[i],
                                            "onUpdate:value": (l)=>d[i] = l,
                                            formValues: r(p),
                                            "onUpdate:formValues": n[0] || (n[0] = (l)=>M(p) ? p.value = l : null),
                                            onChange: x,
                                            onClear: ()=>r(F).setFieldsValue({
                                                    [i]: void 0
                                                }),
                                            multiple: !1,
                                            formProps: r(z),
                                            selectTitle: r(g)("common.selectPort"),
                                            disabled: r(D),
                                            tableProps: {
                                                rowKey: (l)=>l.id,
                                                request: E,
                                                columns: r(G)(),
                                                pagination: {
                                                    simple: !0
                                                }
                                            }
                                        }, null, 8, [
                                            "value",
                                            "onUpdate:value",
                                            "formValues",
                                            "onClear",
                                            "formProps",
                                            "selectTitle",
                                            "disabled",
                                            "tableProps"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { ie as _, __tla };
