import { ProColumns } from "@ant-design/pro-components";
import {  Space, Switch } from "antd";
import BookList from '../bookList';
import LoginList from "../loginList";

export const columns = (params: { enumList: { [key: string]: any },  upDate: (params: { id: any, enabled: boolean }) => void }): ProColumns<any>[] => {
    let { enumList, upDate } = params
    return [
        {
            title: "openId",
            dataIndex: 'openId',
            key: "openId",
            align: "center",
            // hideInSearch: true,
        },
        {
            title: "unionId",
            dataIndex: 'unionId',
            key: "unionId",
            align: "center",
        },
        {
            title: "用户昵称",
            dataIndex: 'nickname',
            key: "nickname",
            align: "center",
        },
        {
            title: "手机号",
            dataIndex: 'phoneNum',
            key: "phoneNum",
            hideInSearch: true,
            align: "center",
        },
        {
            title: "用户身份",
            dataIndex: 'userStanding',
            key: "userStanding",
            valueType: 'select',
            valueEnum: new Map(enumList?.USER_STANDING?.values?.map(({ value, description }: any) => [value, description])),
            align: "center",
            render: (a: any, b: any) => {
                let arr: any = new Map(enumList?.USER_STANDING?.values?.map(({ value, description }: any) => [value, description]))
                return arr.get(b?.userStanding) || '-'
            }
        },
        {
            title: "累计充值金额",
            dataIndex: 'chargeAmount',
            key: "chargeAmount",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.chargeAmount
            }
        },
        {
            title: "累计充值次数",
            dataIndex: 'chargeNum',
            key: "chargeNum",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.chargeNum
            }
        },
        {
            title: "书币余额",
            dataIndex: 'coinNumMin',
            key: "coinNumMin",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.coinNum
            }
        },
        {
            title: "VIP到期时间",
            dataIndex: 'vipExpireTime',
            key: "vipExpireTime",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.vipExpireTime || '-'
            }
        },
        {
            title: "用户来源",
            dataIndex: 'userSource',
            key: "userSource",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.userSource || '-'
            }
        },
        {
            title: "登录设备",
            dataIndex: 'osType',
            key: "osType",
            valueType: 'digit',
            align: "center",
            render:(a,b)=>{
                return b?.osType || '-'
            }
        },
        {
            title: "最近登录IP",
            dataIndex: 'lastLoginIp',
            key: "lastLoginIp",
            align: "center",
            hideInSearch: true,
        },
        {
            title: "最近登录时间",
            dataIndex: 'lastLoginTime',
            key: "lastLoginTime",
            align: "center",
            hideInSearch: true,
        },
        {
            title: "注册时间",
            dataIndex: 'createTime',
            key: "createTime",
            hideInSearch: true,
            align: "center",
        },
        {
            title: "更新时间",
            dataIndex: 'updateTime',
            key: "updateTime",
            hideInSearch: true,
            align: "center",
        },
        {
            title: "状态",
            dataIndex: 'enabled',
            key: "enabled",
            align: "center",
            valueType: 'select',
            valueEnum: { true: "正常", false: "禁用" },
            render: (a, b) => {
                return <Switch checked={b.enabled} size="default" checkedChildren="正常" unCheckedChildren="禁用" onChange={(enabled) => { upDate({ id: b.id, enabled }) }} />
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 90,
            ellipsis: true,
            align: 'center',
            hideInSearch: true,
            render: (a: any, b: any) => {
                return <Space size={0}>
                    <BookList data={b} />
                    <LoginList data={b} />
                </Space>
            }
        },
        // 搜索条件
        {
            title: "最早登录时间",
            dataIndex: 'lastLoginTimeMin',
            valueType: 'date',
            hideInTable: true
        },
        {
            title: "最晚登录时间",
            dataIndex: 'lastLoginTimeMax',
            valueType: 'date',
            hideInTable: true
        },
        {
            title: "注册开始时间",
            dataIndex: 'startTime',
            valueType: 'date',
            hideInTable: true
        },
        {
            title: "注册结束时间",
            dataIndex: 'endTime',
            valueType: 'date',
            hideInTable: true
        },

    ];
}