import { _ as se } 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 te } from "./BasicForm-dL_oCSPM.js";
import { V as G, r as t, a as ie, ay as S, d as oe, ac as ue, c as re, o as T, l as C, w as M, j as R, p as O, A, c7 as ne, H as ce, h as F, a9 as de, aE as pe, hI as ve, i as me, F as fe, cZ as be, __tla as __tla_0 } from "./index-9PRMimni.js";
import { b as B, c as ge, d as he, e as ye, g as xe, f as Ie } from "./planner-BebmniHR.js";
import { a as Pe, i as _e } from "./group-DxznlajQ.js";
import { e as Me } from "./dictionary-BRse4lkf.js";
import { p as ke } from "./plan-n8bSdRD5.js";
import { u as we } from "./useModal-CO65vga3.js";
import { u as Se } from "./useForm-CKmgcynv.js";
let Ye;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const Te = await Pe({}), Re = await Me({
        dictCode: "exercise_project_peroid",
        pageNum: 1,
        pageSize: 999
    }), Ve = await _e({
        pageNum: 1,
        pageSize: 999
    }), { list: De } = Ve;
    function Ne() {
        const { t: u } = G(), v = t(), I = t(), m = t(), P = t([]), d = t([]), b = t([]), p = ie([]), k = t(!1), g = t(!1);
        return S(()=>v.value, async (o)=>{
            o && (P.value = await B(o, 0));
        }, {
            immediate: !0
        }), S(()=>I.value, async (o)=>{
            o && (d.value = await B(v.value, o));
        }, {
            immediate: !0
        }), S(()=>m.value, async (o)=>{
            o && (b.value = await ge(v.value, o));
        }, {
            immediate: !0
        }), {
            modalSchemas: [
                {
                    field: "exerciseType",
                    component: "NSelect",
                    label: u("drill.addPlan.modalType"),
                    componentProps: ()=>({
                            options: p
                        }),
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: u("drill.addPlan.modalTypeRulesMessage"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "exerciseGroupId",
                    component: "NSelect",
                    label: u("drill.addPlan.modalGroup"),
                    componentProps: ()=>({
                            options: Te.records,
                            "label-field": "groupName",
                            "value-field": "id"
                        }),
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: u("drill.addPlan.modalGroupRulesMessage"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "exerciseProjectId",
                    component: "NSelect",
                    label: u("drill.addPlan.modalItem"),
                    componentProps: ()=>({
                            options: De,
                            "label-field": "projectEnglish",
                            "value-field": "id"
                        }),
                    rules: [
                        {
                            type: "number",
                            required: !0,
                            message: u("drill.addPlan.modalItemRulesMessage"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "exerciseCycle",
                    component: "NSelect",
                    label: u("drill.addPlan.modalPeroid"),
                    componentProps: ()=>({
                            options: Re.list,
                            "label-field": "value",
                            "value-field": "value"
                        }),
                    rules: [
                        {
                            type: "string",
                            required: !0,
                            message: u("drill.addPlan.modalPeroidRulesMessage"),
                            trigger: [
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "exerciseYears",
                    component: "NDatePicker",
                    label: u("drill.addPlan.modalYear"),
                    componentProps: {
                        valueFormat: "yyyy",
                        type: "year",
                        isDateDisabled: ()=>{},
                        disabled: g
                    },
                    rules: [
                        {
                            required: !0,
                            message: u("drill.addPlan.modalYearRulesMessage"),
                            trigger: [
                                "blur",
                                "change"
                            ]
                        }
                    ]
                },
                {
                    field: "portId",
                    component: "NSelect",
                    label: u("drill.addPlan.modalMonth"),
                    componentProps: {},
                    slot: "portId"
                }
            ],
            methods: {
                setInitData: (o, h, f)=>{
                    v.value = o, I.value = h, m.value = f;
                },
                setReadOnly: (o, h)=>{
                    k.value = o, g.value = h;
                },
                setAaaValue: (o)=>{
                    o === "1003" ? p.splice(0, p.length, {
                        label: "Annual",
                        value: 0
                    }) : p.splice(0, p.length, {
                        label: "Temporary",
                        value: 1
                    });
                }
            }
        };
    }
    let Ee;
    Ee = [
        "value",
        "disabled"
    ];
    Ye = oe({
        __name: "Modal",
        props: {
            shipInfo: {
                type: Object
            },
            singleVesselStatus: {
                type: String
            }
        },
        emits: [
            "success"
        ],
        setup (u, { expose: v, emit: I }) {
            v({
                showModal: W
            });
            const m = u, P = I, { t: d } = G(), b = be(), { modalSchemas: p, methods: k } = Ne(), { setInitData: g, setReadOnly: V, setAaaValue: D } = k, [o, { openModal: h, setSubLoading: f, closeModal: N }] = we({
                title: d("common.addText"),
                subBtuText: d("common.saveText"),
                cancelText: d("common.cancelText"),
                width: 650
            }), [j, { submit: q, setFieldsValue: J }] = Se({
                layout: "horizontal",
                showActionButtonGroup: !1,
                schemas: p,
                labelWidth: "auto",
                labelPlacement: "top",
                gridProps: {
                    cols: 2,
                    xGap: 45
                }
            }), E = t(), L = t([]), Y = t(), z = t(), n = t([
                {
                    month: "Jan",
                    disabled: !0,
                    value: 1
                },
                {
                    month: "Feb",
                    disabled: !0,
                    value: 2
                },
                {
                    month: "Mar",
                    disabled: !0,
                    value: 3
                },
                {
                    month: "Apr",
                    disabled: !0,
                    value: 4
                },
                {
                    month: "May",
                    disabled: !0,
                    value: 5
                },
                {
                    month: "Jun",
                    disabled: !0,
                    value: 6
                },
                {
                    month: "Jul",
                    disabled: !0,
                    value: 7
                },
                {
                    month: "Aug",
                    disabled: !0,
                    value: 8
                },
                {
                    month: "Sep",
                    disabled: !0,
                    value: 9
                },
                {
                    month: "Oct",
                    disabled: !0,
                    value: 10
                },
                {
                    month: "Nov",
                    disabled: !0,
                    value: 11
                },
                {
                    month: "Dec",
                    disabled: !0,
                    value: 12
                }
            ]), U = t([
                {
                    month: "null",
                    value: 0
                },
                {
                    month: "January",
                    value: 1
                },
                {
                    month: "February",
                    value: 2
                },
                {
                    month: "March",
                    value: 3
                },
                {
                    month: "April",
                    value: 4
                },
                {
                    month: "May",
                    value: 5
                },
                {
                    month: "June",
                    value: 6
                },
                {
                    month: "July",
                    value: 7
                },
                {
                    month: "August",
                    value: 8
                },
                {
                    month: "September",
                    value: 9
                },
                {
                    month: "October",
                    value: 10
                },
                {
                    month: "November",
                    value: 11
                },
                {
                    month: "December",
                    value: 12
                }
            ]), c = t(null), l = t([]), H = t({}), y = t(!1), _ = t(!1), w = t(!0);
            async function W(a, s) {
                if (h(), a) {
                    s ? (w.value = !1, y.value = !1, _.value = !0) : (w.value = !0, y.value = !0, _.value = !1), E.value = a, await ue();
                    const e = await he(a);
                    if (e.portId) {
                        const i = await ye(e.portId);
                        e.portId = i.port;
                    }
                    J(e), g(e.shipId, e.inspectionTypeId, e.subTypeId);
                } else w.value = !0, y.value = !1, _.value = !1, g(null, null, null);
                V(y.value, _.value), D(m.singleVesselStatus);
            }
            function Z(a, s) {
                switch(console.log(s, "0-0"), a && a.exerciseType && a.exerciseType, H.value = {
                    ...a
                }, a.exerciseCycle){
                    case "Monthly":
                        c.value = 1;
                        break;
                    case "2 Monthly":
                        c.value = 2;
                        break;
                    case "3 Monthly":
                        c.value = 3;
                        break;
                    case "4 Monthly":
                        c.value = 4;
                        break;
                    case "6 Monthly":
                        c.value = 6;
                        break;
                    case "Yearly":
                        c.value = 12;
                        break;
                }
                switch(n.value.forEach((e)=>{
                    e.disabled = !1;
                }), l.value = [], c.value){
                    case 1:
                        n.value.forEach((e)=>{
                            e.disabled = !0, l.value.push(e.value);
                        });
                        break;
                    case 2:
                        n.value.forEach((e)=>{
                            e.value > 2 && (e.disabled = !0);
                        });
                        break;
                    case 3:
                        n.value.forEach((e)=>{
                            e.value > 4 && (e.disabled = !0);
                        });
                        break;
                    case 4:
                        n.value.forEach((e)=>{
                            e.value > 3 && (e.disabled = !0);
                        });
                        break;
                    case 6:
                        n.value.forEach((e)=>{
                            e.value > 6 && (e.disabled = !0);
                        });
                        break;
                }
                return "";
            }
            function $() {
                const a = c.value;
                if (a === 12 && l.value.length > 1) l.value = [
                    l.value[l.value.length - 1]
                ];
                else if (a !== 12 && l.value.length > 0) {
                    const s = l.value[0];
                    n.value.forEach((e)=>{
                        if (a === 6) {
                            const i = e.value === s || e.value === s + 6;
                            if (e.disabled = !i, i) l.value.includes(e.value) || l.value.push(e.value);
                            else {
                                const r = l.value.indexOf(e.value);
                                r > -1 && l.value.splice(r, 1);
                            }
                        } else if (a === 3) {
                            const i = (e.value - s) % 4 === 0 && e.value >= s;
                            if (e.disabled = !i, i) l.value.includes(e.value) || l.value.push(e.value);
                            else {
                                const r = l.value.indexOf(e.value);
                                r > -1 && l.value.splice(r, 1);
                            }
                        } else if (a === 2) {
                            const i = (e.value - s) % 2 === 0 && e.value >= s;
                            if (e.disabled = !i, i) l.value.includes(e.value) || l.value.push(e.value);
                            else {
                                const r = l.value.indexOf(e.value);
                                r > -1 && l.value.splice(r, 1);
                            }
                        } else if (a === 4) {
                            const i = (e.value - s) % 4 === 0 && e.value >= s;
                            if (e.disabled = !i, i) l.value.includes(e.value) || l.value.push(e.value);
                            else {
                                const r = l.value.indexOf(e.value);
                                r > -1 && l.value.splice(r, 1);
                            }
                        } else {
                            const i = a !== null && (e.value - s) % a === 0;
                            e.disabled = !i;
                        }
                    });
                }
            }
            async function K() {
                const a = await q();
                if (!a) {
                    f(!1);
                    return;
                }
                if (a.portId) {
                    const s = await xe({
                        namePrefix: a.portId
                    });
                    s.list.length !== 0 ? a.portId = s.list[0].id : b.error("error");
                }
                if (y.value) {
                    const s = {
                        id: E.value,
                        portId: a.portId,
                        inspectors: a.inspectors,
                        planDate: a.planDate
                    };
                    await Ie(s) ? (b.success(d("common.optionsEditSuccessText")), P("success"), f(!1), N()) : f(!1);
                } else {
                    let s = l.value.map((i)=>U.value[i].month), e = {
                        exercisePlan: {
                            moduleCode: "singleVesselExercise",
                            exerciseYears: a.exerciseYears,
                            exerciseShipId: m.shipInfo ? m.shipInfo.id : null
                        },
                        exercisePlanDetails: {
                            exerciseGroupId: a.exerciseGroupId,
                            exerciseProjectId: a.exerciseProjectId,
                            exerciseType: a.exerciseType,
                            exerciseCycle: a.exerciseCycle,
                            exerciseMonth: s.toString()
                        }
                    };
                    await ke(e), b.success(d("common.optionsAddSuccessText")), P("success"), f(!1), N();
                }
            }
            return (a, s)=>{
                const e = ce, i = ne, r = te, Q = se;
                return T(), re(Q, {
                    ref_key: "modalRef",
                    ref: Y,
                    onRegister: C(o),
                    class: "basicModal basicFormModal",
                    onOnOk: K
                }, {
                    default: M(()=>[
                            R(r, {
                                ref_key: "formRef",
                                ref: z,
                                onRegister: C(j)
                            }, {
                                portId: M(({ model: X, field: ee })=>[
                                        O(A(Z(X, ee)) + " ", 1),
                                        R(i, {
                                            value: L.value,
                                            "onUpdate:value": s[1] || (s[1] = (x)=>L.value = x)
                                        }, {
                                            default: M(()=>[
                                                    R(e, {
                                                        "item-style": "display: flex;"
                                                    }, {
                                                        default: M(()=>[
                                                                (T(!0), F(fe, null, de(n.value, (x, ae)=>(T(), F("div", {
                                                                        key: ae
                                                                    }, [
                                                                        pe(me("input", {
                                                                            type: "checkbox",
                                                                            value: x.value,
                                                                            "onUpdate:modelValue": s[0] || (s[0] = (le)=>l.value = le),
                                                                            disabled: x.disabled,
                                                                            onChange: $
                                                                        }, null, 40, Ee), [
                                                                            [
                                                                                ve,
                                                                                l.value
                                                                            ]
                                                                        ]),
                                                                        O(" " + A(x.month), 1)
                                                                    ]))), 128))
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "value"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Ye as _, __tla };
