import { ad as P, V as U, bk as ee, d as te, f as oe, e as ae, r as V, a4 as M, bl as re, aw as ne, c as L, o as N, w as a, j as l, W as le, H as se, i as _, aI as ie, p as y, A as b, l as n, B as pe, h as ce, D as ue, F as me, aH as de, cO as he, fm as fe, cq as ge, hK as be, X as ve, ac as O, cZ as B, bR as _e, R as ye, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as De } from "./BasicForm-dL_oCSPM.js";
import { c as xe } from "./componentSetting-DVhNDBTO.js";
import { u as Fe } from "./useTags-C1thGhjF.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { u as Ce } from "./useForm-CKmgcynv.js";
import { __tla as __tla_1 } from "./index.vue_vue_type_style_index_0_scoped_b974e5ec_lang-_0QwzFKM.js";
import "./Table.vue_vue_type_style_index_0_scoped_7b9e6ece_lang-BoW2DV_e.js";
import "./print-CT_2hrjP.js";
import "./vuedraggable.umd-Co2xEC3p.js";
import { H as we, __tla as __tla_2 } from "./index-8tHZJCCW.js";
import "./schemas-BmKi-UM9.js";
import "./props-CLtNejQT.js";
import { v as Se, b as Ne, d as Pe, __tla as __tla_3 } from "./helper-D3AT1ZPu.js";
import { g as x } from "./equipmentMainLibrary-bJTzj5mC.js";
import { r as Re } from "./round-Cr-4vvHD.js";
import "./Render.vue_vue_type_script_lang-DKUYY0Zw.js";
import "./SingleImageUpload-CNx4b9eC.js";
import "./ImageUpload.vue_vue_type_style_index_0_scoped_cb086928_lang-D-28kXvw.js";
import "./ImageUpload-DUsnro3W.js";
import "./BasicUpload.vue_vue_type_style_index_0_scoped_a4d0e930_lang-DxRbtP01.js";
import "./tabsView-BXskTdVh.js";
import "./BasicForm.vue_vue_type_style_index_0_scoped_b9e995ec_lang-CEvcLwxD.js";
import "./propTypes-CebMRUpe.js";
import "./BasicSelect-C_uwzMkE.js";
import "./BasicSelect.vue_vue_type_style_index_0_scoped_772d51cc_lang-Brp6PjEU.js";
import "./dictionary-BRse4lkf.js";
import "./index-DkvzUEqh.js";
import "./index-kKnqLkWM.js";
import "./AutoComplete-Dv1Bqed4.js";
import "./TreeSelect-BZh2DeCh.js";
import "./usePageCache-DluHn7Yy.js";
import "./jobOrder-CGbsc7bp.js";
import "./has-CjqcrIOV.js";
import "./componentMap-CElCaWis.js";
import "./format-DgF6KtHk.js";
import "./omit-B2_8Y6O_.js";
import "./_flatRest-DBrd2CHT.js";
import "./flatten-DeoUZLdb.js";
import "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./useModal-CO65vga3.js";
import "./TimelineItem-Bkds7ZW8.js";
import "./Flex-CTSf12gq.js";
import "./_createMathOperation-C_MUc_Og.js";
import "./requisitionOrder-D0IG9N7e.js";
import "./_createRound-MlkJBLNh.js";
import "./toInteger-DQeH-nF-.js";
let kt;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_1;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_2;
        } catch  {}
    })(),
    (()=>{
        try {
            return __tla_3;
        } catch  {}
    })()
]).then(async ()=>{
    const H = "", Ee = "";
    function Ae(t) {
        return P.Get(`${H}/financeShipLedgerDetail/${t}`);
    }
    function $(t) {
        return P.Put(`${H}/financeShipLedgerDetail`, t);
    }
    function Ie(t) {
        return P.Post(`${Ee}/approval/submit`, t);
    }
    const Te = !1;
    function ke(t) {
        return t ? {
            ...t,
            amount: t.amount ? +t.amount : null,
            rate: t.rate ? +t.rate : null,
            exchangedAmount: t.exchangedAmount ? +t.exchangedAmount : null,
            attach_path: t.attachFullUrl ? {
                name: t.attachName,
                path: t.attachUrl,
                url: t.attachFullUrl,
                status: "finished"
            } : null
        } : {};
    }
    const qe = await x("finance_expense_type"), Ve = await x("currency"), Me = await x("finance_ship_ledger_belong"), Le = await x("finance_ship_ledger_approver"), v = ee();
    function z(t, r) {
        return Re(Pe(t, r), 2);
    }
    const { t: e } = U();
    function Oe() {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "shipId",
                component: "NSelect",
                label: e("approveDetail.vessel"),
                componentProps: {
                    disabled: !0,
                    placeholder: e("approveDetail.vessel"),
                    labelField: v.getLocale === "en" ? "labelEn" : "label",
                    options: Se
                }
            },
            {
                field: "date",
                component: "NDatePicker",
                label: e("approveDetail.date"),
                componentProps: {
                    disabled: !0,
                    type: "date",
                    valueFormat: "yyyy-MM-dd",
                    placeholder: e("approveDetail.date")
                }
            },
            {
                field: "expenseType",
                component: "NSelect",
                label: e("approveDetail.expenseType"),
                componentProps: {
                    disabled: !0,
                    labelField: v.getLocale === "en" ? "labelEn" : "label",
                    placeholder: e("approveDetail.expenseType"),
                    options: qe
                }
            },
            {
                field: "amount",
                component: "NInputNumber",
                label: e("approveDetail.amount"),
                componentProps: ({ model: t, formAction: r })=>({
                        min: .01,
                        step: 1,
                        precision: 2,
                        style: {
                            width: "100%"
                        },
                        placeholder: e("approveDetail.amount"),
                        onUpdateValue: (p)=>{
                            if (t.rate && p) {
                                const d = z(p, t.rate);
                                r.setFieldsValue({
                                    exchangedAmount: d
                                });
                            } else r.setFieldsValue({
                                exchangedAmount: null
                            });
                        }
                    }),
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.amountRequired")
                    }
                ]
            },
            {
                field: "isForeignCurrency",
                component: "NSelect",
                label: e("approveDetail.foreignCurrency"),
                componentProps: ({ model: t, formAction: r })=>{
                    const { setFieldsValue: p } = r;
                    return {
                        labelField: v.getLocale === "en" ? "labelEn" : "label",
                        placeholder: e("approveDetail.foreignCurrency"),
                        options: Ne,
                        onUpdateValue: (d)=>{
                            d === 0 && p({
                                currency: "usd",
                                rate: null,
                                exchangedAmount: null
                            });
                        }
                    };
                },
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.foreignCurrencyRequired")
                    }
                ]
            },
            {
                field: "currency",
                component: "NSelect",
                label: e("approveDetail.currency"),
                componentProps: ({ model: t, formAction: r })=>({
                        disabled: t.isForeignCurrency === 0,
                        labelField: v.getLocale === "en" ? "labelEn" : "label",
                        placeholder: e("approveDetail.currency"),
                        options: Ve
                    }),
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.currencyRequired")
                    }
                ]
            },
            {
                field: "rate",
                component: "NInputNumber",
                label: e("approveDetail.rate"),
                componentProps: ({ model: t, formAction: r })=>({
                        min: .1,
                        step: 1,
                        precision: 1,
                        style: {
                            width: "100%"
                        },
                        placeholder: e("approveDetail.rate"),
                        disabled: t.isForeignCurrency === 0,
                        onUpdateValue: (p)=>{
                            if (t.amount && p) {
                                const d = z(t.amount, p);
                                r.setFieldsValue({
                                    exchangedAmount: d
                                });
                            } else r.setFieldsValue({
                                exchangedAmount: null
                            });
                        }
                    })
            },
            {
                field: "exchangedAmount",
                component: "NInputNumber",
                label: e("approveDetail.exchangedAmount"),
                componentProps: {
                    min: .01,
                    step: 1,
                    precision: 2,
                    disabled: !0,
                    style: {
                        width: "100%"
                    },
                    placeholder: e("approveDetail.exchangedAmount")
                }
            },
            {
                field: "invoiceNo",
                component: "NInput",
                label: e("approveDetail.invoice"),
                componentProps: {
                    placeholder: e("approveDetail.invoice")
                },
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.invoiceRequired")
                    }
                ]
            },
            {
                field: "belong",
                component: "NSelect",
                label: e("approveDetail.whichTo"),
                componentProps: {
                    labelField: v.getLocale === "en" ? "labelEn" : "label",
                    placeholder: e("approveDetail.whichTo"),
                    options: Me
                },
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.whichToRequired")
                    }
                ]
            },
            {
                field: "expenseDetails",
                component: "NInput",
                label: e("approveDetail.expenseDetails"),
                giProps: {
                    span: 3
                },
                componentProps: {
                    placeholder: e("approveDetail.expenseDetails"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.expenseDetailsRequired")
                    }
                ]
            },
            {
                field: "remark",
                component: "NInput",
                label: e("approveDetail.remark"),
                giProps: {
                    span: 2
                },
                componentProps: {
                    placeholder: e("approveDetail.remark"),
                    type: "textarea",
                    showCount: !0,
                    maxlength: 1e3,
                    autosize: {
                        minRows: 3,
                        maxRows: 3
                    }
                }
            },
            {
                field: "approver",
                component: "NSelect",
                label: e("approveDetail.approver"),
                componentProps: {
                    labelField: v.getLocale === "en" ? "labelEn" : "label",
                    placeholder: e("approveDetail.approver"),
                    options: Le
                },
                rules: [
                    {
                        required: !0,
                        message: e("approveDetail.approverRequired")
                    }
                ]
            },
            {
                field: "attach_path",
                label: e("approveDetail.attachment"),
                giProps: {
                    span: 2
                },
                slot: "attachmentSlot"
            }
        ];
    }
    let Be;
    Be = {
        class: "text-[18px]",
        style: {
            fontWeight: "var(--n-title-font-weight)"
        }
    };
    kt = te({
        __name: "index",
        setup (t) {
            const { t: r } = U(), p = B(), { closeCurrent: d } = Fe(), F = oe(), R = ae(), u = V(!1), E = V(""), C = M(()=>F.query.id), A = re("historyModal"), I = M(()=>F.query?.type === "view"), [W, { setFieldsValue: G, submit: T }] = Ce({
                schemas: Oe(),
                labelWidth: "auto",
                layout: "horizontal",
                gridProps: {
                    cols: 5
                },
                showActionButtonGroup: !1
            });
            function k() {
                const o = F.query?.sourceRouteName;
                try {
                    d(), o && O(()=>{
                        R.replace({
                            name: o
                        });
                    });
                } catch (s) {
                    console.warn("Error closing tab:", s), O(()=>{
                        R.replace(o ?? "/");
                    });
                }
            }
            async function j() {
                try {
                    const o = await T();
                    if (!o) {
                        u.value = !1;
                        return;
                    }
                    u.value = !0;
                    const { attach_path: s, ...c } = o;
                    await $({
                        attachPath: s?.path,
                        ...c
                    }), p.success(r("common.saveSuccessText")), u.value = !1;
                } catch (o) {
                    console.error(o), u.value = !1;
                }
            }
            async function X() {
                try {
                    const o = await T();
                    if (!o) {
                        u.value = !1;
                        return;
                    }
                    u.value = !0;
                    const { attach_path: s, ...c } = o, { shipId: m, id: i, subModuleCode: h } = await $({
                        attachPath: s?.path,
                        ...c
                    });
                    await Ie({
                        shipId: m,
                        busId: i,
                        subModuleCode: h,
                        moduleCode: "FinanceShipLedger"
                    }), k(), p.success(r("common.submitSuccessText")), u.value = !1;
                } catch (o) {
                    console.error(o), u.value = !1;
                }
            }
            function K() {
                A.value?.handleOpenModal();
            }
            function Q({ file: o, event: s }, c, m) {
                try {
                    const i = _e("(" + s.target.response + ")"), { infoField: h } = xe.upload.apiSetting, { code: w } = i, S = i.msg || i.message || r("common.uploadFailText"), D = i[h];
                    w === ye.SUCCESS ? c[m] = {
                        name: o.name,
                        path: D.name,
                        url: D.url,
                        status: "finished"
                    } : B().error(S);
                } catch (i) {
                    console.error(i);
                }
            }
            function Z(o) {
                console.warn("File upload error:", o), p.error(r("common.uploadFailText"));
            }
            async function J() {
                if (C.value) try {
                    const o = await Ae(C.value);
                    E.value = o?.subModuleCode, G(ke(o));
                } catch (o) {
                    console.error("Failed to load detail:", o);
                }
            }
            return ne(()=>{
                J();
            }), (o, s)=>{
                const c = pe, m = ie, i = se, h = le, w = de, S = De, D = ve;
                return N(), L(D, null, {
                    default: a(()=>[
                            l(h, {
                                bordered: !1,
                                class: "proCard"
                            }, {
                                default: a(()=>[
                                        l(i, {
                                            justify: "space-between"
                                        }, {
                                            default: a(()=>[
                                                    l(i, null, {
                                                        default: a(()=>[
                                                                l(m, {
                                                                    trigger: "hover"
                                                                }, {
                                                                    trigger: a(()=>[
                                                                            l(c, {
                                                                                type: "text",
                                                                                class: "size-8",
                                                                                onClick: k
                                                                            }, {
                                                                                icon: a(()=>s[0] || (s[0] = [
                                                                                        _("i", {
                                                                                            class: "iconfont icon-a-shangyibu2 text-[16px]"
                                                                                        }, null, -1)
                                                                                    ])),
                                                                                _: 1
                                                                            })
                                                                        ]),
                                                                    default: a(()=>[
                                                                            y(" " + b(n(r)("common.backToList")), 1)
                                                                        ]),
                                                                    _: 1
                                                                }),
                                                                _("div", Be, b(n(r)("approveDetail.title")), 1)
                                                            ]),
                                                        _: 1
                                                    }),
                                                    l(i, null, {
                                                        default: a(()=>[
                                                                n(I) ? ue("", !0) : (N(), ce(me, {
                                                                    key: 0
                                                                }, [
                                                                    l(m, {
                                                                        trigger: "hover"
                                                                    }, {
                                                                        trigger: a(()=>[
                                                                                l(c, {
                                                                                    type: "primary",
                                                                                    strong: "",
                                                                                    bordered: "",
                                                                                    secondary: "",
                                                                                    class: "size-7",
                                                                                    onClick: j,
                                                                                    disabled: n(u)
                                                                                }, {
                                                                                    icon: a(()=>s[1] || (s[1] = [
                                                                                            _("i", {
                                                                                                class: "iconfont icon-Save"
                                                                                            }, null, -1)
                                                                                        ])),
                                                                                    _: 1
                                                                                }, 8, [
                                                                                    "disabled"
                                                                                ])
                                                                            ]),
                                                                        default: a(()=>[
                                                                                y(" " + b(n(r)("common.saveText")), 1)
                                                                            ]),
                                                                        _: 1
                                                                    }),
                                                                    l(m, {
                                                                        trigger: "hover"
                                                                    }, {
                                                                        trigger: a(()=>[
                                                                                l(c, {
                                                                                    type: "primary",
                                                                                    strong: "",
                                                                                    bordered: "",
                                                                                    secondary: "",
                                                                                    class: "size-7",
                                                                                    onClick: X,
                                                                                    disabled: n(u)
                                                                                }, {
                                                                                    icon: a(()=>s[2] || (s[2] = [
                                                                                            _("i", {
                                                                                                class: "iconfont icon-Submit"
                                                                                            }, null, -1)
                                                                                        ])),
                                                                                    _: 1
                                                                                }, 8, [
                                                                                    "disabled"
                                                                                ])
                                                                            ]),
                                                                        default: a(()=>[
                                                                                y(" " + b(n(r)("common.submit")), 1)
                                                                            ]),
                                                                        _: 1
                                                                    })
                                                                ], 64)),
                                                                l(m, {
                                                                    trigger: "hover"
                                                                }, {
                                                                    trigger: a(()=>[
                                                                            l(c, {
                                                                                type: "primary",
                                                                                strong: "",
                                                                                bordered: "",
                                                                                secondary: "",
                                                                                class: "size-7",
                                                                                onClick: K
                                                                            }, {
                                                                                icon: a(()=>s[3] || (s[3] = [
                                                                                        _("i", {
                                                                                            class: "iconfont icon-Log text-[#0ec06a]"
                                                                                        }, null, -1)
                                                                                    ])),
                                                                                _: 1
                                                                            })
                                                                        ]),
                                                                    default: a(()=>[
                                                                            y(" " + b(n(r)("approveDetail.history")), 1)
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 1
                                                    })
                                                ]),
                                            _: 1
                                        })
                                    ]),
                                _: 1
                            }),
                            l(h, {
                                bordered: !1,
                                class: "proCard mt-2"
                            }, {
                                default: a(()=>[
                                        l(S, {
                                            onRegister: n(W),
                                            disabled: n(I)
                                        }, {
                                            attachmentSlot: a(({ model: f, field: g })=>[
                                                    (N(), L(w, {
                                                        key: f[g] ? f[g].url : "",
                                                        "default-file-list": f[g] ? [
                                                            f[g]
                                                        ] : [],
                                                        accept: ".pdf,.jpg,.png",
                                                        action: `${n(ge)().urlPrefix}${n(Te) ? "/system" : ""}/files`,
                                                        headers: {
                                                            timestamp: new Date().getTime(),
                                                            authorization: `${n(he).get(n(fe))}`
                                                        },
                                                        max: 1,
                                                        onRemove: (q)=>f[g] = null,
                                                        onError: Z,
                                                        onFinish: ({ file: q, event: Y })=>Q({
                                                                file: q,
                                                                event: Y
                                                            }, f, g)
                                                    }, {
                                                        default: a(()=>[
                                                                l(c, {
                                                                    class: "mt-[8px]"
                                                                }, {
                                                                    icon: a(()=>[
                                                                            l(n(be))
                                                                        ]),
                                                                    default: a(()=>[
                                                                            y(" " + b(n(r)("common.uploadText")), 1)
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 2
                                                    }, 1032, [
                                                        "default-file-list",
                                                        "action",
                                                        "headers",
                                                        "onRemove",
                                                        "onFinish"
                                                    ]))
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "onRegister",
                                            "disabled"
                                        ])
                                    ]),
                                _: 1
                            }),
                            l(n(we), {
                                ref_key: "historyModal",
                                ref: A,
                                busId: n(C),
                                moduleCode: "FinanceShipLedger",
                                subModuleCode: n(E)
                            }, null, 8, [
                                "busId",
                                "subModuleCode"
                            ])
                        ]),
                    _: 1
                });
            };
        }
    });
});
export { kt as default, __tla };
