import { _ as ue } 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 de } from "./BasicForm-dL_oCSPM.js";
import { B as me } from "./Table-0PViRYCf.js";
import { _ as fe } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { i as pe, g as ge } from "./sparePartsStock-8NzBm-vI.js";
import { g as b } from "./storageLocation-CpgPSQOH.js";
import { c as ve, a as he, __tla as __tla_0 } from "./modalSchemas-qMFWMNWN.js";
import { d as be, V as _e, r as n, a as ye, Z as d, hp as we, c as Se, o as C, l as s, w as i, j as c, W as ke, aI as xe, p as _, A as y, B as Te, i as Re, h as Ce, D as Be, N as Ne, iy as Ie, cs as De, ac as qe, cZ as Le, __tla as __tla_1 } from "./index-9PRMimni.js";
import { u as Pe } from "./useModal-CO65vga3.js";
import { u as Ee } from "./useForm-CKmgcynv.js";
import { i as Fe } from "./isNumber-D5aBrEhN.js";
let Qe;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    let Ve;
    Ve = {
        key: 0,
        class: "text-red-600 ml-4"
    };
    Qe = be({
        __name: "InboundModal",
        emits: [
            "success"
        ],
        setup (Me, { expose: B, emit: N }) {
            const I = N, { t } = _e(), D = Le(), w = n(""), r = n(), v = n(), u = n(), S = n(), k = n(), x = n(), T = n(), l = n([]), m = n(), f = n(), p = n(), R = n(), [q, { openModal: L, closeModal: P, setSubLoading: h }] = Pe({
                title: t("sparePartsStock.inbound"),
                subBtuText: t("common.saveText"),
                displayDirective: "if",
                width: 1440
            }), E = ye({
                width: 100,
                title: t("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e) {
                    return d(fe, {
                        style: "text",
                        actions: F(e)
                    });
                }
            });
            function F(e) {
                return console.log(e), e.editable ? [
                    {
                        label: t("common.saveText"),
                        labelShow: !1,
                        icon: d("i", {
                            class: "iconfont icon-Save"
                        }),
                        onClick: A.bind(null, e)
                    },
                    {
                        label: t("common.cancelText"),
                        labelShow: !1,
                        icon: d(we),
                        onClick: M.bind(null, e)
                    }
                ] : [
                    {
                        label: t("common.optionsEditText"),
                        labelShow: !1,
                        icon: d("i", {
                            class: "iconfont icon-a-Frame28"
                        }),
                        onClick: V.bind(null, e)
                    },
                    {
                        label: t("common.optionsDelText"),
                        labelShow: !1,
                        icon: d("i", {
                            class: "iconfont icon-Delete red"
                        }),
                        onPositiveClick: async ()=>{
                            l.value = l.value.filter((o)=>o.id !== e.id);
                        },
                        onNegativeClick: ()=>{},
                        isConfirm: !0,
                        confirmContent: t("common.delPop.contRole")
                    }
                ];
            }
            function V(e) {
                console.log(e), w.value = e.id, e.onEdit(!0);
            }
            function M(e) {
                w.value = "", e.onEdit?.(!1, !1);
            }
            async function A(e) {
                await e.onEdit(!1, !0) && (r.value = "", v.value = !1);
            }
            function O({ record: e, index: o, key: a, value: g }) {
                console.log("record", e), console.log("index", o), console.log("key", a), console.log("value", g);
            }
            function j(e) {
                console.log(e);
            }
            function $({ column: e, value: o, record: a }) {
                e.key === "id" && (a.editValueRefs.name4.value = `${o}`), console.log(e, o, a);
            }
            function K() {
                l.value.push({
                    id: De(),
                    operationType: "11",
                    quantity: 0
                }), v.value = !0;
            }
            async function W(e) {
                l.value = [], L(), Fe(e) && (r.value = "", qe(async ()=>{
                    ae({
                        shipId: e
                    }), u.value = e, await Q();
                }));
            }
            async function Z() {
                try {
                    if (await te(), l.value && l.value.length > 0) {
                        if (v.value) return r.value = t("sparePartsStock.inboundDetailsRequired"), h(!1), Promise.reject(t("sparePartsStock.inboundDetailsRequired"));
                    } else return r.value = t("sparePartsStock.inboundDetailsRequired"), h(!1), Promise.reject(t("sparePartsStock.inboundDetailsRequired"));
                    const o = {
                        ...ne(),
                        shipId: u.value,
                        details: l.value.map((a)=>({
                                operationType: a.operationType,
                                itemType: a.itemType,
                                quantity: a.quantity,
                                roomNo: a.roomNo,
                                shelfNo: a.shelfNo,
                                boxNo: a.boxNo
                            }))
                    };
                    await pe(o), D.success(t("common.optionsSuccessText")), I("success"), P();
                } catch (e) {
                    console.log(e), h(!1);
                }
            }
            async function z() {
                const e = await b({
                    shipId: u.value,
                    warehouseType: "0"
                });
                m.value = e.list.map((o)=>({
                        label: o.warehouseName,
                        value: o.id,
                        item: o
                    }));
            }
            async function G() {
                const e = await b({
                    shipId: u.value,
                    warehouseType: "1"
                });
                f.value = e.list.map((o)=>({
                        label: o.warehouseName,
                        value: o.id,
                        item: o
                    }));
            }
            async function U() {
                const e = await b({
                    shipId: u.value,
                    warehouseType: "2"
                });
                p.value = e.list.map((o)=>({
                        label: o.warehouseName,
                        value: o.id,
                        item: o
                    }));
            }
            async function X() {
                if (m.value && f.value && p.value && m.value.length === 0 && f.value.length === 0 && p.value.length === 0) {
                    R.value = !0;
                    return;
                }
                R.value = !1;
            }
            async function H(e) {
                return (await ge({
                    itemId: s(e)
                })).map((a)=>({
                        label: a.reqNo,
                        value: a.reqNo,
                        item: a
                    }));
            }
            function J() {
                console.log("close"), S.value = [], k.value = [], x.value = [], T.value = void 0;
            }
            async function Q() {
                await z(), await G(), await U(), await X();
            }
            const { schemas: Y } = ve({
                getRequisitionList: H,
                shipId: u,
                equipmentList: S,
                sparePartsList: k,
                purchaseRequisitionList: x,
                equipmentInfo: T
            }), { columns: ee } = he({
                storageLocationRoom: m,
                storageLocationShelf: f,
                storageLocationBox: p
            }), [oe, { setFieldsValue: ae, validate: te, getFieldsValue: ne, resetFields: Ae }] = Ee({
                gridProps: {
                    cols: 4
                },
                schemas: Y,
                showAdvancedButton: !1
            });
            return B({
                handleOpenModal: W
            }), (e, o)=>{
                const a = de, g = ke, se = Ne, ie = Te, le = xe, ce = ue;
                return C(), Se(ce, {
                    ref: "modalRef",
                    onRegister: s(q),
                    onOnOk: Z,
                    "on-after-leave": J
                }, {
                    default: i(()=>[
                            c(g, {
                                class: "proCard"
                            }, {
                                default: i(()=>[
                                        c(a, {
                                            onRegister: s(oe),
                                            showActionButtonGroup: !1,
                                            showSubmitButton: !1,
                                            showResetButton: !1
                                        }, null, 8, [
                                            "onRegister"
                                        ])
                                    ]),
                                _: 1
                            }),
                            c(g, {
                                bordered: !1,
                                class: "proCard mt-2"
                            }, {
                                default: i(()=>[
                                        c(s(me), {
                                            ref: "basicTableRef",
                                            columns: s(ee),
                                            dataSource: s(l),
                                            "row-key": (re)=>re.id,
                                            autoScrollX: !0,
                                            actionColumn: s(E),
                                            showTableSetting: !1,
                                            pagination: !1,
                                            "virtual-scroll": "",
                                            onEditEnd: O,
                                            onEditChange: $,
                                            "onUpdate:checkedRowKeys": j
                                        }, {
                                            tableTitle: i(()=>[
                                                    _(y(s(t)("sparePartsStock.inboundDetails")) + " ", 1),
                                                    s(r) ? (C(), Ce("span", Ve, [
                                                        c(se, {
                                                            class: "text-red-600"
                                                        }, {
                                                            default: i(()=>[
                                                                    c(s(Ie))
                                                                ]),
                                                            _: 1
                                                        }),
                                                        _(" " + y(s(r)), 1)
                                                    ])) : Be("", !0)
                                                ]),
                                            toolbar: i(()=>[
                                                    c(le, {
                                                        trigger: "hover"
                                                    }, {
                                                        trigger: i(()=>[
                                                                c(ie, {
                                                                    type: "primary",
                                                                    strong: "",
                                                                    bordered: "",
                                                                    secondary: "",
                                                                    class: "size-8",
                                                                    onClick: K
                                                                }, {
                                                                    icon: i(()=>o[0] || (o[0] = [
                                                                            Re("i", {
                                                                                class: "iconfont icon-ADD"
                                                                            }, null, -1)
                                                                        ])),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        default: i(()=>[
                                                                _(" " + y(s(t)("common.addText")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "columns",
                                            "dataSource",
                                            "row-key",
                                            "actionColumn"
                                        ])
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Qe as _, __tla };
