import { V as D, d as N, r as T, f as M, bk as R, a as O, Z as y, e_ as j, ac as d, c as q, o as L, X as E, w as i, j as s, c6 as V, aI as $, p as h, A as C, l as m, B as z, N as A, iD as F, hj as H, S as Q, cZ as Z, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as W } from "./Table-0PViRYCf.js";
import { _ as X } from "./TableAction.vue_vue_type_script_setup_true_lang-Bj_Y4LtN.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import "./ImageUpload.vue_vue_type_style_index_0_scoped_cb086928_lang-D-28kXvw.js";
import "./vuedraggable.umd-Co2xEC3p.js";
import "./BasicUpload.vue_vue_type_style_index_0_scoped_a4d0e930_lang-DxRbtP01.js";
import "./BasicForm.vue_vue_type_style_index_0_scoped_b9e995ec_lang-CEvcLwxD.js";
import "./BasicSelect.vue_vue_type_style_index_0_scoped_772d51cc_lang-Brp6PjEU.js";
import "./index-DkvzUEqh.js";
import { d as G, __tla as __tla_1 } from "./index.vue_vue_type_style_index_0_scoped_b974e5ec_lang-_0QwzFKM.js";
import { _ as K, __tla as __tla_2 } from "./index.vue_vue_type_script_setup_true_lang-CiThekrH.js";
import "./schemas-BmKi-UM9.js";
import "./props-CLtNejQT.js";
import { b as U, a as Y } from "./unPlannedJob-BvCurP2n.js";
import { g as ee } from "./materialsStock-DZo3mecL.js";
import { i as te } from "./isEmpty-BUg1OsQj.js";
let Ce;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_2;
        } catch  {}
    })()
]).then(async ()=>{
    let c, ae;
    ({ t: c } = D());
    ae = [
        {
            key: "No",
            title: c("unPlannedJob.unPlannedJobComp.tableB.no"),
            width: "50px",
            render (u, _) {
                return _ + 1;
            }
        },
        {
            key: "itemCode",
            title: c("unPlannedJob.unPlannedJobComp.tableB.itemCode")
        },
        {
            key: "itemDescription",
            title: c("unPlannedJob.unPlannedJobComp.tableB.itemDescription")
        },
        {
            key: "specification",
            title: c("unPlannedJob.unPlannedJobComp.tableB.specification")
        },
        {
            key: "manufacturer",
            title: c("unPlannedJob.unPlannedJobComp.tableB.brand")
        },
        {
            key: "quantity",
            title: c("unPlannedJob.unPlannedJobComp.tableB.qty")
        },
        {
            key: "units",
            title: c("unPlannedJob.unPlannedJobComp.tableB.units")
        }
    ];
    Ce = N({
        __name: "index",
        props: {
            dataSource: {
                type: Array,
                default: []
            },
            disabled: {
                type: Boolean,
                default: !1
            },
            mainData: {
                type: Object,
                default: []
            }
        },
        emits: [
            "remove",
            "add-ok"
        ],
        setup (u, { emit: _ }) {
            const o = T(), x = Z(), S = M(), p = u, { t: l } = D();
            R();
            const g = _, P = O({
                width: 160,
                title: l("common.optionsText"),
                key: "action",
                fixed: "right",
                align: "center",
                render (e, n) {
                    return y(X, {
                        style: "text",
                        actions: [
                            {
                                label: l("common.optionsDelText"),
                                labelShow: !1,
                                icon: y("i", {
                                    class: "iconfont icon-Delete red"
                                }),
                                onPositiveClick: async ()=>{
                                    e.id && await U([
                                        e.id
                                    ]), J(n);
                                },
                                onNegativeClick: ()=>{},
                                isConfirm: !0,
                                confirmContent: l("common.dialogContentDeleteText")
                            },
                            {
                                label: l("common.optionsEditText"),
                                labelShow: !1,
                                icon: y(j),
                                onClick: ()=>{
                                    k(e);
                                }
                            }
                        ]
                    });
                }
            });
            function w({ index: e, record: n, done: t }) {
                t();
            }
            async function I({ isEdit: e, setInventoryDetailTableData: n, mainData: t, setMaterialDetail: a }) {
                if (e) d(()=>{
                    n(t?.tableData), a({
                        ...t,
                        ...t.raw
                    });
                });
                else if (t.raw) {
                    const r = await ee({
                        pageNum: 1,
                        pageSize: 1e3,
                        shipId: S.query.shipId,
                        materialId: t.raw?.id
                    });
                    d(()=>{
                        n(r.list), a({
                            ...t,
                            tableData: r.list
                        });
                    });
                } else d(()=>{
                    n([]), a(t);
                });
            }
            async function k(e) {
                if (console.log("mainData", p.mainData), e) {
                    if (e.id) {
                        const t = await Y(e.id);
                        d(()=>{
                            o.value?.setMaterialFormData({
                                ...t?.materialDetailInfo,
                                id: e.id,
                                materialItemId: t?.materialDetailInfo.materialId,
                                materialId: t?.materialDetailInfo.materialId,
                                ROB: t?.materialDetailInfo?.rob,
                                remarks: e.remarks || t?.materialDetailInfo?.remarks,
                                task: p.mainData?.basic?.jobCode,
                                tableData: !te(e.tableData) && e.tableData.map((a)=>({
                                        ...a,
                                        quantity: Number(t?.detailsLocationVos.find((r)=>r.id === a.id).stock)
                                    })) || t?.detailsLocationVos?.map((a)=>({
                                        ...a,
                                        quantity: Number(a.stock),
                                        useQuantity: Number(a.quantity)
                                    }))
                            });
                        });
                    } else d(()=>{
                        o.value?.setMaterialFormData({
                            ...e,
                            ...e.raw,
                            task: p.mainData?.basic?.jobCode
                        });
                    });
                    o.value?.handleOpenModal(e);
                } else o.value?.handleOpenModal(), o.value?.setMaterialFormData({
                    task: p.mainData?.basic?.jobCode
                });
                const { formSchemas: n } = await G();
                o.value.setProps({
                    schemas: n
                });
            }
            function J(e) {
                g("remove", e);
            }
            function B(e) {
                o.value.setSubLoading(!1);
                const { isEdit: n, resData: t, tableData: a } = e;
                if (a.reduce((b, f)=>f.useQuantity ? Number(b) + Number(f.useQuantity) : Number(b), 0) === 0) return x.warning(l("pms.unPlannedJob.materialsTotalZero"));
                g("add-ok", {
                    mainData: t,
                    tableData: a,
                    isEdit: n,
                    close: ()=>{
                        o.value.closeModal();
                    }
                });
            }
            return (e, n)=>{
                const t = Q, a = H, r = A, b = z, f = $, v = E;
                return L(), q(v, null, {
                    default: i(()=>[
                            s(m(W), {
                                columns: m(ae),
                                ref: "basicTableRef",
                                autoScrollX: !0,
                                "virtual-scroll": "",
                                showTableSetting: !1,
                                pagination: !1,
                                showTableAdd: !0,
                                dataSource: u.dataSource,
                                actionColumn: !u.disabled && P,
                                canResize: !1
                            }, V({
                                tableTitle: i(()=>[
                                        s(a, {
                                            prefix: "bar",
                                            "align-text": ""
                                        }, {
                                            default: i(()=>[
                                                    s(t, null, {
                                                        default: i(()=>[
                                                                h(C(m(l)("unPlannedJob.materials")), 1)
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 2
                            }, [
                                u.disabled ? void 0 : {
                                    name: "toolbar",
                                    fn: i(()=>[
                                            s(f, {
                                                trigger: "hover"
                                            }, {
                                                trigger: i(()=>[
                                                        s(b, {
                                                            strong: "",
                                                            secondary: "",
                                                            type: "primary",
                                                            class: "pl-[5px] pr-[5px] h-[28px]",
                                                            onClick: n[0] || (n[0] = (ne)=>k(void 0))
                                                        }, {
                                                            icon: i(()=>[
                                                                    s(r, {
                                                                        size: "18"
                                                                    }, {
                                                                        default: i(()=>[
                                                                                s(m(F))
                                                                            ]),
                                                                        _: 1
                                                                    })
                                                                ]),
                                                            _: 1
                                                        })
                                                    ]),
                                                default: i(()=>[
                                                        h(" " + C(m(l)("common.addText")), 1)
                                                    ]),
                                                _: 1
                                            })
                                        ]),
                                    key: "0"
                                }
                            ]), 1032, [
                                "columns",
                                "dataSource",
                                "actionColumn"
                            ]),
                            s(m(K), {
                                ref_key: "modalMaterialsRef",
                                ref: o,
                                onSuccess: B,
                                title: m(l)("jobOrder.materialsRequired"),
                                mode: "unPlannedJob",
                                onRowEditSuccess: w,
                                onTableDataInit: I
                            }, null, 8, [
                                "title"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { Ce as _, __tla };
