import { _ as xe } 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 Me } from "./BasicForm-dL_oCSPM.js";
import { B as Te } from "./Table-0PViRYCf.js";
import { _ as Ie } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { V as Z, l as n, r as c, a as le, bi as K, bk as X, gI as w, bS as P, gL as Pe, d as Be, b as De, Z as L, hp as qe, c as Oe, o as ee, w as g, j as h, W as Ee, aI as Fe, p as $, A as z, B as Ve, i as Ae, h as Ge, D as $e, N as ze, iy as Ue, cs as je, ac as oe, cZ as We, __tla as __tla_0 } from "./index-9PRMimni.js";
import { i as He } from "./materialsStock-DZo3mecL.js";
import { g as U } from "./storageLocation-CpgPSQOH.js";
import { a as Ze, h as Ke, g as Xe } from "./material-Fe1jAspV.js";
import { g as Je } from "./requisitionListPage-CxtdksCl.js";
import { f as te } from "./find-D_h_aJYR.js";
import { s as Qe } from "./some-vU4SVDLd.js";
import { u as Ye } from "./useModal-CO65vga3.js";
import { u as eo } from "./useForm-CKmgcynv.js";
import { h as j } from "./head-aneRfQQJ.js";
import { i as oo } from "./isEmpty-BUg1OsQj.js";
import { p as to } from "./pick-Cg3anC-c.js";
let Io;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const W = X(), { t: u } = Z(), ae = c(!1), x = c(!1), R = c([]);
    async function ao(o) {
        if (!o) {
            R.value = [];
            return;
        }
        try {
            await Je({
                reqNo: o,
                isMaterial: !0,
                pageNum: 1,
                pageSize: -1
            }).then((a)=>{
                const { list: i } = a, e = w(i, (s)=>({
                        label: s.reqNo,
                        value: s.reqNo,
                        raw: s
                    }));
                R.value = e;
            });
        } catch (a) {
            console.error("Failed to fetch purchase order options:", a), R.value = [];
        }
    }
    const no = K((o)=>{
        ao(o);
    }, 500), q = c(!1), M = c(!1), B = c([]), ne = c(!1), T = c(!1), D = c([]), y = le({
        category: [],
        subCategory: [],
        section: []
    });
    y.category = await Xe();
    const ie = async (o, { label: a, value: i } = {
        label: "label",
        value: "value"
    })=>{
        if (!o.code && !o.description) return [];
        try {
            return q.value = !0, await Ke({
                ...o,
                pageNum: 1,
                pageSize: -1
            }).then((s)=>{
                const { list: l } = s;
                return w(l, (m)=>({
                        label: m[a],
                        value: m[i],
                        raw: m
                    })) ?? [];
            }) ?? [];
        } catch (e) {
            return console.error("Failed to fetch item code options:", e), [];
        } finally{
            q.value = !1;
        }
    }, so = K((o)=>ie(o, {
            label: "code",
            value: "code"
        }).then((a)=>{
            B.value = a;
        }), 500), lo = K((o)=>ie(o, {
            label: "description",
            value: "description"
        }).then((a)=>{
            D.value = a;
        }), 500);
    async function I({ category: o, subCategory: a }) {
        if (!o && !a) return [];
        try {
            return (await Ze({
                category: o,
                subCategory: a
            })).map((e)=>({
                    label: e.label,
                    labelEn: e.labelEn,
                    value: e.value
                }));
        } catch (i) {
            return console.error("Failed to fetch sub-category options:", i), [];
        }
    }
    function io(o = {}) {
        return [
            {
                field: "materialId",
                hidden: !0
            },
            {
                field: "shipId",
                hidden: !0
            },
            {
                field: "itemCode",
                label: u("materialsStock.inStockModal.itemCode"),
                component: "NSelect",
                componentProps: ({ model: a, formAction: i })=>({
                        show: M,
                        remote: !0,
                        clearable: !0,
                        filterable: !0,
                        loading: n(q),
                        options: n(B),
                        placeholder: u("common.inputTextToSearch"),
                        onClear: ()=>{
                            B.value = [];
                        },
                        onBlur: ()=>{
                            q.value = !1;
                        },
                        onSearch: async (e)=>{
                            e.length > 0 ? M.value = !0 : M.value = !1, so({
                                code: e
                            });
                        },
                        onUpdateValue: async (e)=>{
                            const { setFieldsValue: s } = i, l = te(n(B), {
                                value: e
                            }), { description: b, category: m, subCategory: p, section: _, id: S } = l?.raw ?? {};
                            if (s({
                                description: b ?? null,
                                category: m ?? null,
                                subCategory: p ?? null,
                                sectionCode: _ ?? null,
                                materialId: S ?? null
                            }), M.value = !1, l?.raw?.category) {
                                const { category: f } = l.raw;
                                I({
                                    category: f
                                }).then((k)=>{
                                    y.subCategory = k;
                                });
                            }
                            if (l?.raw?.subCategory) {
                                const { category: f, subCategory: k } = l.raw;
                                I({
                                    category: f,
                                    subCategory: k
                                }).then((N)=>{
                                    y.section = N;
                                });
                            }
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: u("materialsStock.inStockModal.itemCodeRequired"),
                        trigger: "blur"
                    }
                ]
            },
            {
                field: "description",
                label: u("materialsStock.inStockModal.itemDescription"),
                component: "NSelect",
                componentProps: ({ formAction: a })=>({
                        show: T,
                        remote: !0,
                        clearable: !0,
                        filterable: !0,
                        loading: n(ne),
                        options: n(D),
                        placeholder: u("common.inputTextToSearch"),
                        onClear: ()=>{
                            D.value = [];
                        },
                        onBlur: ()=>{
                            ne.value = !1;
                        },
                        onSearch: async (i)=>{
                            i.length > 0 ? T.value = !0 : T.value = !1, lo({
                                description: i
                            });
                        },
                        onUpdateValue: async (i)=>{
                            const { setFieldsValue: e } = a, s = te(n(D), {
                                value: i
                            }), { code: l, category: b, subCategory: m, section: p, id: _ } = s?.raw ?? {};
                            if (e({
                                itemCode: l ?? null,
                                category: b ?? null,
                                subCategory: m ?? null,
                                sectionCode: p ?? null,
                                materialId: _ ?? null
                            }), T.value = !1, s?.raw?.category) {
                                const { category: S } = s.raw;
                                I({
                                    category: S
                                }).then((f)=>{
                                    y.subCategory = f;
                                });
                            }
                            if (s?.raw?.subCategory) {
                                const { category: S, subCategory: f } = s.raw;
                                I({
                                    category: S,
                                    subCategory: f
                                }).then((k)=>{
                                    y.section = k;
                                });
                            }
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: u("materialsStock.inStockModal.itemDescriptionRequired"),
                        trigger: "blur"
                    }
                ]
            },
            {
                field: "category",
                label: u("materialsStock.inStockModal.category"),
                component: "NSelect",
                componentProps: ()=>({
                        disabled: !0,
                        placeholder: u("materialsStock.inStockModal.category"),
                        labelField: W.getLocale === "en" ? "labelEn" : "label",
                        options: y.category
                    })
            },
            {
                field: "subCategory",
                label: u("materialsStock.inStockModal.subCategory"),
                component: "NSelect",
                componentProps: ()=>({
                        disabled: !0,
                        placeholder: u("materialsStock.inStockModal.subCategory"),
                        labelField: W.getLocale === "en" ? "labelEn" : "label",
                        options: y.subCategory
                    })
            },
            {
                field: "sectionCode",
                label: u("materialsStock.inStockModal.section"),
                component: "NSelect",
                componentProps: ()=>({
                        disabled: !0,
                        placeholder: u("materialsStock.inStockModal.section"),
                        labelField: W.getLocale === "en" ? "labelEn" : "label",
                        options: y.section
                    })
            },
            {
                field: "poNo",
                label: u("materialsStock.inStockModal.purchaseRequisition"),
                component: "NSelect",
                componentProps: ()=>({
                        show: x,
                        remote: !0,
                        clearable: !0,
                        filterable: !0,
                        loading: n(ae),
                        options: n(R),
                        placeholder: u("common.inputTextToSearch"),
                        onClear: ()=>{
                            R.value = [];
                        },
                        onBlur: ()=>{
                            ae.value = !1;
                        },
                        onSearch: async (a)=>{
                            a.length > 0 ? x.value = !0 : x.value = !1, no(a);
                        },
                        onUpdateValue: async (a)=>{
                            x.value = !1;
                        }
                    })
            },
            {
                field: "remarks",
                label: u("materialsStock.inStockModal.remarks"),
                component: "NInput",
                giProps: {
                    span: 4
                },
                componentProps: {
                    type: "textarea",
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    },
                    showCount: !0,
                    maxlength: 600,
                    placeholder: u("materialsStock.inStockModal.remarks")
                },
                rules: [
                    {
                        required: !0,
                        message: u("materialsStock.inStockModal.remarksRequired"),
                        trigger: "blur"
                    }
                ]
            }
        ];
    }
    const H = X();
    function ro(o) {
        return {
            materialId: o.materialId,
            shipId: o.shipId,
            category: H.getLocale === "en" ? o.categoryLabelEn : o.categoryLabel,
            subCategory: H.getLocale === "en" ? o.subLabelEn : o.subLabel,
            sectionCode: H.getLocale === "en" ? o.sectionLabelEn : o.sectionLabel,
            itemCode: o.itemCode,
            description: o.description
        };
    }
    function co({ fields: o, record: a }) {
        return Qe(o, (i)=>!!(P(a, i) ?? !1));
    }
    const { t: d } = Z(), se = X(), uo = await Pe("storage_type"), re = uo.filter((o)=>![
            "4",
            "7",
            "8"
        ].includes(o.value));
    function po({ storageLocationRoom: o, storageLocationShelf: a, storageLocationBox: i, isFirstInbound: e }) {
        return [
            {
                title: "No.",
                key: "num",
                width: 60,
                render: (s, l)=>l + 1
            },
            {
                title: d("materialsStock.inStockModal.inboundType"),
                key: "inboundType",
                width: 200,
                editComponent: "NSelect",
                editComponentProps: {
                    placeholder: d(""),
                    options: re,
                    class: "w-[180px]",
                    labelField: se.getLocale === "en" ? "labelEn" : "label"
                },
                editRule: (s)=>{
                    const l = s ? "" : d("materialsStock.inStockModal.inboundTypeRequired");
                    return Promise.resolve(l);
                },
                editRow: !0,
                edit: !0,
                render: (s)=>se.getLocale === "en" ? s.labelEn : s.label
            },
            {
                title: d("materialsStock.inStockModal.quantity"),
                key: "quantity",
                width: 140,
                editComponent: "NInputNumber",
                editComponentProps: {
                    placeholder: d(""),
                    min: .01,
                    precision: 2
                },
                editRow: !0,
                editRule: (s)=>{
                    const l = s ? "" : d("materialsStock.inStockModal.quantityRequired");
                    return Promise.resolve(l);
                },
                edit: !0
            },
            {
                title: d("materialsStock.inStockModal.storageLocationRoom"),
                key: "roomNo",
                width: 200,
                editComponent: "NInput",
                editComponentProps: {
                    placeholder: d("")
                },
                ...!e && {
                    editComponent: "NSelect",
                    editComponentProps: {
                        placeholder: d(""),
                        clearable: !0,
                        options: o,
                        class: "w-[190px]"
                    }
                },
                editRow: !0,
                edit: !0
            },
            {
                title: d("materialsStock.inStockModal.storageLocationShelf"),
                key: "shelfNo",
                width: 200,
                editComponent: "NInput",
                editComponentProps: {
                    placeholder: d("")
                },
                ...!e && {
                    editComponent: "NSelect",
                    editComponentProps: {
                        placeholder: d(""),
                        clearable: !0,
                        options: a,
                        class: "w-[190px]"
                    },
                    editRule: (s, l)=>{
                        const b = co({
                            fields: [
                                "roomNo",
                                "shelfNo",
                                "boxNo"
                            ],
                            record: l.editValueRefs
                        }) ? "" : d("GRNList.detailPage.storageLocationRequired");
                        return Promise.resolve(b);
                    }
                },
                editRow: !0,
                edit: !0
            },
            {
                title: d("sparePartsStock.storageLocationBox"),
                key: "boxNo",
                width: 200,
                editComponent: "NInput",
                editComponentProps: {
                    placeholder: d("")
                },
                ...!e && {
                    editComponent: "NSelect",
                    editComponentProps: {
                        placeholder: d(""),
                        clearable: !0,
                        options: i,
                        class: "w-[190px]"
                    }
                },
                editRow: !0,
                edit: !0
            }
        ];
    }
    let mo;
    mo = {
        key: 0,
        class: "text-red-600 ml-4"
    };
    Io = Be({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (o, { expose: a, emit: i }) {
            const { t: e } = Z(), l = De().getShipList, b = We(), m = c(), p = c(), _ = i, [S, { openModal: f, closeModal: k, setSubLoading: N }] = Ye({
                title: e("materialsStock.inStockModal.title"),
                subBtuText: e("common.saveText"),
                width: 1400
            }), [ce, { setFieldsValue: J, validate: ue, getFieldsValue: de }] = eo({
                gridProps: {
                    cols: 4
                },
                schemas: io(),
                showAdvancedButton: !1
            }), pe = le({
                width: 100,
                title: e("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (t) {
                    return L(Ie, {
                        style: "text",
                        actions: me(t)
                    });
                }
            });
            function me(t) {
                return t.editable ? [
                    {
                        label: e("common.saveText"),
                        labelShow: !1,
                        icon: L("i", {
                            class: "iconfont icon-Save"
                        }),
                        onClick: be.bind(null, t)
                    },
                    {
                        label: e("common.cancelText"),
                        labelShow: !1,
                        icon: L(qe),
                        onClick: ge.bind(null, t)
                    }
                ] : [
                    {
                        label: e("common.optionsEditText"),
                        labelShow: !1,
                        icon: L("i", {
                            class: "iconfont icon-a-Frame28"
                        }),
                        onClick: fe.bind(null, t)
                    },
                    {
                        label: e("common.optionsDelText"),
                        labelShow: !1,
                        icon: L("i", {
                            class: "iconfont icon-Delete red"
                        }),
                        onPositiveClick: async ()=>{
                            v.value = v.value.filter((r)=>r.id !== t.id);
                        },
                        onNegativeClick: ()=>{},
                        isConfirm: !0,
                        confirmContent: e("common.delPop.cont")
                    }
                ];
            }
            const Q = c("");
            function fe(t) {
                Q.value = t.id, t.onEdit(!0);
            }
            function ge(t) {
                Q.value = "", t.onEdit?.(!1, !1);
            }
            async function be(t) {
                await t.onEdit(!1, !0) && (p.value = "", O.value = !1);
            }
            function he() {
                v.value.push({
                    id: je("inboundDetail_"),
                    inboundType: P(j(re), "value", ""),
                    quantity: 1,
                    roomNo: "",
                    shelfNo: "",
                    boxNo: ""
                }), O.value = !0;
            }
            const O = c(), C = c(P(j(l), "id"));
            async function ye(t) {
                f(), p.value = "", v.value = [], Ce(), t ? oe(()=>{
                    C.value = t.shipId, J(ro(t));
                }) : oe(()=>{
                    C.value = P(j(l), "id"), J({
                        shipId: n(C)
                    });
                });
            }
            async function Se() {
                try {
                    if (await ue(), oo(v.value)) return p.value = e("materialsStock.inStockModal.inboundDetailsRequired"), N(!1), Promise.reject(e("materialsStock.inStockModal.inboundDetailsRequired"));
                    if (O.value) return p.value = e("materialsStock.inStockModal.inboundDetailsRequired"), N(!1), Promise.reject(e("materialsStock.inStockModal.inboundDetailsRequired"));
                    const r = {
                        ...de(),
                        details: w(v.value, (G)=>to(G, [
                                "inboundType",
                                "quantity",
                                "roomNo",
                                "shelfNo",
                                "boxNo"
                            ]))
                    };
                    await He(r), b.success(e("common.optionsSuccessText")), _("refresh"), k();
                } catch (t) {
                    console.error(t), N(!1);
                }
            }
            const v = c([]), E = c(), F = c(), V = c();
            async function ke() {
                try {
                    await U({
                        shipId: C.value,
                        warehouseType: "0"
                    }).then((t)=>{
                        E.value = w(t.list, (r)=>({
                                label: r.warehouseName,
                                value: r.id,
                                item: r
                            }));
                    }), await U({
                        shipId: C.value,
                        warehouseType: "1"
                    }).then((t)=>{
                        F.value = w(t.list, (r)=>({
                                label: r.warehouseName,
                                value: r.id,
                                item: r
                            }));
                    }), await U({
                        shipId: C.value,
                        warehouseType: "2"
                    }).then((t)=>{
                        V.value = w(t.list, (r)=>({
                                label: r.warehouseName,
                                value: r.id,
                                item: r
                            }));
                    });
                } catch (t) {
                    console.error(t);
                }
            }
            const A = c();
            async function ve() {
                if (E.value.length === 0 && F.value.length === 0 && V.value.length === 0) {
                    A.value = !0;
                    return;
                }
                A.value = !1;
            }
            async function Ce() {
                await ke(), await ve();
            }
            return a({
                handleOpenModal: ye
            }), (t, r)=>{
                const G = Me, Y = Ee, we = ze, _e = Ve, Ne = Fe, Le = xe;
                return ee(), Oe(Le, {
                    ref: "modalRef",
                    onRegister: n(S),
                    onOnOk: Se
                }, {
                    default: g(()=>[
                            h(Y, {
                                class: "proCard"
                            }, {
                                default: g(()=>[
                                        h(G, {
                                            onRegister: n(ce),
                                            showActionButtonGroup: !1,
                                            showSubmitButton: !1,
                                            showResetButton: !1
                                        }, null, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            }),
                            h(Y, {
                                bordered: !1,
                                class: "proCard mt-2"
                            }, {
                                default: g(()=>[
                                        h(n(Te), {
                                            ref_key: "basicTableRef",
                                            ref: m,
                                            columns: n(po)({
                                                storageLocationRoom: n(E),
                                                storageLocationShelf: n(F),
                                                storageLocationBox: n(V),
                                                isFirstInbound: n(A)
                                            }),
                                            dataSource: n(v),
                                            "row-key": (Re)=>Re.id,
                                            autoScrollX: !0,
                                            actionColumn: n(pe),
                                            showTableSetting: !1,
                                            pagination: !1,
                                            "virtual-scroll": ""
                                        }, {
                                            tableTitle: g(()=>[
                                                    $(z(n(e)("materialsStock.inStockModal.inboundDetails")) + " ", 1),
                                                    n(p) ? (ee(), Ge("span", mo, [
                                                        h(we, {
                                                            class: "text-red-600"
                                                        }, {
                                                            default: g(()=>[
                                                                    h(n(Ue))
                                                                ]),
                                                            _: 1
                                                        }),
                                                        $(" " + z(n(p)), 1)
                                                    ])) : $e("", !0)
                                                ]),
                                            toolbar: g(()=>[
                                                    h(Ne, {
                                                        trigger: "hover"
                                                    }, {
                                                        trigger: g(()=>[
                                                                h(_e, {
                                                                    type: "primary",
                                                                    strong: "",
                                                                    bordered: "",
                                                                    secondary: "",
                                                                    class: "size-8",
                                                                    onClick: he
                                                                }, {
                                                                    icon: g(()=>r[0] || (r[0] = [
                                                                            Ae("i", {
                                                                                class: "iconfont icon-ADD"
                                                                            }, null, -1)
                                                                        ])),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        default: g(()=>[
                                                                $(" " + z(n(e)("common.addText")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "columns",
                                            "dataSource",
                                            "row-key",
                                            "actionColumn"
                                        ])
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Io as _, __tla };
