import { r as _, V as A, Z as N, d as Se, u as be, aw as ye, a as Re, ay as q, ac as M, c as P, o as E, w as s, j as c, i as n, D as x, l as t, A as m, cS as we, aI as Pe, p as D, B as Ee, hK as Ne, aH as Ae, cO as Te, fm as Ce, cq as Oe, ds as Ie, hr as ke, N as Fe, i6 as Le, S as xe, ak as De, X as Ue, bR as Be, R as Ve, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as $ } from "./BasicForm-dL_oCSPM.js";
import { u as G } from "./useForm-CKmgcynv.js";
import { c as qe } from "./componentSetting-DVhNDBTO.js";
import { g as Me } from "./equipmentMainLibrary-bJTzj5mC.js";
import { u as $e } from "./useRole-C-Zpngq4.js";
import { _ as Ge } 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 ze } from "./useModal-CO65vga3.js";
import { B as He } from "./Table-0PViRYCf.js";
import { _ as We } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { d as je, p as Ke, a as Xe } from "./defectList-JLVZ8qtV.js";
let bt;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const { t: i } = A();
    function Ze() {
        const l = _(!1);
        return {
            formSchemas: [
                {
                    field: "captainSignUrl",
                    slot: "engineerSlot",
                    giProps: {
                        span: 12
                    }
                },
                {
                    field: "leaderSignUrl",
                    slot: "officerSlot",
                    giProps: {
                        span: 12
                    }
                },
                {
                    field: "asd",
                    slot: "topSlot",
                    giProps: {
                        span: 24
                    }
                },
                {
                    field: "informClass",
                    label: i("defectFormPage.review.classToBeInformed"),
                    component: "NRadioGroup",
                    labelPlacement: "left",
                    labelWidth: 150,
                    componentProps: {
                        disabled: !0,
                        options: [
                            {
                                label: i("common.yes"),
                                value: 1
                            },
                            {
                                label: i("common.no"),
                                value: 0
                            }
                        ]
                    },
                    giProps: {
                        span: 8
                    }
                },
                {
                    field: "flagToBeInformed",
                    label: i("defectFormPage.review.flagToBeInformed"),
                    component: "NRadioGroup",
                    labelPlacement: "left",
                    labelWidth: 141,
                    componentProps: {
                        disabled: !0,
                        options: [
                            {
                                label: i("common.yes"),
                                value: 1
                            },
                            {
                                label: i("common.no"),
                                value: 0
                            }
                        ]
                    },
                    giProps: {
                        span: 8
                    }
                },
                {
                    field: "serviceRequired",
                    label: i("defectFormPage.review.serviceRequired"),
                    component: "NRadioGroup",
                    labelPlacement: "left",
                    labelWidth: 145,
                    componentProps: {
                        disabled: !0,
                        options: [
                            {
                                label: i("common.yes"),
                                value: 1
                            },
                            {
                                label: i("common.no"),
                                value: 0
                            }
                        ]
                    },
                    giProps: {
                        span: 8
                    }
                },
                {
                    field: "reviewRemark",
                    label: i("defectFormPage.review.Remark"),
                    component: "NInput",
                    componentProps: {
                        type: "textarea",
                        disabled: !0
                    },
                    giProps: {
                        span: 24
                    }
                }
            ],
            methods: {
                updataReadOnly: (p)=>{
                    l.value = p;
                }
            }
        };
    }
    function Je() {
        const l = _(!1);
        return {
            schemas: [
                {
                    field: "file",
                    label: i("requisitionOrder.attachmentsTab.file"),
                    slot: "fileSlot",
                    rules: [
                        {
                            key: "file",
                            required: !0,
                            message: i("requisitionOrder.attachmentsTab.filePlaceholder"),
                            trigger: [
                                "change",
                                "blur"
                            ],
                            type: "object"
                        }
                    ]
                },
                {
                    field: "remark",
                    component: "NInput",
                    label: i("requisitionOrder.attachmentsTab.remark"),
                    componentProps: {
                        type: "textarea",
                        autosize: {
                            minRows: 3,
                            maxRows: 3
                        }
                    }
                }
            ],
            methods: {
                updataReadOnly: (p)=>{
                    l.value = p;
                }
            }
        };
    }
    const { t: z } = A(), Qe = [
        {
            title: z("requisitionOrder.attachmentsTab.fileName"),
            key: "attachName",
            width: 180,
            render: (l)=>l.attachUrl ? N("a", {
                    href: l.attachUrl,
                    target: "_blank"
                }, l.attachName) : l.attachName
        },
        {
            title: z("requisitionOrder.attachmentsTab.remark"),
            key: "remark",
            width: 180
        }
    ], { hasRole: H } = $e(), { t: W } = A(), U = {
        OFFICE: "office",
        VESSEL: "vessel"
    }, j = U.VESSEL, Ye = await Me("material_category"), R = {
        SPARES: "0",
        GENERAL_STORES: "1",
        MARINE_PAINT: "2",
        MARINE_CHEMICALS: "3",
        LUBRICANT: "5",
        TANK_CLEANING_CHEMICALS: "6",
        ROPE: "7",
        CHARTS_AND_PUBLICATIONS: "4",
        MEDICINE_AND_MEDICAL: "8",
        WIRE_ROPE: "9"
    };
    [
        R.SPARES,
        ...Ye.filter((l)=>Object.values(R).includes(l.value))
    ];
    j === U.OFFICE ? H([
        "technical_superintendent"
    ]) ? R.SPARES : H([
        "marine_superintendent"
    ]) && R.CHARTS_AND_PUBLICATIONS : R.SPARES;
    W("common.searchText"), W("common.portModal.port");
    let et, tt, at, ot, nt, st, it;
    et = {
        class: "h-[42px]",
        style: {
            "border-bottom": "1px solid #eee",
            width: "1400px"
        }
    };
    tt = {
        class: "h-[50px] mt-2"
    };
    at = {
        class: "h-[50px]"
    };
    ot = {
        class: "h-[42px]"
    };
    nt = {
        class: "h-[100px] mt-2"
    };
    st = {
        class: "mt-4"
    };
    it = {
        style: {
            "margin-bottom": "12px"
        }
    };
    bt = Se({
        __name: "index",
        props: {
            defectDetail: {},
            type: {},
            id: {},
            canEdit: {}
        },
        emits: [
            "changeAttachmentList"
        ],
        setup (l, { expose: T, emit: C }) {
            const p = be(), { formSchemas: K, methods: X } = Ze(), B = _(), { updataReadOnly: O } = X, { schemas: Z } = Je(), I = _([]), g = _([]), f = _([]), J = _("defect"), u = l, { t: o } = A();
            ye(()=>{
                u.type === "view" ? O(!0) : O(!1);
            });
            const [Q, Y] = G({
                gridProps: {
                    cols: 24
                },
                layout: "horizontal",
                schemas: K,
                showActionButtonGroup: !1
            }), { setFieldsValue: ee } = Y, te = C, [ae, { openModal: oe, closeModal: ne, setSubLoading: se }] = ze({
                width: 600,
                title: o("requisitionOrder.attachmentsTab.uploadAttachment")
            }), [ie, { submit: lt, setFieldsValue: k, getFieldsValue: le, validate: re }] = G({
                schemas: Z,
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 1,
                    xGap: 15
                },
                showActionButtonGroup: !1
            }), ce = Re({
                width: 100,
                title: o("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e) {
                    return N(We, {
                        style: "text",
                        actions: [
                            {
                                label: o("common.optionsEditText"),
                                labelShow: !1,
                                icon: N("i", {
                                    class: "iconfont icon-a-Frame28"
                                }),
                                onClick: ()=>V("report", e),
                                ifShow: ()=>u.canEdit !== "false" || u.type !== "view"
                            },
                            {
                                label: o("common.optionsDelText"),
                                labelShow: !1,
                                icon: N("i", {
                                    class: "iconfont icon-Delete red"
                                }),
                                onPositiveClick: async ()=>{
                                    await je(e.id), p.success(o("common.delPop.success")), f.value = f.value.filter((a)=>a.id !== e.id);
                                },
                                onNegativeClick: ()=>{},
                                isConfirm: !0,
                                confirmContent: o("requisitionOrder.delPop"),
                                ifShow: ()=>u.canEdit !== "false" || u.type !== "view"
                            }
                        ]
                    });
                }
            });
            q(()=>u.defectDetail, (e)=>{
                e && (+ee(e), f.value = e.reportAttachList || []);
            }, {
                immediate: !0
            }), q(()=>u.type, (e)=>{
                O(e === "view");
            }, {
                immediate: !0
            });
            function me({ file: e, event: a }, S, d) {
                try {
                    const r = Be("(" + a.target.response + ")"), { infoField: h } = qe.upload.apiSetting, { code: b } = r, F = r.msg || r.message || o("common.uploadFailText"), y = r[h];
                    b === Ve.SUCCESS ? (S[d] = {
                        name: e.name,
                        path: y.name,
                        url: y.url,
                        status: "finished"
                    }, I.value = y.name) : p.error(F);
                } catch (r) {
                    console.error(r);
                }
            }
            async function ue() {
                return await B.value?.validate(), B.value?.getFieldsValue();
            }
            function de() {
                g.value = [];
            }
            const v = _(null);
            async function V(e, a) {
                if (I.value = a?.attachPath ?? "", J.value = e, v.value = a?.id ?? null, g.value = [], oe(), await M(), await M(), typeof k != "function") {
                    console.warn("modal setFieldsValue not ready yet");
                    return;
                }
                a ? (k({
                    file: {
                        name: a.attachName,
                        path: a.attachPath,
                        url: a.attachUrl,
                        status: "finished"
                    },
                    remark: a.remark || ""
                }), g.value = [
                    {
                        name: a.attachName,
                        path: a.attachPath,
                        url: a.attachUrl,
                        status: "finished"
                    }
                ]) : k({
                    file: null,
                    remark: ""
                });
            }
            function pe(e) {
                console.warn("File upload error:", e), p.error(o("common.uploadFailText"));
            }
            async function fe() {
                try {
                    await re();
                    const { file: e, remark: a } = le();
                    let d = {
                        defectId: u.id,
                        attachName: e.name,
                        attachPath: e.path,
                        remark: a,
                        type: 2
                    };
                    if (v.value) {
                        const r = {
                            attachName: d.attachName,
                            attachPath: I.value,
                            remark: d.remark,
                            type: d.type
                        };
                        await Ke({
                            ...r,
                            id: v.value
                        }), f.value = f.value.map((h)=>h.id === v.value ? {
                                ...h,
                                ...d,
                                attachUrl: e.url,
                                id: v.value
                            } : h), p.success(o("common.editPop.success"));
                    } else {
                        const h = (await Xe(d))?.data?.id || Date.now(), b = {
                            ...d,
                            attachUrl: e.url,
                            id: h
                        };
                        f.value = [
                            ...f.value,
                            b
                        ], p.success(o("common.optionsSuccessText"));
                    }
                    te("changeAttachmentList", {
                        reportAttachList: f.value
                    }), ne();
                } catch (e) {
                    console.error("Error submitting attachment:", e);
                } finally{
                    se(!1);
                }
            }
            return T({
                getFormData: ue
            }), (e, a)=>{
                const S = we, d = Ee, r = Pe, h = Fe, b = xe, F = De, y = ke, he = Ae, _e = Ue;
                return E(), P(_e, null, {
                    default: s(()=>[
                            c(t($), {
                                onRegister: t(Q)
                            }, {
                                engineerSlot: s(()=>[
                                        n("div", null, [
                                            n("div", et, m(t(o)("pms.defectList.signatureVesselRepresentative")), 1),
                                            n("div", tt, [
                                                n("span", null, m(t(o)("pms.defectList.departmentHeadName")), 1),
                                                n("span", null, m(e.defectDetail ? e.defectDetail.leaderName : ""), 1)
                                            ]),
                                            n("div", at, [
                                                n("span", null, m(t(o)("pms.defectList.departmentHeadSignature")), 1),
                                                e.defectDetail?.leaderSignUrl ? (E(), P(S, {
                                                    key: 0,
                                                    width: "100",
                                                    height: "100",
                                                    src: e.defectDetail?.leaderSignUrl
                                                }, null, 8, [
                                                    "src"
                                                ])) : x("", !0)
                                            ])
                                        ])
                                    ]),
                                officerSlot: s(()=>[
                                        n("div", null, [
                                            n("div", ot, [
                                                n("span", null, m(t(o)("pms.defectList.captainsName")), 1),
                                                n("span", null, m(e.defectDetail ? e.defectDetail.captainName : ""), 1)
                                            ]),
                                            n("div", nt, [
                                                n("span", null, m(t(o)("pms.defectList.captainsSignature")), 1),
                                                e.defectDetail?.captainSignUrl ? (E(), P(S, {
                                                    key: 0,
                                                    width: "100",
                                                    height: "100",
                                                    src: e.defectDetail?.captainSignUrl
                                                }, null, 8, [
                                                    "src"
                                                ])) : x("", !0)
                                            ])
                                        ])
                                    ]),
                                topSlot: s(()=>a[2] || (a[2] = [
                                        n("div", {
                                            style: {
                                                "border-bottom": "1px solid #eee",
                                                width: "100%"
                                            }
                                        }, null, -1)
                                    ])),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ]),
                            n("div", st, m(t(o)("pms.defectList.voyageRepairReport")), 1),
                            u.canEdit !== "false" || u.type !== "view" ? (E(), P(r, {
                                key: 0,
                                trigger: "hover"
                            }, {
                                trigger: s(()=>[
                                        c(d, {
                                            quaternary: "",
                                            circle: "",
                                            onClick: a[0] || (a[0] = (w)=>V("report", null))
                                        }, {
                                            icon: s(()=>[
                                                    c(t(Ne))
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                default: s(()=>[
                                        D(" " + m(t(o)("requisitionOrder.attachmentsTab.uploadAttachment")), 1)
                                    ]),
                                _: 1
                            })) : x("", !0),
                            c(t(He), {
                                columns: t(Qe),
                                dataSource: t(f),
                                "row-key": (w)=>w.attachPath,
                                pagination: !1,
                                ref: "itemDetailsTableRef",
                                autoScrollX: !0,
                                "virtual-scroll": "",
                                showTableSetting: !1,
                                actionColumn: t(ce),
                                canResize: !1
                            }, null, 8, [
                                "columns",
                                "dataSource",
                                "row-key",
                                "actionColumn"
                            ]),
                            c(t(Ge), {
                                onRegister: t(ae),
                                onOnOk: fe
                            }, {
                                default: s(()=>[
                                        c(t($), {
                                            onRegister: t(ie),
                                            ref: "formRef"
                                        }, {
                                            fileSlot: s(({ model: w, field: ge })=>[
                                                    c(he, {
                                                        "directory-dnd": "",
                                                        "file-list": t(g),
                                                        "onUpdate:fileList": a[1] || (a[1] = (L)=>Ie(g) ? g.value = L : null),
                                                        accept: ".pdf,.jpg,.png",
                                                        action: `${t(Oe)().urlPrefix}${t(j) === t(U).OFFICE ? "/system" : ""}/files`,
                                                        headers: {
                                                            timestamp: new Date().getTime(),
                                                            authorization: `${t(Te).get(t(Ce))}`
                                                        },
                                                        max: 1,
                                                        onRemove: de,
                                                        onError: pe,
                                                        onFinish: ({ file: L, event: ve })=>me({
                                                                file: L,
                                                                event: ve
                                                            }, w, ge)
                                                    }, {
                                                        default: s(()=>[
                                                                c(y, null, {
                                                                    default: s(()=>[
                                                                            n("div", it, [
                                                                                c(h, {
                                                                                    size: "48",
                                                                                    depth: 3,
                                                                                    component: t(Le)
                                                                                }, null, 8, [
                                                                                    "component"
                                                                                ])
                                                                            ]),
                                                                            c(b, {
                                                                                style: {
                                                                                    "font-size": "16px"
                                                                                }
                                                                            }, {
                                                                                default: s(()=>[
                                                                                        D(m(t(o)("requisitionOrder.attachmentsTab.uploadBtn")), 1)
                                                                                    ]),
                                                                                _: 1
                                                                            }),
                                                                            c(F, {
                                                                                depth: "3",
                                                                                style: {
                                                                                    margin: "8px 0 0 0"
                                                                                }
                                                                            }, {
                                                                                default: s(()=>[
                                                                                        D(m(t(o)("requisitionOrder.attachmentsTab.uploadTips")), 1)
                                                                                    ]),
                                                                                _: 1
                                                                            })
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 2
                                                    }, 1032, [
                                                        "file-list",
                                                        "action",
                                                        "headers",
                                                        "onFinish"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { bt as _, __tla };
