import { _ as be } 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 ve } from "./BasicForm-dL_oCSPM.js";
import { d as _e, V as ge, e as he, f as ye, r as n, a as Re, Z as h, hp as we, cZ as De, c as I, o as x, l as s, w as c, D as j, j as l, W as xe, i as Ce, B as Se, p as y, A as R, h as Ee, N as ke, iy as Oe, ac as Te, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as Be } from "./Table-0PViRYCf.js";
import { _ as Pe } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import { g as Ie, h as je, __tla as __tla_1 } from "./index.vue_vue_type_style_index_0_scoped_b974e5ec_lang-_0QwzFKM.js";
import { u as qe } from "./useModal-CO65vga3.js";
import { u as q } from "./useForm-CKmgcynv.js";
import { i as N } from "./isEmpty-BUg1OsQj.js";
let ze;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    let Ne, Ve;
    Ne = {
        class: "h-auto w-[20%] justify-end flex items-end"
    };
    Ve = {
        key: 0,
        class: "text-red-600 ml-4"
    };
    ze = _e({
        __name: "index",
        props: {
            mode: {}
        },
        emits: [
            "success",
            "rowEditSuccess",
            "tableDataInit"
        ],
        setup (V, { expose: F, emit: M }) {
            const d = M, w = V, { t: a } = ge(), A = he(), J = ye(), b = De(), { columns: G } = Ie(), K = J.query.shipId, C = n(), S = n(), Q = n(), r = n(), E = n(), k = n(), f = n(), v = n(!1), u = n(!1), _ = n(), O = n(), W = Re({
                width: 100,
                title: a("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e, t) {
                    return h(Pe, {
                        style: "text",
                        actions: Z(e, t)
                    });
                }
            });
            function Z(e, t) {
                return console.log(e, t), e.editable ? [
                    {
                        label: a("common.saveText"),
                        labelShow: !1,
                        icon: h("i", {
                            class: "iconfont icon-Save"
                        }),
                        onClick: H.bind(null, {
                            record: e,
                            index: t
                        })
                    },
                    {
                        label: a("common.cancelText"),
                        labelShow: !1,
                        icon: h(we),
                        onClick: X.bind(null, e)
                    }
                ] : [
                    {
                        label: a("common.optionsEditText"),
                        labelShow: !1,
                        icon: h("i", {
                            class: "iconfont icon-a-Frame28"
                        }),
                        onClick: U.bind(null, {
                            record: e,
                            index: t
                        })
                    }
                ];
            }
            function $({ record: e, index: t, key: o, value: i }) {
                console.log("record", e), console.log("index", t), console.log("key", o), console.log("value", i);
            }
            function z(e) {
                console.log(e);
            }
            function L({ column: e, value: t, record: o }) {
                console.log(e, t, o);
            }
            function U({ record: e, index: t }) {
                try {
                    for (const o of r.value)if (o.editable) {
                        console.log(o), b.warning(a("jobOrder.editTip"));
                        return;
                    }
                    console.log(e), C.value = e.id, v.value = !0, e.onEdit(!0);
                } catch (o) {
                    console.log(o);
                }
            }
            function X(e) {
                C.value = "", e.onEdit?.(!1, !1), v.value = !1;
            }
            async function H({ record: e, index: t }) {
                const o = async ()=>{
                    S.value.reload(), b.success(a("common.saveSuccessText")), await e.onEdit(!1);
                };
                try {
                    await e.onEdit(!1, !0) && (f.value = "", v.value = !1, w.mode === "unPlannedJob" ? d("rowEditSuccess", {
                        record: e,
                        index: t,
                        done: o
                    }) : d("rowEditSuccess", {
                        record: e,
                        index: t,
                        setInventoryDetailTableData: D,
                        done: o
                    }));
                } catch (i) {
                    console.log(i);
                }
            }
            const [Y, { openModal: ee, closeModal: T, setSubLoading: m }] = qe({
                title: a("jobOrder.outbound"),
                width: 1140
            }), [te, { setFieldsValue: g, getFieldsValue: B, setProps: oe, validate: ae, resetFields: se }] = q({
                gridProps: {
                    cols: 16
                },
                layout: "horizontal"
            });
            async function ne(e, t) {
                ee(), k.value = t, console.log(e, t), N(e) ? (u.value = !1, r.value = []) : (u.value = !0, Te(()=>{
                    se();
                })), f.value = "";
            }
            const { schemas: le } = je({
                shipId: Number(K),
                equipmentInfo: k,
                setSparePartsFormData: P
            }), [re] = q({
                gridProps: {
                    cols: 2
                },
                schemas: le,
                showAdvancedButton: !1
            });
            async function ie() {
                try {
                    await ae(), await ce();
                    const e = B();
                    if (N(e.sparePartNumber)) {
                        b.warning(a("jobOrder.sparePartNumberRequired")), m(!1);
                        return;
                    }
                    const t = r.value.reduce((o, i)=>Number(o) + Number(s(i.editValueRefs.normalQuantity)) + Number(s(i.editValueRefs.reconditionedQuantity)), 0);
                    if (e && t === 0) {
                        b.warning(a("jobOrder.sparePartInventoryRequired")), m(!1);
                        return;
                    }
                    if (e.quantity = t, w.mode === "unPlannedJob") {
                        const o = {
                            ...E.value,
                            ...e,
                            id: _.value,
                            itemId: O.value
                        };
                        d("success", {
                            isEdit: u.value,
                            resData: o,
                            tableData: r.value
                        });
                    } else {
                        const o = {
                            ...e,
                            id: _.value
                        };
                        d("success", {
                            isEdit: u.value,
                            resData: o,
                            tableData: r.value
                        });
                    }
                } catch  {
                    m(!1);
                }
            }
            async function ce() {
                if (r.value && r.value.length > 0) {
                    if (v.value) return f.value = a("jobOrder.saveOutboundDetailsRequired"), m(!1), Promise.reject(a("jobOrder.saveOutboundDetailsRequired"));
                } else return f.value = a("jobOrder.outboundDetailsRequired"), m(!1), Promise.reject(a("jobOrder.outboundDetailsRequired"));
            }
            async function P(e) {
                E.value = e;
                try {
                    w.mode === "unPlannedJob" ? (_.value = e.id || "", O.value = e.itemId || "", g(e), d("tableDataInit", {
                        isEdit: u.value,
                        setInventoryDetailTableData: D,
                        mainData: e,
                        setSparePartsDetail: g
                    })) : d("tableDataInit", {
                        isEdit: u.value,
                        setInventoryDetailTableData: D,
                        setSparePartId: de,
                        mainData: e,
                        setSparePartsDetail: g
                    });
                } catch  {}
            }
            function ue() {
                A.push({
                    name: "requisitionOrder",
                    query: {}
                }), T();
            }
            function D(e) {
                r.value = e;
            }
            function de(e) {
                _.value = e;
            }
            return F({
                handleOpenModal: ne,
                setProps: oe,
                getSparePartsDetail: B,
                setSparePartsFormData: P,
                closeModal: T,
                setSubLoading: m,
                setSparePartsDetail: g
            }), (e, t)=>{
                const o = ve, i = Se, p = xe, fe = ke, me = be;
                return x(), I(me, {
                    ref: "modalRef",
                    subBtuText: s(a)("common.confirmText"),
                    onRegister: s(Y),
                    onOnOk: ie
                }, {
                    default: c(()=>[
                            s(u) ? j("", !0) : (x(), I(p, {
                                key: 0,
                                class: "proCard",
                                "content-class": "flex flex-row "
                            }, {
                                default: c(()=>[
                                        l(o, {
                                            class: "flex-auto",
                                            onRegister: s(re),
                                            showActionButtonGroup: !1
                                        }, null, 8, [
                                            "onRegister"
                                        ]),
                                        Ce("div", Ne, [
                                            l(i, {
                                                class: "",
                                                type: "success",
                                                onClick: ue
                                            }, {
                                                default: c(()=>[
                                                        y(R(s(a)("jobOrder.createRequisition")), 1)
                                                    ]),
                                                _: 1
                                            })
                                        ])
                                    ]),
                                _: 1
                            })),
                            l(p, {
                                class: "proCard mt-2",
                                "content-class": "pt-4 pb-0"
                            }, {
                                default: c(()=>[
                                        l(p, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0 text-[16px] font-bold"
                                        }, {
                                            default: c(()=>[
                                                    y(R(s(a)("jobOrder.sparePartsDetail")), 1)
                                                ]),
                                            _: 1
                                        }),
                                        l(p, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0"
                                        }, {
                                            default: c(()=>[
                                                    l(o, {
                                                        ref_key: "formRef",
                                                        ref: Q,
                                                        onRegister: s(te),
                                                        showActionButtonGroup: !1
                                                    }, null, 8, [
                                                        "onRegister"
                                                    ])
                                                ]),
                                            _: 1
                                        }),
                                        l(p, {
                                            bordered: !1,
                                            class: "proCard mt-2",
                                            "content-class": "p-0"
                                        }, {
                                            default: c(()=>[
                                                    l(s(Be), {
                                                        ref_key: "basicTableRef",
                                                        ref: S,
                                                        columns: s(G),
                                                        dataSource: s(r),
                                                        "row-key": (pe)=>pe.id,
                                                        autoScrollX: !0,
                                                        actionColumn: s(W),
                                                        showTableSetting: !1,
                                                        pagination: !1,
                                                        "virtual-scroll": "",
                                                        onEditEnd: $,
                                                        onEditChange: L,
                                                        "onUpdate:checkedRowKeys": z
                                                    }, {
                                                        tableTitle: c(()=>[
                                                                y(R(s(a)("jobOrder.inventoryDetail")) + " ", 1),
                                                                s(f) ? (x(), Ee("span", Ve, [
                                                                    l(fe, {
                                                                        class: "text-red-600"
                                                                    }, {
                                                                        default: c(()=>[
                                                                                l(s(Oe))
                                                                            ]),
                                                                        _: 1
                                                                    }),
                                                                    y(" " + R(s(f)), 1)
                                                                ])) : j("", !0)
                                                            ]),
                                                        _: 1
                                                    }, 8, [
                                                        "columns",
                                                        "dataSource",
                                                        "row-key",
                                                        "actionColumn"
                                                    ])
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            })
                        ]),
                    _: 1
                }, 8, [
                    "subBtuText",
                    "onRegister"
                ]);
            };
        }
    });
});
export { ze as _, __tla };
