import { g as W, h as Z, i as G } from "./role-DXhO1zOz.js";
import { _ as H } from "./basicModal.vue_vue_type_script_setup_true_lang-CsJydKhW.js";
import "./basicModal.vue_vue_type_style_index_0_lang-8QZP7ApW.js";
import { u as J } from "./useModal-CO65vga3.js";
import { V as E, bk as w, Z as Q, ae as X, d as Y, r as u, u as ee, aw as le, c as T, o as N, w as n, j as t, t as oe, D as ae, _ as te, l as a, k as re, aA as ne, c8 as se, c9 as ue, p as R, A as k, __tla as __tla_0 } from "./index-9PRMimni.js";
import { B as P } from "./BasicSelect-C_uwzMkE.js";
let _e, ye;
let __tla = Promise.all([
    (()=>{
        try {
            return __tla_0;
        } catch  {}
    })()
]).then(async ()=>{
    let c, me, ie, x;
    ({ t: c } = E());
    me = w();
    ie = await W();
    x = (ie || []).map((s)=>({
            ...s,
            value: +s.value
        }));
    ye = [
        {
            title: "No.",
            key: "num",
            width: 60,
            render: (s, d)=>d + 1
        },
        {
            title: c("common.editPop.roleName"),
            key: "name"
        },
        {
            title: c("common.editPop.roleNameEn"),
            key: "nameEn"
        },
        {
            title: c("common.editPop.roleCode"),
            key: "code"
        },
        {
            title: c("common.editPop.roleType"),
            key: "roleType",
            render (s) {
                const d = x.find((p)=>+p.value == +s.roleType);
                return me.getLocale === "en" ? d?.labelEn : d?.label;
            }
        },
        {
            title: c("common.userController.status"),
            key: "status",
            render (s) {
                return Q(X, {
                    bordered: !1,
                    type: s.status == 1 ? "success" : "error"
                }, {
                    default: ()=>s.status == 1 ? "Enable" : "Disable"
                });
            }
        }
    ];
    _e = Y({
        __name: "CreateDrawer",
        props: {
            title: {
                type: String,
                default: ""
            },
            width: {
                type: Number,
                default: 450
            },
            permissionList: {
                type: Array
            }
        },
        emits: [
            "change",
            "success"
        ],
        setup (s, { expose: d, emit: p }) {
            const { t: o } = E(), I = w(), L = {
                roleCode: {
                    required: !0,
                    message: o("common.editPop.placeholderRoleCode"),
                    trigger: "blur"
                },
                roleName: {
                    required: !0,
                    message: o("common.editPop.placeholderRoleName"),
                    trigger: "blur"
                },
                nameEn: {
                    required: !0,
                    message: o("common.editPop.placeholderRoleNameEn"),
                    trigger: "blur"
                },
                roleType: {
                    required: !0,
                    trigger: [
                        "blur",
                        "change"
                    ],
                    validator: (m, l)=>l == null ? new Error(o("common.editPop.placeholderRoleType")) : !0
                }
            }, S = p, U = s, [D, { openModal: M, closeModal: y, setSubLoading: _ }] = J({
                title: U.title,
                subBtuText: o("common.okText"),
                cancelText: o("common.cancelText"),
                width: 650
            }), b = ()=>({
                    roleId: null,
                    roleName: "",
                    roleCode: "",
                    remark: "",
                    permissions: [],
                    permissionKeys: [],
                    status: 1,
                    roleType: null,
                    nameEn: "",
                    roleCategory: null,
                    categories: []
                }), v = u(null), C = ee();
            u([]);
            const g = u(null), V = u(!1);
            u(!1), u(!1), u(!1), u(), u();
            const e = u(b());
            function B() {
                e.value.roleCategory = null, e.value.categories = [];
            }
            function O() {
                e.value.categories = [];
            }
            function q(m) {
                return e.value.roleType || e.value.roleType === 0 ? +e.value?.roleType == 2 ? (m || []).filter((l)=>[
                        1,
                        2
                    ].includes(+l.value)) : (m || []).filter((l)=>![
                        1,
                        2
                    ].includes(+l.value)) : [];
            }
            async function A(m) {
                v.value = m, e.value.roleId = m;
                const l = await Z(v.value);
                e.value.roleName = l.name, e.value.nameEn = l.nameEn, e.value.roleCode = l.code, e.value.status = l.status, e.value.roleType = l.roleType, e.value.categories = l.categories, e.value.roleCategory = l.roleCategory, V.value = !0;
            }
            function F() {
                g.value.validate(async (m)=>{
                    if (m) _(!1), C.error(o("common.editPop.validateFail"));
                    else try {
                        await G({
                            name: e.value.roleName,
                            nameEn: e.value.nameEn,
                            code: e.value.roleCode,
                            roleType: Number(e.value.roleType),
                            status: e.value.status,
                            categories: e.value.categories,
                            roleCategory: e.value.roleCategory,
                            id: v.value
                        }), C.success(o("common.disablePop.success")), S("success"), y();
                    } catch  {
                        _(!1);
                    }
                });
            }
            function j() {
                g.value.restoreValidation(), e.value = Object.assign(e.value, b());
            }
            return le(()=>{}), d({
                openModal: M,
                closeModal: y,
                getInfo: A
            }), (m, l)=>{
                const f = re, i = te, $ = ne, h = ue, z = se, K = oe;
                return N(), T(a(H), {
                    onRegister: a(D),
                    ref: "modalRef",
                    onOnClose: j,
                    onOnOk: F
                }, {
                    default: n(()=>[
                            t(K, {
                                class: "mt-4",
                                model: e.value,
                                rules: L,
                                ref_key: "formRef",
                                ref: g,
                                "label-placement": "top",
                                "label-width": 80
                            }, {
                                default: n(()=>[
                                        t(i, {
                                            label: a(o)("common.editPop.roleCode"),
                                            path: "roleCode"
                                        }, {
                                            default: n(()=>[
                                                    t(f, {
                                                        placeholder: a(o)("common.editPop.placeholderRoleCode"),
                                                        value: e.value.roleCode,
                                                        "onUpdate:value": l[0] || (l[0] = (r)=>e.value.roleCode = r),
                                                        disabled: !!e.value.roleId
                                                    }, null, 8, [
                                                        "placeholder",
                                                        "value",
                                                        "disabled"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ]),
                                        t(i, {
                                            label: a(o)("common.editPop.roleName"),
                                            path: "roleName"
                                        }, {
                                            default: n(()=>[
                                                    t(f, {
                                                        placeholder: a(o)("common.editPop.placeholderRoleName"),
                                                        value: e.value.roleName,
                                                        "onUpdate:value": l[1] || (l[1] = (r)=>e.value.roleName = r)
                                                    }, null, 8, [
                                                        "placeholder",
                                                        "value"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ]),
                                        t(i, {
                                            label: a(o)("common.editPop.roleNameEn"),
                                            path: "nameEn"
                                        }, {
                                            default: n(()=>[
                                                    t(f, {
                                                        placeholder: a(o)("common.editPop.placeholderRoleNameEn"),
                                                        value: e.value.nameEn,
                                                        "onUpdate:value": l[2] || (l[2] = (r)=>e.value.nameEn = r)
                                                    }, null, 8, [
                                                        "placeholder",
                                                        "value"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ]),
                                        t(i, {
                                            label: a(o)("common.editPop.roleType"),
                                            path: "roleType"
                                        }, {
                                            default: n(()=>[
                                                    t($, {
                                                        value: e.value.roleType,
                                                        "onUpdate:value": [
                                                            l[3] || (l[3] = (r)=>e.value.roleType = r),
                                                            B
                                                        ],
                                                        options: a(x),
                                                        labelField: a(I).getLocale === "en" ? "labelEn" : "label"
                                                    }, null, 8, [
                                                        "value",
                                                        "options",
                                                        "labelField"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ]),
                                        t(i, {
                                            label: a(o)("common.editPop.roleCategory"),
                                            path: "roleCategory"
                                        }, {
                                            default: n(()=>[
                                                    t(a(P), {
                                                        value: e.value.roleCategory,
                                                        "onUpdate:value": [
                                                            l[4] || (l[4] = (r)=>e.value.roleCategory = r),
                                                            O
                                                        ],
                                                        "handle-option-item": q,
                                                        "option-type": "number",
                                                        "cache-key": "sys_role_category",
                                                        block: ""
                                                    }, null, 8, [
                                                        "value"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ]),
                                        +e.value.roleCategory == 4 ? (N(), T(i, {
                                            key: 0,
                                            label: a(o)("common.editPop.vesselCategory"),
                                            path: "categories"
                                        }, {
                                            default: n(()=>[
                                                    t(a(P), {
                                                        value: e.value.categories,
                                                        "onUpdate:value": l[5] || (l[5] = (r)=>e.value.categories = r),
                                                        "option-type": "number",
                                                        "cache-key": "shipCategory",
                                                        block: "",
                                                        multiple: ""
                                                    }, null, 8, [
                                                        "value"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ])) : ae("", !0),
                                        t(i, {
                                            label: a(o)("common.userController.status"),
                                            path: "status"
                                        }, {
                                            default: n(()=>[
                                                    t(z, {
                                                        value: e.value.status,
                                                        "onUpdate:value": l[6] || (l[6] = (r)=>e.value.status = r)
                                                    }, {
                                                        default: n(()=>[
                                                                t(h, {
                                                                    value: 1
                                                                }, {
                                                                    default: n(()=>[
                                                                            R(k(a(o)("common.userController.normal")), 1)
                                                                        ]),
                                                                    _: 1
                                                                }),
                                                                t(h, {
                                                                    value: 0
                                                                }, {
                                                                    default: n(()=>[
                                                                            R(k(a(o)("common.userController.disable")), 1)
                                                                        ]),
                                                                    _: 1
                                                                })
                                                            ]),
                                                        _: 1
                                                    }, 8, [
                                                        "value"
                                                    ])
                                                ]),
                                            _: 1
                                        }, 8, [
                                            "label"
                                        ])
                                    ]),
                                _: 1
                            }, 8, [
                                "model"
                            ])
                        ]),
                    _: 1
                }, 8, [
                    "onRegister"
                ]);
            };
        }
    });
});
export { _e as _, ye as c, __tla };
