import {
    apiGet,
    formCreatedUserAndModifiedUser,
    horizontalFormOptions,
    mappingField,
    userRoleMapping,
    userStateMapping
} from "../constants.js";

const dialogBody = [
    {
        type: 'input-email',
        name: 'username',
        label: '邮箱',
    },
    {
        type: 'group',
        body: [
            {
                type: 'control',
                label: '角色',
                body: mappingField('role', '角色', userRoleMapping, 120),
            },
            {
                type: 'control',
                label: '账号状态',
                body: mappingField('state', '账号状态', userStateMapping),
            }
        ]
    },
    ...formCreatedUserAndModifiedUser(),
    {
        type: 'group',
        body: [
            {
                type: 'input-text',
                name: 'checkedUsername',
                label: '审核人',
            },
            {
                type: 'input-datetime',
                name: 'checkedTime',
                label: '审核时间',
            },
        ]
    },
]

export function userDetailDialog() {
    return {
        actionType: 'dialog',
        dialog: {
            title: '账号详情',
            actions: [],
            size: 'md',
            body: {
                type: 'form',
                initApi: apiGet('${base}/user_management/detail/${username}'),
                ...horizontalFormOptions(),
                horizontal: {
                    left: 2,
                },
                static: true,
                body: [
                    ...dialogBody,
                    {
                        type: 'input-datetime',
                        name: 'lastLoginTime',
                        label: '上次登陆时间',
                    },
                ],
            }
        }
    }
}

export function userCheckDialog() {
    return {
        actionType: 'dialog',
        dialog: {
            title: '账号审核',
            actions: [
                {
                    type: 'action',
                    label: '同意',
                    level: 'primary',
                    actionType: 'submit',
                    confirmTitle: '审核通过',
                    confirmText: '确认通过账号为${username}通过审核吗？审核通过后将无法撤销。',
                },
            ],
            size: 'md',
            body: {
                type: 'form',
                api: apiGet('${base}/user_management/check/${username}'),
                initApi: apiGet('${base}/user_management/detail/${username}'),
                ...horizontalFormOptions(),
                horizontal: {
                    left: 2,
                },
                static: true,
                body: dialogBody,
            }
        }
    }
}