import { V as H, bk as ne, gI as z, d as le, f as se, a4 as ue, r as P, bl as ce, c as E, o as R, l as o, w as u, j as I, D as V, B as pe, p as x, A as Q, fU as me, H as he, aH as qe, cO as fe, fm as be, cq as Oe, cZ as f, bR as ge, R as Me, ac as ye, __tla as __tla_0 } from "./index-9PRMimni.js";
import { c as Ne } from "./componentSetting-DVhNDBTO.js";
import { _ as Pe } 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 { B as Re } from "./BasicForm-dL_oCSPM.js";
import { u as Ie } from "./useForm-CKmgcynv.js";
import { e as G, f as Se, h as Ce } from "./requisitionOrder-D0IG9N7e.js";
import { g as $, a as h, c as U, e as c, C as p, b as i, f as Te, P as S, __tla as __tla_1 } from "./helper-CNwA55dE.js";
import { i as w } from "./includes-DdMWPj0t.js";
import { g as D, _ as _e, __tla as __tla_2 } from "./index.vue_vue_type_script_setup_true_lang-Cv5LP8XJ.js";
let ze;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_2;
        } catch  {}
    })()
]).then(async ()=>{
    const { t: e } = H(), v = ne(), Ae = await G({
        category: 2
    }).then((a)=>z(a, (t)=>({
                label: t.name,
                labelEn: t.name,
                value: t.id + ""
            }))).catch((a)=>(console.error("Failed to fetch packing UOM options:", a), [])), k = await G({
        category: 1
    }).then((a)=>z(a, (t)=>({
                label: t.name,
                labelEn: t.name,
                value: t.id + ""
            }))).catch((a)=>(console.error("Failed to fetch UOM options:", a), []));
    function ve(a) {
        const t = $(a?.procurementCategory ?? "");
        switch(t){
            case h.SPARE_PARTS:
                return [
                    {
                        field: "partNumber",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.partNumber"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "plateDrawingNumber",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.plateDrawingNumber"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "equipmentName",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.equipmentName"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "equipmentModel",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.equipmentModel"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "serialNo",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.serialNo"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "maker",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.maker"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "equipmentType",
                        component: "NSelect",
                        label: e("requisitionOrder.addModal.equipmentType"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "hullNo",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.hullNo"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "itemDescription",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.itemDescription"),
                        giProps: {
                            span: 4
                        },
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "specification",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.specification"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.specification")
                        }
                    },
                    {
                        field: "umo",
                        component: "NSelect",
                        label: e("requisitionOrder.addModal.uom"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.uom"),
                            labelField: v.getLocale === "en" ? "labelEn" : "label",
                            options: k
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.uomRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    {
                        field: "sdocRequired",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.sdocRequired"),
                        componentProps: {
                            disabled: c !== p.OFFICE,
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.sdocRequired"),
                            options: [
                                {
                                    label: "是",
                                    labelEn: "YES",
                                    value: 1
                                },
                                {
                                    label: "否",
                                    labelEn: "NO",
                                    value: 0
                                }
                            ]
                        }
                    },
                    {
                        field: "mdRequired",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.mdRequired"),
                        componentProps: {
                            disabled: c !== p.OFFICE,
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.mdRequired"),
                            options: [
                                {
                                    label: "是",
                                    labelEn: "YES",
                                    value: 1
                                },
                                {
                                    label: "否",
                                    labelEn: "NO",
                                    value: 0
                                }
                            ]
                        }
                    },
                    {
                        field: "rob",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.rob"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "reqQuantity",
                        component: "NInputNumber",
                        label: e("requisitionOrder.addModal.requiredQty"),
                        componentProps: {
                            min: 1,
                            precision: 0,
                            placeholder: e("requisitionOrder.addModal.requiredQty")
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.requiredQtyRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ],
                                type: "number"
                            }
                        ]
                    },
                    {
                        field: "reqQuality",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.requiredQuality"),
                        componentProps: {
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.requiredQuality"),
                            options: Te
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.requiredQualityRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    {
                        field: "remarkToOffice",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToOffice"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToOffice"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "remarkToVendor",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToVendor"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToVendor"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "attachPath",
                        label: e("requisitionOrder.addModal.attachment"),
                        giProps: {
                            span: 2
                        },
                        slot: "attachmentSlot"
                    }
                ];
            case h.MATERIALS:
                return [
                    {
                        field: "itemCode",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.itemCode"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "issaNo",
                        hidden: !0
                    },
                    {
                        field: "itemCategory",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.itemCategory"),
                        componentProps: {
                            disabled: !0,
                            style: {
                                width: "100%"
                            },
                            placeholder: "",
                            options: U
                        }
                    },
                    {
                        field: "itemDescription",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.itemDescription"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "rob",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.rob"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "umo",
                        component: "NSelect",
                        label: e("requisitionOrder.addModal.uom"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.uom"),
                            labelField: v.getLocale === "en" ? "labelEn" : "label",
                            options: k
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.uomRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    {
                        field: "sdocRequired",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.sdocRequired"),
                        componentProps: {
                            disabled: c !== p.OFFICE,
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.sdocRequired"),
                            options: [
                                {
                                    label: "是",
                                    labelEn: "YES",
                                    value: 1
                                },
                                {
                                    label: "否",
                                    labelEn: "NO",
                                    value: 0
                                }
                            ]
                        }
                    },
                    {
                        field: "mdRequired",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.mdRequired"),
                        componentProps: {
                            disabled: c !== p.OFFICE,
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.mdRequired"),
                            options: [
                                {
                                    label: "是",
                                    labelEn: "YES",
                                    value: 1
                                },
                                {
                                    label: "否",
                                    labelEn: "NO",
                                    value: 0
                                }
                            ]
                        }
                    },
                    {
                        field: "specification",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.specification"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.specification")
                        },
                        rules: [
                            {
                                required: w([
                                    i.MARINE_PAINT,
                                    i.MARINE_CHEMICALS,
                                    i.LUBRICANT,
                                    i.TANK_CLEANING_CHEMICALS
                                ], a?.procurementCategory),
                                message: e("requisitionOrder.addModal.specificationRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    ...a?.procurementCategory !== i.GENERAL_STORES ? [
                        {
                            field: "brand",
                            component: "NInput",
                            label: e("requisitionOrder.addModal.brandManufacturer"),
                            componentProps: {
                                placeholder: e("requisitionOrder.addModal.brandManufacturer")
                            },
                            rules: [
                                {
                                    required: w([
                                        i.MARINE_PAINT,
                                        i.MARINE_CHEMICALS,
                                        i.LUBRICANT,
                                        i.TANK_CLEANING_CHEMICALS
                                    ], a?.procurementCategory),
                                    message: e("requisitionOrder.addModal.brandManufacturerRequired"),
                                    trigger: [
                                        "change",
                                        "blur"
                                    ]
                                }
                            ]
                        }
                    ] : [],
                    {
                        field: "reqQuantity",
                        component: "NInputNumber",
                        label: e("requisitionOrder.addModal.requiredQty"),
                        componentProps: {
                            min: .01,
                            precision: 2,
                            placeholder: e("requisitionOrder.addModal.requiredQty")
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.requiredQtyRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ],
                                type: "number"
                            }
                        ]
                    },
                    {
                        field: "packingUmo",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.packingUom"),
                        componentProps: {
                            style: {
                                width: "100%"
                            },
                            placeholder: e("requisitionOrder.addModal.packingUom"),
                            options: Ae
                        }
                    },
                    {
                        field: "remarkToOffice",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToOffice"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToOffice"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "remarkToVendor",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToVendor"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToVendor"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "attachPath",
                        label: e("requisitionOrder.addModal.attachment"),
                        giProps: {
                            span: 2
                        },
                        slot: "attachmentSlot"
                    }
                ];
            case h.CHARTS_AND_PUBLICATIONS:
                return [
                    {
                        field: "itemCategory",
                        component: "BasicSelect",
                        label: e("requisitionOrder.addModal.itemCategory"),
                        componentProps: {
                            disabled: !0,
                            style: {
                                width: "100%"
                            },
                            placeholder: "",
                            options: U
                        }
                    },
                    {
                        field: "itemCode",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.itemCode"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "issaNo",
                        hidden: !0
                    },
                    {
                        field: "itemDescription",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.itemDescription"),
                        giProps: {
                            span: 3
                        },
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "specification",
                        hidden: !0
                    },
                    {
                        field: "umo",
                        component: "NSelect",
                        label: e("requisitionOrder.addModal.uom"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.uom"),
                            labelField: v.getLocale === "en" ? "labelEn" : "label",
                            options: k
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.uomRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    {
                        field: "rob",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.rob"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "edition",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.editionOnBoard"),
                        componentProps: {
                            disabled: !0,
                            placeholder: ""
                        }
                    },
                    {
                        field: "reqQuantity",
                        component: "NInputNumber",
                        label: e("requisitionOrder.addModal.requiredQty"),
                        componentProps: {
                            min: 1,
                            precision: 0,
                            placeholder: e("requisitionOrder.addModal.requiredQty")
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.requiredQtyRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ],
                                type: "number"
                            }
                        ]
                    },
                    {
                        field: "reqEdition",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.requiredEdition"),
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.requiredEdition")
                        },
                        rules: [
                            {
                                required: !0,
                                message: e("requisitionOrder.addModal.requiredEditionRequired"),
                                trigger: [
                                    "change",
                                    "blur"
                                ]
                            }
                        ]
                    },
                    {
                        field: "remarkToOffice",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToOffice"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToOffice"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "remarkToVendor",
                        component: "NInput",
                        label: e("requisitionOrder.addModal.remarksToVendor"),
                        giProps: {
                            span: 2
                        },
                        componentProps: {
                            placeholder: e("requisitionOrder.addModal.remarksToVendor"),
                            type: "textarea",
                            autosize: {
                                minRows: 3,
                                maxRows: 3
                            }
                        }
                    },
                    {
                        field: "attachPath",
                        label: e("requisitionOrder.addModal.attachment"),
                        giProps: {
                            span: 2
                        },
                        slot: "attachmentSlot"
                    }
                ];
            default:
                return console.warn(`No schemas defined for procurement type: ${t}`), [];
        }
    }
    ze = le({
        __name: "index",
        props: {
            isEdit: {
                type: Boolean
            },
            vesselValue: {},
            procurementCategory: {},
            reqFormOtherInfo: {}
        },
        emits: [
            "refresh",
            "changeKeyWordsDisabled"
        ],
        setup (a, { expose: t, emit: K }) {
            const { t: m } = H(), d = a, C = K, Y = se(), j = ue(()=>Y.query.type ?? S.CREATE), b = P(null), q = P(null), O = P(null), F = P(!1), [W, { openModal: Z, closeModal: B, setSubLoading: L }] = Ee({
                width: 1200,
                title: D(d.procurementCategory)?.modalName
            }), [J, { setFieldsValue: T, getFieldsValue: X, validate: ee }] = Ie({
                schemas: ve(d),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: d.procurementCategory === i.CHARTS_AND_PUBLICATIONS ? 5 : 4,
                    xGap: 15
                },
                showActionButtonGroup: !1
            });
            async function re() {
                if (!q.value && !F.value) {
                    f().warning(m("requisitionOrder.addModal.noSelectionText")), L(!1);
                    return;
                }
                ee().then(()=>{
                    const r = X();
                    q.value ? Se({
                        id: q.value,
                        ...r,
                        approveQuantity: c === p.OFFICE ? r.reqQuantity : 0,
                        attachPath: r.attachPath?.path
                    }).then((g)=>{
                        f().success(m("requisitionOrder.addModal.editSuccess")), C("refresh"), B();
                    }) : Ce({
                        reqId: d.reqFormOtherInfo.id,
                        itemId: b.value,
                        shipId: +d.vesselValue,
                        category: d.procurementCategory,
                        itemCode: O.value,
                        ...r,
                        approveQuantity: c === p.OFFICE ? r.reqQuantity : 0,
                        attachPath: r.attachPath?.path
                    }).then((g)=>{
                        f().success(m("requisitionOrder.addModal.addSuccess")), C("refresh"), C("changeKeyWordsDisabled", !0), B();
                    });
                }).finally(()=>{
                    L(!1);
                });
            }
            const _ = ce("searchRef");
            function oe() {
                const r = $(d.procurementCategory);
                if (!r) {
                    console.warn("Invalid procurement category:", d.procurementCategory);
                    return;
                }
                if (r === h.SPARE_PARTS) {
                    _.value?.handleOpenSearchModal();
                    return;
                }
                if (r === h.MATERIALS) {
                    _.value?.handleOpenSearchModal();
                    return;
                }
                if (r === h.CHARTS_AND_PUBLICATIONS) {
                    _.value?.handleOpenSearchModal();
                    return;
                }
            }
            function ae({ file: r, event: g }, M, A) {
                try {
                    const n = ge("(" + g.target.response + ")"), { infoField: l } = Ne.upload.apiSetting, { code: s } = n, y = n.msg || n.message || m("common.uploadFailText"), N = n[l];
                    s === Me.SUCCESS ? M[A] = {
                        name: r.name,
                        path: N.name,
                        url: N.url,
                        status: "finished"
                    } : f().error(y);
                } catch (n) {
                    console.error(n);
                }
            }
            function te(r) {
                console.warn("File upload error:", r), f().error(m("common.uploadFailText"));
            }
            function ie(r) {
                b.value = r.itemId, O.value = r.itemCode, T(r), F.value = !0;
            }
            function de(r = {}) {
                Z(), ye(()=>{
                    Object.keys(r).length > 0 ? (b.value = null, O.value = null, q.value = r.id, T(r)) : (b.value = null, O.value = null, q.value = null, T({}));
                });
            }
            return t({
                handleOpenModal: de
            }), (r, g)=>{
                const M = pe, A = he, n = qe;
                return R(), E(o(Pe), {
                    onRegister: o(W),
                    onOnOk: re
                }, {
                    default: u(()=>[
                            I(A, {
                                class: "mb-3",
                                justify: "end"
                            }, {
                                default: u(()=>[
                                        o(w)([
                                            o(S).CREATE,
                                            o(S).CREATED,
                                            o(S).EDIT
                                        ], o(j)) && r.isEdit !== !0 ? (R(), E(M, {
                                            key: 0,
                                            type: "primary",
                                            ghost: "",
                                            onClick: oe
                                        }, {
                                            icon: u(()=>[
                                                    I(o(me))
                                                ]),
                                            default: u(()=>[
                                                    x(" " + Q(o(D)(r.procurementCategory)?.searchBtnName), 1)
                                                ]),
                                            _: 1
                                        })) : V("", !0)
                                    ]),
                                _: 1
                            }),
                            I(o(Re), {
                                onRegister: o(J)
                            }, {
                                attachmentSlot: u(({ model: l, field: s })=>[
                                        (R(), E(n, {
                                            key: l[s] ? l[s].url : "",
                                            "default-file-list": l[s] ? [
                                                l[s]
                                            ] : [],
                                            accept: ".pdf,.jpg,.png",
                                            action: `${o(Oe)().urlPrefix}${o(c) === o(p).OFFICE ? "/system" : ""}/files`,
                                            headers: {
                                                timestamp: new Date().getTime(),
                                                authorization: `${o(fe).get(o(be))}`
                                            },
                                            max: 1,
                                            onRemove: (y)=>l[s] = null,
                                            onError: te,
                                            onFinish: ({ file: y, event: N })=>ae({
                                                    file: y,
                                                    event: N
                                                }, l, s)
                                        }, {
                                            default: u(()=>[
                                                    I(M, null, {
                                                        default: u(()=>[
                                                                x(Q(o(m)("common.uploadText")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 2
                                        }, 1032, [
                                            "default-file-list",
                                            "action",
                                            "headers",
                                            "onRemove",
                                            "onFinish"
                                        ]))
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ]),
                            r.isEdit ? V("", !0) : (R(), E(_e, {
                                key: 0,
                                ref: "searchRef",
                                vesselValue: r.vesselValue,
                                procurementCategory: r.procurementCategory,
                                onSelected: ie
                            }, null, 8, [
                                "vesselValue",
                                "procurementCategory"
                            ]))
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { ze as _, __tla };
