import { B as X } from "./BasicForm-dL_oCSPM.js";
import { _ as Z } 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 G } from "./useModal-CO65vga3.js";
import { ad as y, V as v, bk as I, d as J, r as x, c as K, o as Y, l as i, w as E, j as m, ee, ch as te, aA as ie, cZ as se, ac as ae, __tla as __tla_0 } from "./index-9PRMimni.js";
import { v as F } from "./helper-D9DF1oLX.js";
import { g as T } from "./equipmentMainLibrary-bJTzj5mC.js";
import { u as re } from "./useForm-CKmgcynv.js";
let o, Ne, Pe, Ee, be, we;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const { HSQE_PREFIX: f } = Object.fromEntries([
        [
            "HSQE_PREFIX",
            "/tx"
        ]
    ].map(([e, g])=>[
            e,
            ""
        ]));
    be = function(e) {
        return y.Post(`${f}/certificateConfig/listPage`, e);
    };
    function le(e) {
        return y.Post(`${f}/certificateConfig/insert`, e);
    }
    function oe(e) {
        return y.Post(`${f}/certificateConfig/update`, e);
    }
    we = function(e) {
        return y.Post(`${f}/certificateConfig/issue`, e);
    };
    Pe = function(e) {
        return y.Post(`${f}/certificateConfig/cancel`, e);
    };
    const { t: N } = v(), p = "2";
    o = ((e)=>(e.ADD = "add", e.VIEW = "view", e.EDIT = "edit", e))(o || {});
    function ne(e = "view") {
        switch(e){
            case "add":
                return N("vesselsCertificateType.addCertificateType");
            case "view":
                return N("vesselsCertificateType.viewCertificateType");
            case "edit":
                return N("vesselsCertificateType.editCertificateType");
            default:
                return "";
        }
    }
    function ce(e) {
        return e ? {
            ...e,
            category: e.hasOwnProperty("category") ? e.category + "" : void 0,
            type: e.hasOwnProperty("type") ? e.type + "" : void 0,
            vesselType: e.hasOwnProperty("vesselType") ? e.vesselType + "" : void 0,
            termType: e.hasOwnProperty("termType") ? e.termType + "" : void 0
        } : {};
    }
    const { t: O } = v(), pe = I(), $ = await T("sms_category");
    Ee = function() {
        return [
            {
                field: "vesselType",
                component: "NSelect",
                label: O("vesselsCertificateType.vesselType"),
                componentProps: {
                    placeholder: O("vesselsCertificateType.vesselType"),
                    labelField: pe.getLocale === "en" ? "labelEn" : "label",
                    options: $
                }
            }
        ];
    };
    const { t } = v(), u = I(), ue = await T("certificate_category"), ye = await T("ship_certificate_type"), fe = await T("certificate_validity_type");
    function R({ validityTypeRequired: e } = {
        validityTypeRequired: !0
    }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "category",
                component: "NSelect",
                label: t("vesselsCertificateType.certificateCategory"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.certificateCategory"),
                    labelField: u.getLocale === "en" ? "labelEn" : "label",
                    options: ue
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.certificateCategoryRequired")
                    }
                ]
            },
            {
                field: "type",
                component: "NSelect",
                label: t("vesselsCertificateType.certificateType"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.certificateType"),
                    labelField: u.getLocale === "en" ? "labelEn" : "label",
                    options: ye
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.certificateTypeRequired")
                    }
                ]
            },
            {
                field: "no",
                component: "NInput",
                label: t("vesselsCertificateType.certificateTypeNo"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.certificateTypeNo")
                },
                rules: [
                    {
                        required: !0,
                        validator: (g, l)=>l == null || l === "" ? new Error(`${t("vesselsCertificateType.certificateTypeNoRequired")}`) : /^[A-Z]/.test(l) ? !0 : new Error(`${t("vesselsCertificateType.certificateTypeNoStartWithLetter")}`)
                    }
                ]
            },
            {
                field: "vesselType",
                component: "NSelect",
                label: t("vesselsCertificateType.vesselType"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.vesselType"),
                    labelField: u.getLocale === "en" ? "labelEn" : "label",
                    options: $
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.vesselTypeRequired")
                    }
                ]
            },
            {
                field: "englishName",
                component: "NInput",
                label: t("vesselsCertificateType.certificateNameEn"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.certificateNameEn")
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.certificateNameEnRequired")
                    }
                ]
            },
            {
                field: "chineseName",
                component: "NInput",
                label: t("vesselsCertificateType.certificateNameCn"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.certificateNameCn")
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.certificateNameCnRequired")
                    }
                ]
            },
            {
                field: "termType",
                component: "NSelect",
                label: t("vesselsCertificateType.validityType"),
                componentProps: {
                    placeholder: t("vesselsCertificateType.validityType"),
                    labelField: u.getLocale === "en" ? "labelEn" : "label",
                    options: fe
                },
                rules: [
                    {
                        required: !0,
                        message: t("vesselsCertificateType.certificateTypeRequired")
                    }
                ]
            },
            {
                field: "validity",
                label: t("vesselsCertificateType.validity"),
                slot: "validitySlot",
                rules: [
                    {
                        required: e,
                        message: t("vesselsCertificateType.validityRequired")
                    }
                ]
            },
            {
                field: "validityUnit",
                hidden: !0
            },
            {
                field: "remark",
                component: "NInput",
                label: t("vesselsCertificateType.remark"),
                giProps: {
                    span: 3
                },
                showFeedback: !1,
                componentProps: {
                    placeholder: t("vesselsCertificateType.remark"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                }
            }
        ];
    }
    Ne = J({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (e, { expose: g, emit: l }) {
            const { t: d } = v(), U = se(), k = l, q = x(o.VIEW), n = x(!1), [L, { submit: V, setFieldsValue: C, setSchema: A, setProps: B }] = re({
                schemas: R(),
                layout: "horizontal",
                gridProps: {
                    cols: 3
                }
            }), [D, { setProps: W, openModal: M, closeModal: j, setSubLoading: h }] = G({
                subBtuText: d("common.confirmText"),
                cancelText: d("common.cancelText"),
                width: 840
            });
            function z(s) {
                const { termType: a, validityUnit: c } = s;
                C(a === p ? {
                    validity: null,
                    validityUnit: null
                } : {
                    validityUnit: c ?? 0
                }), A(R({
                    validityTypeRequired: a !== p
                })), B({
                    schemas: R({
                        validityTypeRequired: a !== p
                    })
                });
            }
            async function H() {
                try {
                    const s = await V();
                    if (!s) {
                        h(!1);
                        return;
                    }
                    const a = {
                        [o.ADD]: le,
                        [o.EDIT]: oe
                    }[q.value], { category: c, type: _, vesselType: b, termType: w, ...r } = s;
                    await a({
                        category: +c,
                        type: +_,
                        vesselType: +b,
                        termType: +w,
                        ...r
                    }), U.success(d("common.saveSuccessText")), h(!1), k("refresh"), j();
                } catch  {
                    h(!1);
                }
            }
            async function Q({ mode: s, record: a }) {
                q.value = s || o.VIEW, n.value = s === o.VIEW, W({
                    title: ne(s)
                }), M(), await ae(), C(ce(a));
            }
            return g({
                handleOpenModal: Q
            }), (s, a)=>{
                const c = te, _ = ie, b = ee, w = X;
                return Y(), K(i(Z), {
                    onRegister: i(D),
                    onOnOk: H,
                    showAction: !i(n)
                }, {
                    default: E(()=>[
                            m(w, {
                                onRegister: i(L),
                                showActionButtonGroup: !1,
                                disabled: i(n),
                                onChange: z
                            }, {
                                validitySlot: E(({ model: r, field: S })=>[
                                        m(b, null, {
                                            default: E(()=>[
                                                    m(c, {
                                                        disabled: r.termType === i(p) || i(n),
                                                        placeholder: i(d)("vesselsCertificateType.validity"),
                                                        value: r[S],
                                                        "onUpdate:value": (P)=>r[S] = P,
                                                        min: 1
                                                    }, null, 8, [
                                                        "disabled",
                                                        "placeholder",
                                                        "value",
                                                        "onUpdate:value"
                                                    ]),
                                                    m(_, {
                                                        disabled: r.termType === i(p) || i(n),
                                                        value: r.validityUnit,
                                                        "onUpdate:value": (P)=>r.validityUnit = P,
                                                        options: i(F),
                                                        "default-value": i(F)?.[0].value,
                                                        "label-field": i(u).getLocale === "en" ? "labelEn" : "label",
                                                        class: "w-[120px]",
                                                        placeholder: ""
                                                    }, null, 8, [
                                                        "disabled",
                                                        "value",
                                                        "onUpdate:value",
                                                        "options",
                                                        "default-value",
                                                        "label-field"
                                                    ])
                                                ]),
                                            _: 2
                                        }, 1024)
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister",
                                "disabled"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]);
            };
        }
    });
});
export { o as M, Ne as _, Pe as a, Ee as c, be as g, we as i, __tla };
