import { V as T, r as d, Z as A, d as mt, u as pt, aw as dt, ay as D, a as ft, ac as ht, c as U, o as q, w as c, j as u, l as a, D as _t, aI as gt, p as w, A as L, B as vt, hK as yt, aH as St, cO as Et, fm as At, cq as Tt, ds as bt, hr as Nt, i as Rt, N as Ct, i6 as Ot, S as wt, ak as Lt, X as kt, bR as xt, R as It, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as Pt } from "./BasicForm-dL_oCSPM.js";
import { c as Ft } from "./componentSetting-DVhNDBTO.js";
import { g as Bt } from "./equipmentMainLibrary-bJTzj5mC.js";
import { u as Dt } from "./useRole-C-Zpngq4.js";
import { _ as Ut } 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 qt } from "./useModal-CO65vga3.js";
import { B as Mt } from "./Table-0PViRYCf.js";
import { _ as Vt } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { d as $t, p as jt, a as zt } from "./defectList-JLVZ8qtV.js";
import { u as Gt } from "./useForm-CKmgcynv.js";
let re;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const { hasRole: M } = Dt(), { t: V } = T(), x = {
        OFFICE: "office",
        VESSEL: "vessel"
    }, j = x.VESSEL, Ht = await Bt("material_category"), S = {
        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"
    };
    [
        S.SPARES,
        ...Ht.filter((r)=>Object.values(S).includes(r.value))
    ];
    j === x.OFFICE ? M([
        "technical_superintendent"
    ]) ? S.SPARES : M([
        "marine_superintendent"
    ]) && S.CHARTS_AND_PUBLICATIONS : S.SPARES;
    V("common.searchText"), V("common.portModal.port");
    const { t: k } = T();
    function Kt() {
        const r = d(!1);
        return {
            schemas: [
                {
                    field: "file",
                    label: k("requisitionOrder.attachmentsTab.file"),
                    slot: "fileSlot",
                    rules: [
                        {
                            key: "file",
                            required: !0,
                            message: k("requisitionOrder.attachmentsTab.filePlaceholder"),
                            trigger: [
                                "change",
                                "blur"
                            ],
                            type: "object"
                        }
                    ]
                },
                {
                    field: "remark",
                    component: "NInput",
                    label: k("requisitionOrder.attachmentsTab.remark"),
                    componentProps: {
                        type: "textarea",
                        autosize: {
                            minRows: 3,
                            maxRows: 3
                        }
                    }
                }
            ],
            methods: {
                updataReadOnly: (n)=>{
                    r.value = n;
                }
            }
        };
    }
    let $, Wt, Xt;
    ({ t: $ } = T());
    Wt = [
        {
            title: $("requisitionOrder.attachmentsTab.fileName"),
            key: "attachName",
            width: 180,
            render: (r)=>r.attachUrl ? A("a", {
                    href: r.attachUrl,
                    target: "_blank"
                }, r.attachName) : r.attachName
        },
        {
            title: $("requisitionOrder.attachmentsTab.remark"),
            key: "remark",
            width: 180
        }
    ];
    Xt = {
        style: {
            "margin-bottom": "12px"
        }
    };
    re = mt({
        __name: "index",
        props: {
            readOnly: {
                type: Boolean,
                default: !1
            },
            attachmentList: {
                type: Array,
                default: ()=>[]
            },
            defectDetail: {
                type: Object,
                default: ()=>({})
            },
            id: {
                type: Number,
                default: null
            },
            type: {
                type: String,
                default: "edit"
            },
            canEdit: {
                type: String,
                default: ""
            },
            activeTab: {
                type: String,
                default: ""
            }
        },
        emits: [
            "changeAttachmentList"
        ],
        setup (r, { expose: I, emit: P }) {
            const { t: n } = T(), v = pt(), b = d(), { schemas: z, methods: G } = Kt(), m = d([]), _ = d([]), { updataReadOnly: N } = G, p = d([]), s = r;
            dt(()=>{
                s.type === "view" ? N(!0) : N(!1);
            }), D(()=>s.defectDetail, (t)=>{
                m.value = t.defectAttachList || [], p.value = t.reportAttachList || [];
            }, {
                immediate: !0
            }), D(()=>s.type, (t)=>{
                N(t === "view");
            }, {
                immediate: !0
            });
            const H = P, [K, { openModal: W, closeModal: X, setSubLoading: Z }] = qt({
                width: 600,
                title: n("requisitionOrder.attachmentsTab.uploadAttachment")
            }), R = d([]), [J, { submit: Zt, setFieldsValue: Q, getFieldsValue: Y, validate: tt }] = Gt({
                schemas: z,
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 1,
                    xGap: 15
                },
                showActionButtonGroup: !1
            }), et = ft({
                width: 100,
                title: n("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (t) {
                    return A(Vt, {
                        style: "text",
                        actions: [
                            {
                                label: n("common.optionsEditText"),
                                labelShow: !1,
                                icon: A("i", {
                                    class: "iconfont icon-a-Frame28"
                                }),
                                onClick: ()=>B(t.type === 1 ? "defect" : "report", t),
                                ifShow: ()=>s.canEdit !== "false" || s.type !== "view"
                            },
                            {
                                label: n("common.optionsDelText"),
                                labelShow: !1,
                                icon: A("i", {
                                    class: "iconfont icon-Delete red"
                                }),
                                onPositiveClick: async ()=>{
                                    await $t(t.id), v.success(n("common.delPop.success")), t.type === 1 ? m.value = m.value.filter((e)=>e.id !== t.id) : p.value = p.value.filter((e)=>e.id !== t.id);
                                },
                                onNegativeClick: ()=>{},
                                isConfirm: !0,
                                confirmContent: n("requisitionOrder.delPop"),
                                ifShow: ()=>s.canEdit !== "false" || s.type !== "view"
                            }
                        ]
                    });
                }
            });
            async function at() {
                try {
                    await tt();
                    const { file: t, remark: e } = Y(), h = F.value === "defect" ? 1 : 2;
                    let i = {
                        defectId: s.id,
                        attachName: t.name,
                        attachPath: t.path,
                        remark: e,
                        type: h
                    };
                    if (f.value) {
                        const l = {
                            attachName: i.attachName,
                            attachPath: R.value,
                            remark: i.remark,
                            type: i.type
                        };
                        await jt({
                            ...l,
                            id: f.value
                        }), h === 1 ? m.value = m.value.map((o)=>o.id === f.value ? {
                                ...o,
                                ...i,
                                attachUrl: t.url,
                                id: f.value
                            } : o) : p.value = p.value.map((o)=>o.id === f.value ? {
                                ...o,
                                ...i,
                                attachUrl: t.url,
                                id: f.value
                            } : o), v.success(n("common.editPop.success"));
                    } else {
                        const o = (await zt(i))?.data?.id || Date.now(), g = {
                            ...i,
                            attachUrl: t.url,
                            id: o
                        };
                        h === 1 ? m.value = [
                            ...m.value,
                            g
                        ] : p.value = [
                            ...p.value,
                            g
                        ], v.success(n("common.optionsSuccessText"));
                    }
                    H("changeAttachmentList", {
                        defectAttachList: m.value,
                        reportAttachList: p.value
                    }), X();
                } catch (t) {
                    console.error("Error submitting attachment:", t);
                } finally{
                    Z(!1);
                }
            }
            function nt(t) {
                console.warn("File upload error:", t), v.error(n("common.uploadFailText"));
            }
            function ot({ file: t, event: e }, h, i) {
                try {
                    const l = xt("(" + e.target.response + ")"), { infoField: o } = Ft.upload.apiSetting, { code: g } = l, C = l.msg || l.message || n("common.uploadFailText"), y = l[o];
                    g === It.SUCCESS ? (h[i] = {
                        name: t.name,
                        path: y.name,
                        url: y.url,
                        status: "finished"
                    }, R.value = y.name) : v.error(C);
                } catch (l) {
                    console.error(l);
                }
            }
            function st() {
                _.value = [];
            }
            const F = d("defect"), f = d(null);
            function B(t, e) {
                R.value = e?.attachPath ?? "", F.value = t, f.value = e?.id ?? null, _.value = [], W(), ht(()=>{
                    e && (Q({
                        file: {
                            name: e.attachName,
                            path: e.attachPath,
                            url: e.attachUrl,
                            status: "finished"
                        },
                        remark: e.remark || ""
                    }), _.value = [
                        {
                            name: e.attachName,
                            path: e.attachPath,
                            url: e.attachUrl,
                            status: "finished"
                        }
                    ]);
                });
            }
            async function it() {
                return await b.value?.validate(), b.value?.getFieldsValue();
            }
            return I({
                getFormData: it
            }), (t, e)=>{
                const h = vt, i = gt, l = Ct, o = wt, g = Lt, C = Nt, y = St, lt = Pt, ct = kt;
                return q(), U(ct, null, {
                    default: c(()=>[
                            u(a(Mt), {
                                columns: a(Wt),
                                dataSource: a(m),
                                "row-key": (E)=>E.attachPath,
                                pagination: !1,
                                ref: "itemDetailsTableRef",
                                autoScrollX: !0,
                                "virtual-scroll": "",
                                actionColumn: a(et)
                            }, {
                                tableTitle: c(()=>[
                                        (s.canEdit !== "false" || s.type !== "view") && s.activeTab != "2" ? (q(), U(i, {
                                            key: 0,
                                            trigger: "hover"
                                        }, {
                                            trigger: c(()=>[
                                                    u(h, {
                                                        quaternary: "",
                                                        circle: "",
                                                        onClick: e[0] || (e[0] = (E)=>B("defect", null))
                                                    }, {
                                                        icon: c(()=>[
                                                                u(a(yt))
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            default: c(()=>[
                                                    w(" " + L(a(n)("requisitionOrder.attachmentsTab.uploadAttachment")), 1)
                                                ]),
                                            _: 1
                                        })) : _t("", !0)
                                    ]),
                                _: 1
                            }, 8, [
                                "columns",
                                "dataSource",
                                "row-key",
                                "actionColumn"
                            ]),
                            u(a(Ut), {
                                onRegister: a(K),
                                onOnOk: at
                            }, {
                                default: c(()=>[
                                        u(lt, {
                                            onRegister: a(J),
                                            ref_key: "formRef",
                                            ref: b
                                        }, {
                                            fileSlot: c(({ model: E, field: rt })=>[
                                                    u(y, {
                                                        "directory-dnd": "",
                                                        "file-list": a(_),
                                                        "onUpdate:fileList": e[1] || (e[1] = (O)=>bt(_) ? _.value = O : null),
                                                        accept: ".pdf,.jpg,.png",
                                                        action: `${a(Tt)().urlPrefix}${a(j) === a(x).OFFICE ? "/system" : ""}/files`,
                                                        headers: {
                                                            timestamp: new Date().getTime(),
                                                            authorization: `${a(Et).get(a(At))}`
                                                        },
                                                        max: 1,
                                                        onRemove: st,
                                                        onError: nt,
                                                        onFinish: ({ file: O, event: ut })=>ot({
                                                                file: O,
                                                                event: ut
                                                            }, E, rt)
                                                    }, {
                                                        default: c(()=>[
                                                                u(C, null, {
                                                                    default: c(()=>[
                                                                            Rt("div", Xt, [
                                                                                u(l, {
                                                                                    size: "48",
                                                                                    depth: 3,
                                                                                    component: a(Ot)
                                                                                }, null, 8, [
                                                                                    "component"
                                                                                ])
                                                                            ]),
                                                                            u(o, {
                                                                                style: {
                                                                                    "font-size": "16px"
                                                                                }
                                                                            }, {
                                                                                default: c(()=>[
                                                                                        w(L(a(n)("requisitionOrder.attachmentsTab.uploadBtn")), 1)
                                                                                    ]),
                                                                                _: 1
                                                                            }),
                                                                            u(g, {
                                                                                depth: "3",
                                                                                style: {
                                                                                    margin: "8px 0 0 0"
                                                                                }
                                                                            }, {
                                                                                default: c(()=>[
                                                                                        w(L(a(n)("requisitionOrder.attachmentsTab.uploadTips")), 1)
                                                                                    ]),
                                                                                _: 1
                                                                            })
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 2
                                                    }, 1032, [
                                                        "file-list",
                                                        "action",
                                                        "headers",
                                                        "onFinish"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { re as _, __tla };
