import { _ as A } 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 E } from "./BasicForm-dL_oCSPM.js";
import { _ as U } from "./TableSelect.vue_vue_type_script_setup_true_lang-BAU5mgvB.js";
import { V as x, bk as W, gD as D, d as $, f as G, r as m, c as K, o as Z, l as n, w as M, j as _, ds as z, cZ as H, ac as J, __tla as __tla_0 } from "./index-9PRMimni.js";
import { o as Q, p as X } from "./victualingDetail-CLhgLkA4.js";
import { g as Y } from "./goodsReceiptNoteDetail-DWFnSNrx.js";
import { g as ee } from "./equipmentMainLibrary-bJTzj5mC.js";
import { u as oe } from "./useForm-CKmgcynv.js";
import { u as te } from "./useModal-CO65vga3.js";
let Pe;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    const I = W(), ae = await ee("currency"), { t: o } = x(), re = {
        gridProps: {
            cols: "2"
        },
        labelWidth: 80,
        submitButtonText: o("common.searchText"),
        showAdvancedButton: !1,
        schemas: [
            {
                field: "namePrefix",
                component: "NInput",
                label: o("common.portModal.port")
            }
        ]
    };
    function ne() {
        return [
            {
                title: o("common.portModal.port"),
                key: "port"
            },
            {
                title: o("common.portModal.country"),
                key: "country"
            }
        ];
    }
    function se({ startDate: a, endDate: c, currencyDisabled: f = !1 }) {
        return [
            {
                field: "id",
                hidden: !0
            },
            {
                field: "portName",
                label: o("victualingDetail.provisionInventory.addPortModal.port"),
                slot: "portSlot",
                rules: [
                    {
                        required: !0,
                        message: o("victualingDetail.provisionInventory.addPortModal.portRequired")
                    }
                ]
            },
            {
                field: "purchaseDate",
                component: "NDatePicker",
                label: o("victualingDetail.provisionInventory.addPortModal.purchaseDate"),
                defaultValue: a,
                componentProps: {
                    type: "date",
                    valueFormat: "yyyy-MM-dd",
                    placeholder: o("victualingDetail.provisionInventory.addPortModal.purchaseDate"),
                    isDateDisabled: (t)=>{
                        if (a && c) {
                            const u = D(a), d = D(c);
                            return t < u.toDate() || t > d.toDate();
                        }
                    }
                },
                rules: [
                    {
                        required: !0,
                        message: o("victualingDetail.provisionInventory.addPortModal.dateRequired")
                    }
                ]
            },
            {
                field: "currency",
                component: "NSelect",
                label: o("victualingDetail.provisionInventory.addPortModal.currency"),
                componentProps: {
                    labelField: I.getLocale === "en" ? "labelEn" : "label",
                    placeholder: o("victualingDetail.provisionInventory.addPortModal.currency"),
                    disabled: f,
                    options: ae
                },
                rules: [
                    {
                        required: !0,
                        message: o("victualingDetail.provisionInventory.addPortModal.currencyRequired")
                    }
                ]
            }
        ];
    }
    function ie({ data: a }) {
        return a ? {
            ...a
        } : {};
    }
    Pe = $({
        __name: "index",
        emits: [
            "refresh"
        ],
        setup (a, { expose: c, emit: f }) {
            const { t } = x(), u = H(), d = G(), T = f, { startDate: w, endDate: F } = d.query, h = m("add"), p = m({}), k = m({}), b = m(!1);
            function R(e) {
                k.value = e;
            }
            function S(e) {
                return Y({
                    ...e,
                    ...n(p)
                });
            }
            const [V, { submit: q, setFieldsValue: B }] = oe({
                schemas: se({
                    startDate: w,
                    endDate: F,
                    currencyDisabled: b
                }),
                labelWidth: "auto",
                gridProps: {
                    cols: 3
                }
            }), [O, { openModal: N, closeModal: C, setSubLoading: v }] = te({
                title: t("victualingDetail.provisionInventory.addPortModal.title"),
                subBtuText: t("common.okText"),
                cancelText: t("common.cancelText"),
                width: 800
            });
            async function L() {
                try {
                    const e = await q();
                    if (!e) {
                        v(!1);
                        return;
                    }
                    const { shipId: s, year: g, month: y } = d.query, P = {
                        add: X,
                        edit: Q
                    }[h.value];
                    await P({
                        shipId: s,
                        year: g,
                        month: y,
                        ...e
                    }).then((r)=>{
                        const i = I.getLocale === "en" ? "tipNameEn" : "tipName";
                        return r?.hasOwnProperty(i) && r[i] !== null ? (u.warning(r[i]), Promise.reject()) : r;
                    }), u.success(t("common.optionsAddSuccessText")), v(!1), T("refresh"), C();
                } catch (e) {
                    console.error(e), v(!1);
                }
            }
            function j({ type: e, record: s } = {
                type: "add"
            }) {
                h.value = e, b.value = e === "edit", N(), e === "edit" && J(()=>{
                    B(ie({
                        data: s
                    }));
                });
            }
            return c({
                handleOpenModal: j
            }), (e, s)=>{
                const g = U, y = E, P = A;
                return Z(), K(P, {
                    onRegister: n(O),
                    onOnOk: L
                }, {
                    default: M(()=>[
                            _(y, {
                                onRegister: n(V),
                                showActionButtonGroup: !1
                            }, {
                                portSlot: M(({ model: r, field: i })=>[
                                        _(g, {
                                            class: "w-full",
                                            labelField: "port",
                                            valueField: "id",
                                            value: r[i],
                                            "onUpdate:value": (l)=>r[i] = l,
                                            formValues: n(p),
                                            "onUpdate:formValues": s[0] || (s[0] = (l)=>z(p) ? p.value = l : null),
                                            onChange: R,
                                            multiple: !1,
                                            formProps: n(re),
                                            disabled: !1,
                                            selectTitle: n(t)("victualingDetail.provisionInventory.addPortModal.selectPort"),
                                            tableProps: {
                                                rowKey: (l)=>l.id,
                                                request: S,
                                                columns: n(ne)(),
                                                pagination: {
                                                    simple: !0
                                                }
                                            }
                                        }, null, 8, [
                                            "value",
                                            "onUpdate:value",
                                            "formValues",
                                            "formProps",
                                            "selectTitle",
                                            "tableProps"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "onRegister"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { Pe as _, __tla };
