import { B as Q } from "./BasicForm-dL_oCSPM.js";
import { _ as X } 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 ee } from "./useModal-CO65vga3.js";
import { V as E, gI as T, bk as L, gD as te, d as se, r as D, c as q, o as A, l as a, w as n, j as h, B as ae, p as x, A as b, aH as ie, cq as oe, cO as re, fm as le, hK as ne, i as ce, bR as fe, R as pe, cZ as I, ac as ue, __tla as __tla_0 } from "./index-9PRMimni.js";
import { c as de } from "./componentSetting-DVhNDBTO.js";
import { e as me, s as he } from "./vesselsCertificate-Hd_5oIk8.js";
import { I as ge } from "./helper-D9DF1oLX.js";
import { g as P } from "./equipmentMainLibrary-bJTzj5mC.js";
import { g as ve } from "./requisitionOrder-D0IG9N7e.js";
import { h as ye } from "./head-aneRfQQJ.js";
import { u as Ce } from "./useForm-CKmgcynv.js";
import { _ as be } from "./Flex-CTSf12gq.js";
let $e, Ve;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const { t: R } = E();
    function _e(i = "view") {
        switch(i){
            case "view":
                return R("vesselsCertificate.viewCertificateInfo");
            case "edit":
                return R("vesselsCertificate.editCertificateInfo");
            case "update":
                return R("vesselsCertificate.updateCertificateInfo");
            default:
                return "";
        }
    }
    function xe(i) {
        return i ? {
            ...i,
            category: i.hasOwnProperty("category") ? i.category + "" : void 0,
            certificateAttachmentEntities: i?.certificateAttachmentEntities?.length ? T(i.certificateAttachmentEntities, (o)=>({
                    name: o.fileName,
                    path: o.fileUrl,
                    url: o.longFileUrl,
                    status: "finished"
                })) : []
        } : {};
    }
    function Ne({ file: i, event: o, model: u, field: t, result: r }) {
        Array.isArray(u[t]) ? u[t].push({
            name: i.name,
            path: r.name,
            url: r.url,
            status: "finished"
        }) : u[t] = [
            {
                name: i.name,
                path: r.name,
                url: r.url,
                status: "finished"
            }
        ];
    }
    const { t: m } = E(), N = L(), O = await ve().then((i)=>T(i, (o)=>({
                label: o.shipName,
                labelEn: o.shipNameEn,
                value: o.id,
                raw: o
            }))), B = await P("certificate_category"), V = await P("ship_certificate_type"), Ee = await P("ship_certificate_status");
    Ve = function() {
        return [
            {
                field: "queryWarning",
                hidden: !0
            },
            {
                field: "shipId",
                component: "NSelect",
                label: m("vesselsCertificate.vessel"),
                defaultValue: ye(O)?.value,
                componentProps: {
                    placeholder: m("vesselsCertificate.vessel"),
                    labelField: N.getLocale === "en" ? "labelEn" : "label",
                    options: O
                }
            },
            {
                field: "category",
                component: "NSelect",
                label: m("vesselsCertificate.certificateCategory"),
                componentProps: {
                    placeholder: m("vesselsCertificate.certificateCategory"),
                    labelField: N.getLocale === "en" ? "labelEn" : "label",
                    options: B
                }
            },
            {
                field: "type",
                component: "NSelect",
                label: m("vesselsCertificate.certificateType"),
                componentProps: {
                    placeholder: m("vesselsCertificate.certificateType"),
                    labelField: N.getLocale === "en" ? "labelEn" : "label",
                    options: V
                }
            },
            {
                field: "status",
                component: "NSelect",
                label: m("vesselsCertificate.status"),
                componentProps: {
                    placeholder: m("vesselsCertificate.status"),
                    labelField: N.getLocale === "en" ? "labelEn" : "label",
                    options: Ee
                }
            }
        ];
    };
    const M = L(), { t: e } = E();
    function we() {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "certificateConfigId",
                hidden: !0
            },
            {
                field: "validity",
                hidden: !0
            },
            {
                field: "validityUnit",
                hidden: !0
            },
            {
                field: "status",
                hidden: !0
            },
            {
                field: "category",
                component: "NSelect",
                label: e("vesselsCertificate.certificateCategory"),
                componentProps: {
                    disabled: !0,
                    placeholder: e("vesselsCertificate.certificateCategory"),
                    labelField: M.getLocale === "en" ? "labelEn" : "label",
                    options: B
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.certificateCategoryRequired")
                    }
                ]
            },
            {
                field: "type",
                component: "NSelect",
                label: e("vesselsCertificate.certificateType"),
                componentProps: {
                    placeholder: e("vesselsCertificate.certificateType"),
                    labelField: M.getLocale === "en" ? "labelEn" : "label",
                    options: V
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.certificateTypeRequired")
                    }
                ]
            },
            {
                field: "certificateEnglishName",
                component: "NInput",
                label: e("vesselsCertificate.certificateNameEn"),
                componentProps: {
                    disabled: !0,
                    placeholder: e("vesselsCertificate.certificateNameEn")
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.certificateNameEnRequired")
                    }
                ]
            },
            {
                field: "certificateChineseName",
                component: "NInput",
                label: e("vesselsCertificate.certificateNameCn"),
                componentProps: {
                    disabled: !0,
                    placeholder: e("vesselsCertificate.certificateNameCn")
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.certificateNameCnRequired")
                    }
                ]
            },
            {
                field: "certificateNo",
                component: "NInput",
                label: e("vesselsCertificate.certificateNo"),
                componentProps: {
                    placeholder: e("vesselsCertificate.certificateNo")
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.certificateTypeNoRequired")
                    }
                ]
            },
            {
                field: "issueBy",
                component: "NInput",
                label: e("vesselsCertificate.authority"),
                componentProps: {
                    placeholder: e("vesselsCertificate.authority")
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.authorityRequired")
                    }
                ]
            },
            {
                field: "issueDate",
                component: "NDatePicker",
                label: e("vesselsCertificate.issueDate"),
                componentProps: ({ model: i, formAction: o })=>{
                    const { validity: u, validityUnit: t } = i, { setFieldsValue: r } = o;
                    return {
                        valueFormat: "yyyy-MM-dd",
                        placeholder: e("vesselsCertificate.issueDate"),
                        onUpdateValue: (_)=>{
                            if (u > 0 && t >= 0 && _) {
                                const v = te(_).add(u ?? 0, t === 0 ? "year" : "month").format("YYYY-MM-DD");
                                r({
                                    expireDate: v
                                });
                            } else r({
                                expireDate: null
                            });
                        }
                    };
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.issueDateRequired")
                    }
                ]
            },
            {
                field: "expireDate",
                component: "NDatePicker",
                label: e("vesselsCertificate.expireDate"),
                componentProps: {
                    valueFormat: "yyyy-MM-dd",
                    placeholder: e("vesselsCertificate.expireDate")
                }
            },
            {
                field: "lastEndorse",
                component: "NDatePicker",
                label: e("vesselsCertificate.lastEndorse"),
                componentProps: {
                    valueFormat: "yyyy-MM-dd",
                    placeholder: e("vesselsCertificate.lastEndorse")
                },
                rules: [
                    {
                        required: !0,
                        message: e("vesselsCertificate.lastEndorseRequired")
                    }
                ]
            },
            {
                field: "remark",
                component: "NInput",
                label: e("vesselsCertificate.remark"),
                giProps: {
                    span: 3
                },
                showFeedback: !1,
                componentProps: {
                    placeholder: e("vesselsCertificate.remark"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                }
            },
            {
                field: "configRemark",
                giProps: {
                    span: 3
                },
                showLabel: !1,
                slot: "tipsSlot"
            },
            {
                field: "certificateAttachmentEntities",
                label: e("vesselsCertificate.attachment"),
                giProps: {
                    span: 3
                },
                slot: "attachmentSlot"
            }
        ];
    }
    let Se;
    Se = {
        class: "text-[#F59C23]"
    };
    $e = se({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (i, { expose: o, emit: u }) {
            const { t } = E(), r = I(), _ = u, v = D(!1), g = D(!1), [$, { submit: U, setFieldsValue: j }] = Ce({
                schemas: we(),
                layout: "horizontal",
                gridProps: {
                    cols: 3
                }
            }), [Y, { setProps: z, openModal: G, closeModal: k, setSubLoading: w }] = ee({
                subBtuText: t("common.okText"),
                cancelText: t("common.cancelText"),
                width: 840
            });
            function K({ file: c, fileList: s, index: l }, y, f) {
                y[f].splice(l, 1);
            }
            function W({ file: c, event: s }, l, y) {
                try {
                    const f = fe("(" + s.target.response + ")"), { infoField: F } = de.upload.apiSetting, { code: p } = f, d = f.msg || f.message || t("common.uploadFailText"), C = f[F];
                    p === pe.SUCCESS ? Ne({
                        file: c,
                        event: s,
                        model: l,
                        field: y,
                        result: C
                    }) : I().error(d);
                } catch (f) {
                    console.error(f);
                }
            }
            function H(c) {
                console.warn("File upload error:", c), r.error(t("common.uploadFailText"));
            }
            async function S(c) {
                try {
                    const s = await U();
                    if (!s) {
                        g.value = !1, w(!1);
                        return;
                    }
                    g.value = !0, await me({
                        ...s,
                        certificateAttachmentEntities: T(s.certificateAttachmentEntities, (l)=>({
                                fileName: l.name,
                                fileUrl: l.path
                            }))
                    }), c === "sync" ? (await he({
                        idList: [
                            s.id
                        ],
                        configList: [
                            s.certificateConfigId
                        ]
                    }), r.success(t("common.syncSuccessText"))) : r.success(t("common.saveSuccessText")), g.value = !1, w(!1), _("refresh"), k();
                } catch  {
                    g.value = !1, w(!1);
                }
            }
            async function Z({ mode: c, record: s }) {
                v.value = c === "view", z({
                    title: _e(c)
                }), G(), await ue(), j(xe(s));
            }
            return o({
                handleOpenModal: Z
            }), (c, s)=>{
                const l = ae, y = ie, f = Q, F = be;
                return A(), q(a(X), {
                    onRegister: a(Y),
                    onOnOk: S,
                    showAction: !a(v)
                }, {
                    default: n(()=>[
                            h(f, {
                                onRegister: a($),
                                showActionButtonGroup: !1,
                                disabled: a(v)
                            }, {
                                tipsSlot: n(({ model: p, field: d })=>[
                                        ce("div", Se, "Tips: " + b(p[d]), 1)
                                    ]),
                                attachmentSlot: n(({ model: p, field: d })=>[
                                        (A(), q(y, {
                                            key: p[d]?.length,
                                            max: 3,
                                            accept: ".pdf,.jpg,.png",
                                            "default-file-list": p[d],
                                            headers: {
                                                timestamp: new Date().getTime(),
                                                authorization: `${a(re).get(a(le))}`
                                            },
                                            action: `${a(oe)().urlPrefix}${a(ge) ? "/system" : ""}/files`,
                                            onRemove: (C)=>K({
                                                    ...C
                                                }, p, d),
                                            onError: H,
                                            onFinish: ({ file: C, event: J })=>W({
                                                    file: C,
                                                    event: J
                                                }, p, d)
                                        }, {
                                            default: n(()=>[
                                                    h(l, {
                                                        class: "mt-[8px]"
                                                    }, {
                                                        icon: n(()=>[
                                                                h(a(ne))
                                                            ]),
                                                        default: n(()=>[
                                                                x(" " + b(a(t)("common.uploadText")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 2
                                        }, 1032, [
                                            "default-file-list",
                                            "headers",
                                            "action",
                                            "onRemove",
                                            "onFinish"
                                        ]))
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister",
                                "disabled"
                            ])
                        ]),
                    action: n(()=>[
                            h(F, {
                                class: "flex-1",
                                justify: "center"
                            }, {
                                default: n(()=>[
                                        h(l, {
                                            class: "w-24",
                                            style: {
                                                "--n-color": "#E4F4ED",
                                                "--n-text-color": "#6DA18A"
                                            },
                                            onClick: a(k)
                                        }, {
                                            default: n(()=>[
                                                    x(b(a(t)("common.cancelText")), 1)
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "onClick"
                                        ]),
                                        h(l, {
                                            class: "w-24",
                                            loading: a(g),
                                            type: "primary",
                                            onClick: s[0] || (s[0] = (p)=>S("save"))
                                        }, {
                                            default: n(()=>[
                                                    x(b(a(t)("common.saveText")), 1)
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "loading"
                                        ]),
                                        h(l, {
                                            class: "w-24",
                                            loading: a(g),
                                            type: "primary",
                                            onClick: s[1] || (s[1] = (p)=>S("sync"))
                                        }, {
                                            default: n(()=>[
                                                    x(b(a(t)("common.syncText")), 1)
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "loading"
                                        ])
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]);
            };
        }
    });
});
export { $e as _, Ve as c, __tla };
