import { V as S, Z as U, bk as oe, gI as te, d as ae, u as ie, r as q, bl as ne, a4 as se, aw as ce, c as E, o as L, X as le, w as m, j as f, W as de, l as c, H as ue, D as pe, aI as me, p as he, A as ye, B as fe, i as be, bU as ge, __tla as __tla_0 } from "./index-9PRMimni.js";
import { _ as qe } 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 Oe } from "./useModal-CO65vga3.js";
import { B as Ce } from "./BasicForm-dL_oCSPM.js";
import { u as _e } from "./useForm-CKmgcynv.js";
import { B as Me } from "./Table-0PViRYCf.js";
import { a as Ne, b as Se, c as v, d as Te } from "./requisitionOrder-D0IG9N7e.js";
import { g as b, a, b as Pe, __tla as __tla_1 } from "./helper-CNwA55dE.js";
import { g as we } from "./equipmentMainLibrary-bJTzj5mC.js";
import { i as M } from "./isNumber-D5aBrEhN.js";
import { i as Ae } from "./includes-DdMWPj0t.js";
import { f as Re } from "./find-D_h_aJYR.js";
import { s as Ie } from "./some-vU4SVDLd.js";
import { s as B } from "./startsWith-JzGQtvao.js";
let Ze, Le;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    const { t: i } = S();
    function ke(t) {
        const e = b(t?.procurementCategory ?? "");
        switch(e){
            case a.SPARE_PARTS:
                return [
                    {
                        type: "selection",
                        key: "selection",
                        multiple: !1,
                        width: 60
                    },
                    {
                        title: i("requisitionOrder.searchModal.equipmentCode"),
                        key: "productCode",
                        width: 140
                    },
                    {
                        title: i("requisitionOrder.searchModal.equipmentName"),
                        key: "productName",
                        width: 180
                    },
                    {
                        title: i("requisitionOrder.searchModal.partNumber"),
                        key: "partNumber",
                        width: 120
                    },
                    {
                        title: i("requisitionOrder.searchModal.itemDescription"),
                        key: "itemDescription",
                        width: 180
                    },
                    {
                        title: i("requisitionOrder.searchModal.plateDrawingNumber"),
                        key: "plateDrawingNumber",
                        width: 180
                    },
                    {
                        title: i("requisitionOrder.searchModal.critical"),
                        key: "critical",
                        width: 100,
                        render: (n)=>n.critical ? i("common.yes") : i("common.no")
                    },
                    {
                        title: i("requisitionOrder.searchModal.drawing"),
                        key: "drawing",
                        width: 200,
                        render: (n)=>U("a", {
                                href: n.drawingUrl,
                                target: "_blank"
                            }, n.drawing?.split("/").pop())
                    }
                ];
            case a.MATERIALS:
                return [
                    {
                        type: "selection",
                        key: "selection",
                        multiple: !1,
                        width: 60
                    },
                    {
                        title: i("requisitionOrder.searchModal.itemCode"),
                        key: "code",
                        width: 120
                    },
                    {
                        title: i("requisitionOrder.searchModal.itemDescription"),
                        key: "description"
                    },
                    {
                        title: i("requisitionOrder.searchModal.brand"),
                        key: "brand",
                        width: 120
                    },
                    {
                        title: i("requisitionOrder.searchModal.specification"),
                        key: "specification",
                        width: 140
                    },
                    {
                        title: i("requisitionOrder.searchModal.uom"),
                        key: "unitName",
                        width: 120
                    }
                ];
            case a.CHARTS_AND_PUBLICATIONS:
                return [
                    {
                        type: "selection",
                        key: "selection",
                        multiple: !1,
                        width: 60
                    },
                    {
                        title: i("requisitionOrder.searchModal.itemCode"),
                        key: "code",
                        width: 120
                    },
                    {
                        title: i("requisitionOrder.searchModal.itemDescription"),
                        key: "description"
                    },
                    {
                        title: i("requisitionOrder.searchModal.specification"),
                        key: "specification",
                        width: 140
                    },
                    {
                        title: i("requisitionOrder.searchModal.uom"),
                        key: "unitName",
                        width: 120
                    },
                    {
                        title: i("requisitionOrder.searchModal.brand"),
                        key: "brand",
                        width: 120
                    }
                ];
            default:
                return console.warn(`No schemas defined for procurement type: ${e}`), [];
        }
    }
    const N = oe(), { t: o } = S();
    async function V({ shipId: t, code: e = "0", model: n = "0", serialNumber: s = "0" }) {
        try {
            return (await Ne({
                shipId: t,
                code: e,
                model: n,
                serialNumber: s
            })).map((r)=>({
                    label: r.name,
                    value: r.code,
                    isLeaf: r.ifLeaf,
                    raw: r
                }));
        } catch (g) {
            return console.error("Failed to fetch code prefix options:", g), [];
        }
    }
    async function w({ category: t, subCategory: e }) {
        try {
            return (await Se({
                category: t,
                subCategory: e
            })).map((s)=>({
                    label: s.label,
                    labelEn: s.labelEn,
                    value: s.value
                }));
        } catch (n) {
            return console.error("Failed to fetch sub-category options:", n), [];
        }
    }
    await we("material_category").then((t)=>te(t, (e)=>({
                ...e
            })) ?? []).catch((t)=>(console.error("Error fetching category options:", t), []));
    const De = ({ props: t, codePrefixOptions: e, subCategoryOptions: n, sectionOptions: s })=>{
        switch(b(t?.procurementCategory ?? "")){
            case a.SPARE_PARTS:
                return [
                    {
                        field: "productCode",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.equipmentCode"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.equipmentCode")
                        }
                    },
                    {
                        field: "productName",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.equipmentName"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.equipmentName")
                        }
                    },
                    {
                        field: "partNumber",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.partNumber"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.partNumber")
                        }
                    },
                    {
                        field: "itemDescription",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.itemDescription"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.itemDescription")
                        }
                    },
                    {
                        field: "productCodePrefix",
                        component: "NCascader",
                        label: o("requisitionOrder.searchModal.equipmentType"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.equipmentType"),
                            checkStrategy: "parent",
                            showPath: !1,
                            allowCheckingNotLoaded: !0,
                            options: e,
                            remote: !0,
                            renderLabel: (r)=>U("span", {
                                    title: r.label
                                }, r.label),
                            onLoad: async (r)=>{
                                r.children = await V({
                                    shipId: t.vesselValue,
                                    code: r.raw.code,
                                    model: r.raw.model,
                                    serialNumber: r.raw.serialNumber
                                });
                            }
                        }
                    }
                ];
            case a.MATERIALS:
                return [
                    {
                        field: "category",
                        hidden: !0,
                        defaultValue: t?.procurementCategory
                    },
                    {
                        field: "subCategory",
                        component: "NSelect",
                        label: o("requisitionOrder.searchModal.categorySubType"),
                        componentProps: ({ model: r })=>({
                                labelField: N.getLocale === "en" ? "labelEn" : "label",
                                placeholder: o("requisitionOrder.searchModal.categorySubType"),
                                options: n.value,
                                onUpdateValue: async (y)=>{
                                    r.section = null, s.value = y ? await w({
                                        category: t.procurementCategory,
                                        subCategory: y
                                    }) : [];
                                }
                            })
                    },
                    {
                        field: "section",
                        component: "NSelect",
                        label: o("requisitionOrder.searchModal.section"),
                        componentProps: {
                            labelField: N.getLocale === "en" ? "labelEn" : "label",
                            placeholder: o("requisitionOrder.searchModal.section"),
                            options: s
                        }
                    },
                    {
                        field: "description",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.itemDescription"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.itemDescription")
                        }
                    },
                    {
                        field: "brand",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.brand"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.brand")
                        }
                    },
                    {
                        field: "code",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.itemCode"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.itemCode")
                        }
                    }
                ];
            case a.CHARTS_AND_PUBLICATIONS:
                return [
                    {
                        field: "category",
                        hidden: !0,
                        defaultValue: t?.procurementCategory
                    },
                    {
                        field: "subCategory",
                        component: "NSelect",
                        label: o("requisitionOrder.searchModal.categorySubType"),
                        componentProps: ({ model: r })=>({
                                labelField: N.getLocale === "en" ? "labelEn" : "label",
                                placeholder: o("requisitionOrder.searchModal.categorySubType"),
                                options: n.value,
                                onUpdateValue: async (y)=>{
                                    r.section = null, s.value = y ? await w({
                                        category: t.procurementCategory,
                                        subCategory: y
                                    }) : [];
                                }
                            })
                    },
                    {
                        field: "section",
                        component: "NSelect",
                        label: o("requisitionOrder.searchModal.section"),
                        componentProps: {
                            labelField: N.getLocale === "en" ? "labelEn" : "label",
                            placeholder: o("requisitionOrder.searchModal.section"),
                            options: s
                        }
                    },
                    {
                        field: "code",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.itemCode"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.itemCode")
                        }
                    },
                    {
                        field: "description",
                        component: "NInput",
                        label: o("requisitionOrder.searchModal.itemDescription"),
                        componentProps: {
                            placeholder: o("requisitionOrder.searchModal.itemDescription")
                        }
                    }
                ];
            default:
                return [];
        }
    }, { t: h } = S();
    function Ee({ props: t, selected: e }) {
        if (!e) return {};
        const n = b(t.procurementCategory);
        if (!n) return console.warn("Invalid procurement category:", t.procurementCategory), {};
        switch(n){
            case a.SPARE_PARTS:
                return {
                    itemId: e.itemId,
                    itemCode: e.itemCode,
                    partNumber: e.partNumber,
                    plateDrawingNumber: e.plateDrawingNumber,
                    equipmentName: e.productName,
                    equipmentModel: e.model,
                    serialNo: e.serialNumber,
                    maker: e.maker,
                    equipmentType: e.productType,
                    hullNo: e.hullNo,
                    itemDescription: e.itemDescription,
                    specification: e.itemSpecification,
                    reqQuantity: e.reqQuantity ?? null,
                    reqQuality: e.reqQuality ?? null,
                    rob: e.ROB,
                    umo: M(e.uom) ? e.uom + "" : e.uom,
                    sdocRequired: e.sDocRequired,
                    mdRequired: e.mdRequired,
                    remarkToOffice: "",
                    remarkToVendor: "",
                    attachPath: null
                };
            case a.MATERIALS:
                return {
                    itemId: e.id,
                    itemCode: e.code,
                    issaNo: e.issaNo,
                    itemCategory: e.category,
                    itemDescription: e.description,
                    specification: e.specification,
                    reqQuantity: e.reqQuantity,
                    rob: e.rob,
                    umo: M(e.unit) ? e.unit + "" : e.unit,
                    ...t.procurementCategory !== Pe.GENERAL_STORES && {
                        brand: e.brand
                    },
                    packingUmo: M(e.packingUmo) ? e.packingUmo + "" : e.packingUmo,
                    sdocRequired: e.sdocRequired,
                    mdRequired: e.mdRequired,
                    remarksToOffice: "",
                    remarksToVendor: "",
                    attachPath: null
                };
            case a.CHARTS_AND_PUBLICATIONS:
                return {
                    itemId: e.id,
                    itemCode: e.code,
                    issaNo: e.issaNo,
                    itemCategory: e.category,
                    itemDescription: e.description,
                    specification: e.specification,
                    reqQuantity: e.reqQuantity,
                    reqEdition: e.edition,
                    rob: e.rob,
                    edition: e.edition,
                    umo: M(e.unit) ? e.unit + "" : e.unit,
                    remarkToOffice: "",
                    remarkToVendor: "",
                    attachPath: null
                };
            default:
                return console.warn("Unsupported procurement type:", n), {};
        }
    }
    Le = function(t) {
        const e = b(t);
        return e ? {
            modalName: e === a.SPARE_PARTS ? h("requisitionOrder.addModal.sparePartsDetail") : e === a.MATERIALS ? h("requisitionOrder.addModal.materialsDetail") : e === a.CHARTS_AND_PUBLICATIONS ? h("requisitionOrder.addModal.chartsAndPublicationsDetail") : "",
            searchBtnName: e === a.SPARE_PARTS ? h("requisitionOrder.addModal.sparePartsSearch") : e === a.MATERIALS ? h("requisitionOrder.addModal.materialsSearch") : e === a.CHARTS_AND_PUBLICATIONS ? h("requisitionOrder.addModal.chartsAndPublicationsSearch") : "",
            searchModalName: e === a.SPARE_PARTS ? h("requisitionOrder.addModal.sparePartsSearch") : e === a.MATERIALS ? h("requisitionOrder.addModal.materialsSearch") : e === a.CHARTS_AND_PUBLICATIONS ? h("requisitionOrder.addModal.chartsAndPublicationsSearch") : ""
        } : (console.warn("Invalid procurement category:", t), {});
    };
    Ze = ae({
        __name: "index",
        props: {
            vesselValue: {},
            procurementCategory: {}
        },
        emits: [
            "selected"
        ],
        setup (t, { expose: e, emit: n }) {
            const { t: s } = S(), g = ie(), r = t, y = n, A = q([]), T = q([]), x = q([]), R = q(!1), F = ne("tableRef"), H = se(()=>ke({
                    procurementCategory: r.procurementCategory
                })), [Q, { openModal: $, closeModal: W, setSubLoading: I }] = Oe({
                width: 1100,
                title: Le(r.procurementCategory)?.searchModalName
            }), [j, { getFieldsValue: k, setFieldsValue: ve }] = _e({
                gridProps: {
                    cols: 4
                },
                schemas: De({
                    props: r,
                    codePrefixOptions: A,
                    subCategoryOptions: T,
                    sectionOptions: x
                })
            });
            function X(p) {
                const { subCategory: l } = p;
                if (l) {
                    const d = [
                        "IMPA"
                    ], { label: u, labelEn: O } = Re(c(T), {
                        value: l
                    });
                    R.value = Ie(d, (C)=>B(u, C) || B(O, C));
                }
            }
            async function z(p, l) {
                const d = b(r.procurementCategory);
                if (!d) return console.warn("Invalid procurement type:", r.procurementCategory), Promise.resolve({
                    list: [],
                    total: 0
                });
                const u = {
                    [a.SPARE_PARTS]: Te,
                    [a.MATERIALS]: v,
                    [a.CHARTS_AND_PUBLICATIONS]: v
                }[d];
                return await u?.({
                    ...p,
                    ...l,
                    shipId: r.vesselValue
                }) ?? {
                    list: [],
                    total: 0
                };
            }
            const P = q({});
            function G(p, l, { row: d }) {
                P.value = d;
            }
            async function K() {
                if (Object.keys(P.value).length === 0) {
                    g.warning(s("common.pleaseSelectOneRow")), I(!1);
                    return;
                }
                W(), I(!1), y("selected", Ee({
                    props: r,
                    selected: ge(P.value)
                }));
            }
            function Y() {
                $();
            }
            function Z() {
                const { category: p, subCategory: l, section: d } = k(), u = new URLSearchParams;
                u.append("type", "add"), u.append("shipId", r.vesselValue), u.append("category", p), l && u.append("subCategory", l), d && u.append("section", d), window.open(`/pms/material/add?${u.toString()}`, "_blank");
            }
            function D() {
                F.value?.restReload();
            }
            async function J() {
                const p = await V({
                    shipId: r.vesselValue
                });
                A.value = p ?? [];
            }
            async function ee() {
                if (b(r.procurementCategory) === a.SPARE_PARTS) return;
                const l = await w({
                    category: r.procurementCategory
                });
                T.value = l ?? [];
            }
            return ce(()=>{
                J(), ee();
            }), e({
                handleOpenSearchModal: Y
            }), (p, l)=>{
                const d = de, u = fe, O = me, C = ue, re = le;
                return L(), E(re, null, {
                    default: m(()=>[
                            f(c(qe), {
                                onRegister: c(Q),
                                onOnOk: K,
                                subBtuText: c(s)("common.confirmText")
                            }, {
                                default: m(()=>[
                                        f(d, {
                                            bordered: !1,
                                            class: "proCard",
                                            "content-class": "p-0"
                                        }, {
                                            default: m(()=>[
                                                    f(c(Ce), {
                                                        onRegister: c(j),
                                                        onSubmit: D,
                                                        onReset: D,
                                                        onChange: X
                                                    }, null, 8, [
                                                        "onRegister"
                                                    ])
                                                ]),
                                            _: 1
                                        }),
                                        f(d, {
                                            bordered: !1,
                                            class: "proCard",
                                            "content-class": "px-0"
                                        }, {
                                            default: m(()=>[
                                                    f(c(Me), {
                                                        columns: H.value,
                                                        request: (_)=>z(_, c(k)()),
                                                        "row-key": (_)=>_.itemId ?? _.id,
                                                        ref: "tableRef",
                                                        "onUpdate:checkedRowKeys": G,
                                                        autoScrollX: !0,
                                                        "virtual-scroll": "",
                                                        showTableSetting: !1
                                                    }, {
                                                        toolbar: m(()=>[
                                                                f(C, null, {
                                                                    default: m(()=>[
                                                                            c(Ae)([
                                                                                c(a).MATERIALS,
                                                                                c(a).CHARTS_AND_PUBLICATIONS
                                                                            ], c(b)(r.procurementCategory)) ? (L(), E(O, {
                                                                                key: 0,
                                                                                trigger: "hover"
                                                                            }, {
                                                                                trigger: m(()=>[
                                                                                        f(u, {
                                                                                            type: "primary",
                                                                                            strong: "",
                                                                                            bordered: "",
                                                                                            secondary: "",
                                                                                            class: "size-8",
                                                                                            onClick: Z,
                                                                                            disabled: c(R)
                                                                                        }, {
                                                                                            icon: m(()=>l[0] || (l[0] = [
                                                                                                    be("i", {
                                                                                                        class: "iconfont icon-ADD"
                                                                                                    }, null, -1)
                                                                                                ])),
                                                                                            _: 1
                                                                                        }, 8, [
                                                                                            "disabled"
                                                                                        ])
                                                                                    ]),
                                                                                default: m(()=>[
                                                                                        he(" " + ye(c(s)("requisitionOrder.detailsTab.add")), 1)
                                                                                    ]),
                                                                                _: 1
                                                                            })) : pe("", !0)
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 1
                                                    }, 8, [
                                                        "columns",
                                                        "request",
                                                        "row-key"
                                                    ])
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister",
                                "subBtuText"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { Ze as _, Le as g, __tla };
