import { _ as $ } 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 A } from "./BasicForm-dL_oCSPM.js";
import { c as E, __tla as __tla_0 } from "./schemas-DEsCEng-.js";
import { u as O } from "./account-C850CBTF.js";
import { d as G, s as K } from "./workpermit-ycq2YJDA.js";
import { h as z } from "./smsFormsTemplate-Dsea_L5v.js";
import { d as H } from "./download-CIBdrxiA.js";
import { d as Z, V as j, bk as J, r as Q, c as X, o as Y, l, w as c, j as u, i as T, aH as ee, B as oe, p as te, A as y, ac as se, cZ as ae, __tla as __tla_1 } from "./index-9PRMimni.js";
import { u as ne } from "./useModal-CO65vga3.js";
import { u as re } from "./useForm-CKmgcynv.js";
let Te;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    let le;
    le = {
        class: "w-full"
    };
    Te = Z({
        __name: "AddModal",
        props: {
            selectedTreeItem: {}
        },
        emits: [
            "success"
        ],
        setup (g, { expose: R, emit: B }) {
            const s = g, k = B, { t: a } = j(), d = ae(), v = J(), f = Q(""), [F, { openModal: b, closeModal: S, setSubLoading: m, setProps: M }] = ne({
                title: "",
                width: 700
            }), { modalSchemas: I } = E(), [P, { submit: U, setFieldsValue: V, validate: _ }] = re({
                gridProps: {
                    cols: 1
                },
                layout: "horizontal",
                labelPlacement: "left",
                labelWidth: "150",
                schemas: I,
                showActionButtonGroup: !1
            });
            async function C(e) {
                M({
                    title: e
                }), b(), await se(), V({
                    permitsTypeName: v.getLocale === "en" ? s.selectedTreeItem?.nameEn : s.selectedTreeItem?.name,
                    processType: 0
                }), q();
            }
            async function q() {
                f.value = await z(s.selectedTreeItem?.businessKey);
            }
            function D() {
                H({
                    url: f.value
                });
            }
            async function L(e, o, t) {
                let i = e.file?.file;
                const n = new FormData;
                n.append("file", i);
                try {
                    const r = await O(n);
                    o[t] = r.name, _([
                        t
                    ]), e.onFinish();
                } catch  {
                    e.onError(), h(o, t);
                }
            }
            function N({ file: e }) {
                const o = e.name?.split(".")?.pop()?.toLowerCase();
                return o !== "xlsx" && o !== "xls" ? (d.error(`${a("common.file.uploadFormat")} .xlsx, .xls`), !1) : !0;
            }
            function h(e, o) {
                e[o] = "", _([
                    o
                ]);
            }
            async function W() {
                const e = await U();
                if (!e) {
                    m(!1);
                    return;
                }
                try {
                    const o = await G({
                        ...e,
                        workPermitsType: s.selectedTreeItem?.businessKey
                    });
                    +e.processType == 1 && await K({
                        id: o
                    }), m(!1), S(), d.success(a("common.optionsSuccessText")), k("success", +e.processType != 1, o);
                } catch  {
                    m(!1);
                }
            }
            return R({
                handleOpenModal: C
            }), (e, o)=>{
                const t = oe, i = ee, n = A, r = $;
                return Y(), X(r, {
                    ref: "modalRef",
                    onRegister: l(F),
                    onOnOk: W
                }, {
                    default: c(()=>[
                            u(n, {
                                ref: "formRef",
                                onRegister: l(P)
                            }, {
                                fileSlot: c(({ model: x, field: w })=>[
                                        T("div", le, [
                                            u(i, {
                                                multiple: "",
                                                accept: ".xlsx, .xls",
                                                max: 1,
                                                customRequest: (p)=>L(p, x, w),
                                                onBeforeUpload: N,
                                                onRemove: (p)=>h(x, w)
                                            }, {
                                                default: c(()=>[
                                                        u(t, null, {
                                                            default: c(()=>[
                                                                    te(y(l(a)("common.uploadText")), 1)
                                                                ]),
                                                            _: 1
                                                        })
                                                    ]),
                                                _: 2
                                            }, 1032, [
                                                "customRequest",
                                                "onRemove"
                                            ]),
                                            T("a", {
                                                href: "javascript:",
                                                onClick: o[0] || (o[0] = (p)=>D())
                                            }, y(l(a)("hsqe.workpermit.downloadTemplate")), 1)
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Te as _, __tla };
