import { _ as q } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { B as P } from "./Table-0PViRYCf.js";
import { _ as A } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { g as h } from "./storageLocation-CpgPSQOH.js";
import { u as z, g as Z } from "./materialsStock-DZo3mecL.js";
import { g as N } from "./equipmentMainLibrary-bJTzj5mC.js";
import { g as $, b as j } from "./requisitionOrder-D0IG9N7e.js";
import { gI as f, bS as H, V as C, d as Q, bl as U, r as k, a as W, Z as d, hp as X, cZ as G, c as J, o as K, l as m, w as g, j as _, W as Y, __tla as __tla_0 } from "./index-9PRMimni.js";
import { s as ee } from "./some-vU4SVDLd.js";
import { u as te } from "./useModal-CO65vga3.js";
let w, Se, we, x, be, ye, he;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    he = await $().then((t)=>t.map((o)=>({
                label: o.shipName,
                labelEn: o.shipNameEn,
                value: o.id
            }))).catch((t)=>(console.error("Error fetching vessel options:", t), []));
    we = await N("material_category").then((t)=>f(t, (o)=>({
                ...o
            })) ?? []).catch((t)=>(console.error("Error fetching category options:", t), []));
    be = async function({ category: t, subCategory: o }) {
        try {
            return (await j({
                category: t,
                subCategory: o
            })).map((a)=>({
                    label: a.label,
                    labelEn: a.labelEn,
                    value: a.value
                }));
        } catch (r) {
            return console.error("Failed to fetch sub-category options:", r), [];
        }
    };
    ye = await N("rob_condition");
    w = {
        OFFICE: "office",
        VESSEL: "vessel"
    };
    x = w.VESSEL;
    function oe({ fields: t, record: o }) {
        return ee(t, (r)=>!!(H(o, r) ?? !1));
    }
    let n, ae;
    ({ t: n } = C());
    ae = ({ storageLocationOptions: t })=>[
            {
                title: "No.",
                key: "num",
                width: 60,
                render: (o, r)=>r + 1
            },
            {
                title: n("materialsStock.itemCode"),
                key: "itemCode",
                width: 100
            },
            {
                title: n("materialsStock.itemDescription"),
                key: "description",
                width: 140
            },
            {
                title: n("materialsStock.specification"),
                key: "specification",
                width: 120
            },
            {
                title: n("materialsStock.price"),
                ifShow: x === w.OFFICE,
                key: "unitPrice",
                width: 100
            },
            {
                title: n("materialsStock.uom"),
                key: "uom",
                width: 80
            },
            {
                title: n("materialsStock.quantity"),
                key: "quantity",
                width: 90
            },
            {
                title: n("materialsStock.brand"),
                key: "brandManufacturer",
                width: 160
            },
            {
                title: n("materialsStock.storageLocationRoomNo"),
                key: "roomNo",
                width: 240,
                edit: !0,
                editRow: !0,
                editComponent: "NSelect",
                editComponentProps: {
                    style: {
                        width: "220px"
                    },
                    clearable: !0,
                    options: t.roomNo
                }
            },
            {
                title: n("materialsStock.storageLocationShelfNo"),
                key: "shelfNo",
                width: 240,
                edit: !0,
                editRow: !0,
                editRule: (o, r)=>{
                    const a = oe({
                        fields: [
                            "roomNo",
                            "shelfNo",
                            "boxNo"
                        ],
                        record: r.editValueRefs
                    }) ? "" : n("materialsStock.storageLocationRequired");
                    return Promise.resolve(a);
                },
                editComponent: "NSelect",
                editComponentProps: {
                    style: {
                        width: "220px"
                    },
                    clearable: !0,
                    options: t.shelfNo
                }
            },
            {
                title: n("materialsStock.storageLocationBoxNo"),
                key: "boxNo",
                width: 240,
                edit: !0,
                editRow: !0,
                editComponent: "NSelect",
                editComponentProps: {
                    style: {
                        width: "220px"
                    },
                    clearable: !0,
                    options: t.boxNo
                }
            },
            {
                title: n("materialsStock.frozenStock"),
                key: "freezeQuantity",
                width: 120
            }
        ];
    Se = Q({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (t, { expose: o, emit: r }) {
            const { t: a } = C(), E = G(), b = U("tableRef"), p = k({}), y = k({
                roomNo: [],
                shelfNo: [],
                boxNo: []
            }), [v, { openModal: R, closeModal: T }] = te({
                title: a("materialsStock.stockDetails"),
                subBtuText: a("common.saveText"),
                width: 1750
            }), L = W({
                width: 80,
                title: a("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e) {
                    return d(A, {
                        style: "text",
                        actions: O(e)
                    });
                }
            });
            function O(e) {
                return e.editable ? [
                    {
                        label: a("common.saveText"),
                        labelShow: !1,
                        icon: d("i", {
                            class: "iconfont icon-Save"
                        }),
                        onClick: I.bind(null, e)
                    },
                    {
                        label: a("common.cancelText"),
                        labelShow: !1,
                        icon: d(X),
                        onClick: D.bind(null, e)
                    }
                ] : [
                    {
                        label: a("common.optionsEditText"),
                        labelShow: !1,
                        icon: d("i", {
                            class: "iconfont icon-a-Frame28"
                        }),
                        onClick: B.bind(null, e)
                    }
                ];
            }
            async function B(e) {
                const { shipId: c } = p.value;
                if (!c) {
                    console.error("Ship ID is required to fetch storage locations");
                    return;
                }
                await S(c), e.onEdit?.(!0);
            }
            async function I(e) {
                if (await e.onEdit?.(!1, !0)) try {
                    const { id: l, roomNo: u, shelfNo: i, boxNo: s } = e;
                    await z({
                        id: l,
                        roomNo: u,
                        shelfNo: i,
                        boxNo: s
                    }), E.success(a("common.optionsEditSuccessText")), b.value?.restReload();
                } catch (l) {
                    console.error("Edit failed:", l);
                }
            }
            function D(e) {
                e.onEdit?.(!1, !1);
            }
            async function F(e) {
                await S(e.shipId), p.value = e, R();
            }
            async function M() {
                T();
            }
            async function S(e) {
                const c = await h({
                    shipId: e,
                    warehouseType: "0"
                }).then((i)=>f(i.list, (s)=>({
                            label: s.warehouseName,
                            value: s.id,
                            raw: s
                        })) ?? []).catch(()=>[]), l = await h({
                    shipId: e,
                    warehouseType: "1"
                }).then((i)=>f(i.list, (s)=>({
                            label: s.warehouseName,
                            value: s.id,
                            raw: s
                        })) ?? []).catch(()=>[]), u = await h({
                    shipId: e,
                    warehouseType: "2"
                }).then((i)=>f(i.list, (s)=>({
                            label: s.warehouseName,
                            value: s.id,
                            raw: s
                        })) ?? []).catch(()=>[]);
                y.value = {
                    roomNo: c,
                    shelfNo: l,
                    boxNo: u
                };
            }
            async function V(e) {
                const { shipId: c, materialId: l } = p.value;
                try {
                    return await Z({
                        ...e,
                        shipId: c,
                        materialId: l
                    });
                } catch (u) {
                    return console.error("Failed to load data table:", u), {
                        list: [],
                        total: 0
                    };
                }
            }
            return o({
                handleOpenModal: F
            }), (e, c)=>{
                const l = Y, u = q;
                return K(), J(u, {
                    ref: "modalRef",
                    onRegister: m(v),
                    onOnOk: M,
                    showAction: !1
                }, {
                    default: g(()=>[
                            _(l, {
                                bordered: !1,
                                class: "proCard mt-2",
                                "content-class": "p-0"
                            }, {
                                default: g(()=>[
                                        _(m(P), {
                                            ref_key: "tableRef",
                                            ref: b,
                                            columns: m(ae)({
                                                storageLocationOptions: m(y)
                                            }),
                                            request: (i)=>V(i),
                                            "row-key": (i)=>i.id,
                                            actionColumn: m(x) === m(w).VESSEL ? m(L) : void 0,
                                            showTableSetting: !1,
                                            autoScrollX: !0,
                                            "virtual-scroll": ""
                                        }, null, 8, [
                                            "columns",
                                            "request",
                                            "row-key",
                                            "actionColumn"
                                        ])
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { w as C, Se as _, we as a, x as c, be as f, ye as r, he as v, __tla };
