import { _ as K } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { B as Z } from "./BasicForm-dL_oCSPM.js";
import { _ as J } from "./TableSelect.vue_vue_type_script_setup_true_lang-BAU5mgvB.js";
import { h as M, c as Q, a as X, g as k, d as Y, e as ee, i as te, f as ae } from "./planner-BebmniHR.js";
import { V as B, bk as se, r as a, ay as S, d as le, c as oe, o as ne, l as m, w as F, j as L, ds as re, ac as N, cZ as ie, __tla as __tla_0 } from "./index-9PRMimni.js";
import { u as ue } from "./useModal-CO65vga3.js";
import { u as ce } from "./useForm-CKmgcynv.js";
let Te;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const de = await X();
    function pe() {
        const { t: n } = B(), v = se(), c = a(), d = a(), t = a(), f = a([]), I = a([]), T = a([]), p = a(!1), u = a(!1);
        return S(()=>c.value, async (e)=>{
            e && (f.value = await M(e, 0));
        }, {
            immediate: !0
        }), S(()=>d.value, async (e)=>{
            e && (I.value = await M(c.value, e));
        }, {
            immediate: !0
        }), S(()=>t.value, async (e)=>{
            e && (T.value = await Q(c.value, e));
        }, {
            immediate: !0
        }), {
            modalSchemas: [
                {
                    field: "shipId",
                    component: "NSelect",
                    label: n("hsqe.planner.modal.vessel"),
                    componentProps: ({ formAction: e })=>{
                        const { setFieldsValue: o } = e;
                        return {
                            options: de,
                            "label-field": v.getLocale === "en" ? "shipNameEn" : "shipName",
                            "value-field": "id",
                            disabled: p.value || u.value,
                            onUpdateValue: (s)=>{
                                c.value = s, o({
                                    inspectionTypeId: null,
                                    subTypeId: null,
                                    inspectors: null
                                }), d.value = void 0, t.value = void 0;
                            }
                        };
                    },
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: n("hsqe.planner.modal.vessel"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "inspectionTypeId",
                    component: "NSelect",
                    label: n("hsqe.planner.modal.auditInspectionType"),
                    componentProps: ({ formAction: e })=>{
                        const { setFieldsValue: o } = e;
                        return {
                            disabled: p.value || u.value,
                            options: f.value,
                            "label-field": v.getLocale === "en" ? "content" : "contentCn",
                            "value-field": "id",
                            onUpdateValue: (s)=>{
                                d.value = s, o({
                                    subTypeId: null,
                                    inspectors: null
                                }), t.value = void 0;
                            }
                        };
                    },
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: n("hsqe.planner.modal.auditInspectionType"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "subTypeId",
                    component: "NSelect",
                    label: n("hsqe.planner.modal.auditInspectionSubType"),
                    componentProps: ({ formAction: e })=>{
                        const { setFieldsValue: o } = e;
                        return {
                            disabled: p.value || u.value,
                            options: I.value,
                            "label-field": v.getLocale === "en" ? "content" : "contentCn",
                            "value-field": "id",
                            onUpdateValue: (s)=>{
                                t.value = s, o({
                                    inspectors: null
                                });
                            }
                        };
                    },
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: n("hsqe.planner.modal.auditInspectionSubType"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "planDate",
                    component: "NDatePicker",
                    label: n("hsqe.planner.modal.planDate"),
                    componentProps: {
                        valueFormat: "yyyy-MM-dd",
                        type: "date",
                        isDateDisabled: (e)=>{
                            const o = new Date;
                            o.setHours(0, 0, 0, 0);
                            const s = new Date(e);
                            return s.setHours(0, 0, 0, 0), s < o;
                        },
                        disabled: u
                    },
                    rules: [
                        {
                            required: !0,
                            message: n("hsqe.planner.modal.planDate"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "portId",
                    component: "NSelect",
                    label: n("hsqe.planner.modal.planPort"),
                    componentProps: {},
                    slot: "portId",
                    rules: [
                        {
                            required: !0,
                            message: n("hsqe.planner.modal.planPort"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "inspectors",
                    component: "NSelect",
                    label: n("hsqe.planner.modal.inspector"),
                    componentProps: ()=>({
                            multiple: !0,
                            options: T.value,
                            disabled: u.value,
                            "label-field": "userName",
                            "value-field": "userId",
                            onUpdateValue: (e)=>{}
                        }),
                    rules: [
                        {
                            type: "array",
                            required: !0,
                            message: n("hsqe.planner.modal.inspector"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                }
            ],
            methods: {
                setInitData: (e, o, s)=>{
                    c.value = e, d.value = o, t.value = s;
                },
                setReadOnly: (e, o)=>{
                    p.value = e, u.value = o;
                }
            }
        };
    }
    Te = le({
        __name: "Modal",
        emits: [
            "success"
        ],
        setup (n, { expose: v, emit: c }) {
            const d = c, { t } = B(), f = ie(), { modalSchemas: I, methods: T } = pe(), { setInitData: p, setReadOnly: u } = T, q = a(), x = a(), e = a(), o = a(), s = a({}), O = {
                gridProps: {
                    cols: "2"
                },
                labelWidth: 80,
                submitButtonText: t("common.searchText"),
                showAdvancedButton: !1,
                schemas: [
                    {
                        field: "namePrefix",
                        component: "NInput",
                        label: t("hsqe.planner.modal.planPort")
                    }
                ]
            }, U = [
                {
                    title: t("hsqe.planner.modal.port"),
                    key: "port"
                },
                {
                    title: t("hsqe.planner.modal.country"),
                    key: "country"
                }
            ], w = a(""), [A, { openModal: E, setSubLoading: h, closeModal: D }] = ue({
                title: w,
                subBtuText: t("common.saveText"),
                cancelText: t("common.cancelText"),
                width: 650
            });
            function C(l) {
                return k({
                    ...l,
                    ...m(s)
                });
            }
            const b = a(!1), g = a(!1), P = a(!0);
            async function W(l, r) {
                if (E(), l) {
                    r ? (P.value = !1, b.value = !1, g.value = !0, w.value = t("hsqe.planner.planDetails")) : (P.value = !0, b.value = !0, g.value = !1, w.value = t("common.optionsEditText")), q.value = l, await N();
                    const i = await Y(l);
                    if (i.portId) {
                        const _ = await ee(i.portId);
                        i.portId = _.port;
                    }
                    N(()=>{
                        H(i), p(i.shipId, i.inspectionTypeId, i.subTypeId);
                    });
                } else P.value = !0, b.value = !1, g.value = !1, w.value = t("common.addText"), p(null, null, null);
                u(b.value, g.value);
            }
            const [z, { submit: G, setFieldsValue: H }] = ce({
                layout: "horizontal",
                showActionButtonGroup: !1,
                schemas: I,
                labelWidth: "auto",
                labelPlacement: "top",
                gridProps: {
                    cols: 2,
                    xGap: 45
                }
            });
            async function $() {
                const l = await G();
                if (!l) {
                    h(!1);
                    return;
                }
                try {
                    if (l.portId) {
                        const r = await k({
                            namePrefix: l.portId
                        });
                        r.list.length !== 0 ? l.portId = r.list[0].id : f.error("error");
                    }
                    if (!b.value) await te(l), f.success(t("common.optionsAddSuccessText")), d("success"), h(!1), D();
                    else {
                        const r = {
                            id: q.value,
                            portId: l.portId,
                            inspectors: l.inspectors,
                            planDate: l.planDate
                        };
                        await ae(r) ? (f.success(t("common.optionsEditSuccessText")), d("success"), h(!1), D()) : h(!1);
                    }
                } catch  {
                    h(!1);
                }
            }
            return v({
                showModal: W
            }), (l, r)=>{
                const i = J, _ = Z, j = K;
                return ne(), oe(j, {
                    ref_key: "modalRef",
                    ref: x,
                    onRegister: m(A),
                    class: "basicModal basicFormModal",
                    onOnOk: $,
                    showAction: m(P)
                }, {
                    default: F(()=>[
                            L(_, {
                                ref_key: "formRef",
                                ref: e,
                                onRegister: m(z)
                            }, {
                                portId: F(({ model: R, field: V })=>[
                                        L(i, {
                                            ref_key: "portTableSelectRef",
                                            ref: o,
                                            class: "w-full",
                                            labelField: "port",
                                            valueField: "id",
                                            contentWidth: "530px",
                                            value: R[V],
                                            "onUpdate:value": (y)=>R[V] = y,
                                            formValues: m(s),
                                            "onUpdate:formValues": r[0] || (r[0] = (y)=>re(s) ? s.value = y : null),
                                            multiple: !1,
                                            formProps: O,
                                            disabled: m(g),
                                            selectTitle: m(t)("hsqe.planner.modal.selectPort"),
                                            tableProps: {
                                                rowKey: (y)=>y.id,
                                                request: C,
                                                columns: U,
                                                pagination: {
                                                    simple: !0
                                                }
                                            }
                                        }, null, 8, [
                                            "value",
                                            "onUpdate:value",
                                            "formValues",
                                            "disabled",
                                            "selectTitle",
                                            "tableProps"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]);
            };
        }
    });
});
export { Te as _, __tla };
