import { _ as M } 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 P } from "./BasicForm-dL_oCSPM.js";
import { c as b, __tla as __tla_0 } from "./schemas-C0ECnkWr.js";
import { t as O, v as k, w as V } from "./template-rpthWlT9.js";
import { d as A, V as N, r as m, c as $, o as C, l, w as U, j, ac as d, cZ as z, __tla as __tla_1 } from "./index-9PRMimni.js";
import { u as G } from "./useModal-CO65vga3.js";
import { u as L } from "./useForm-CKmgcynv.js";
let X;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })()
]).then(async ()=>{
    X = A({
        __name: "RectificationModal",
        props: {
            formData: {}
        },
        emits: [
            "success"
        ],
        setup (h, { expose: T, emit: x }) {
            const f = x, s = h, { t: c } = N(), n = z(), y = m(""), [v, { openModal: g, closeModal: p, setSubLoading: i, setProps: _ }] = G({
                title: "",
                width: 800
            }), { rectificationSchemas: D, methods: w } = b({
                formData: s.formData
            }), [R, { submit: B, setFieldsValue: u }] = L({
                gridProps: {
                    cols: 3
                },
                layout: "horizontal",
                labelWidth: "800",
                schemas: D,
                showActionButtonGroup: !1
            }), r = m(""), o = m({});
            async function F(a, e, t) {
                _({
                    title: a
                }), g(), w?.setRectificationOnly(t), e ? (o.value = await O(e.id), o.value.expirationTime && typeof o.value.expirationTime == "string" && (o.value.expirationTime = o.value.expirationTime.split(/T| /)[0]), d(()=>{
                    u(o.value);
                }), t ? r.value = "view" : r.value = "edit") : (r.value = "add", d(()=>{
                    u({
                        reportNo: s.formData?.reportNum
                    });
                })), y.value = e?.id;
            }
            async function I() {
                try {
                    const a = await B();
                    if (!a) {
                        i(!1);
                        return;
                    }
                    const e = {
                        ...a
                    };
                    if (e.expirationTime) if (typeof e.expirationTime == "string") {
                        const t = e.expirationTime.split(/T| /)[0];
                        e.expirationTime = `${t} 00:00:00`;
                    } else e.expirationTime instanceof Date && (e.expirationTime = `${e.expirationTime.toISOString().split("T")[0]} 00:00:00`);
                    if (delete e.deficiencyPhotoUrlPhoto, r.value === "add") k({
                        ...e,
                        shipId: s.formData?.shipId,
                        reportId: s.formData?.uuid,
                        status: "new",
                        reportType: "safetyQuality",
                        auditTypeId: s.formData?.visitType || 29
                    }).then((t)=>{
                        t.data?.success ? (p(), f("success"), n.success(c("common.optionsSuccessText"))) : n.error(t.data?.msg), i(!1);
                    }).catch(()=>{
                        i(!1);
                    });
                    else {
                        const t = {
                            ...o.value,
                            ...e
                        };
                        delete t.deficiencyPhotoUrlPhoto, await V(t), p(), f("success"), n.success(c("common.optionsSuccessText"));
                    }
                } catch  {
                    i(!1), n.error(c("common.saveFailedText"));
                } finally{
                    i(!1);
                }
            }
            return T({
                handleOpenModal: F
            }), (a, e)=>{
                const t = P, S = M;
                return C(), $(S, {
                    ref: "modalRef",
                    onRegister: l(v),
                    onOnOk: I,
                    showAction: l(r) !== "view"
                }, {
                    default: U(()=>[
                            j(t, {
                                ref: "formRef",
                                onRegister: l(R)
                            }, null, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister",
                    "showAction"
                ]);
            };
        }
    });
});
export { X as _, __tla };
