import { ProColumns } from "@ant-design/pro-components";
import { useModel } from "@umijs/max";
import { Badge, Button, Image, Space, Tag } from "antd";
import PopUp from "./popUp";

export const columns = (sync: (id: any) => void): ProColumns<any>[] => {
    const { getEnum } = useModel("global")
    return [
        {
            title: "企微名称",
            dataIndex: 'corpName',
            key: "corpName",
            align: "center",
            width:100,
            ellipsis:true,
            fixed: 'left'
        },
        {
            title: "企微ID",
            dataIndex: 'corpId',
            key: "corpId",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "授权方企业类型",
            dataIndex: 'corpType',
            key: "corpType",
            hideInSearch: true,
            align: "center",
            width:100,
            ellipsis:true,
            valueEnum: getEnum("CORPTYPE", "map")
        },
        {
            title: "授权方企业用户规模",
            dataIndex: 'corpUserMax',
            key: "corpUserMax",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "授权方企业的主体名称",
            dataIndex: 'corpFullName',
            key: "corpFullName",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "认证到期时间",
            dataIndex: 'verifiedEndTime',
            key: "verifiedEndTime",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "企业类型",
            dataIndex: 'subjectType',
            key: "subjectType",
            hideInSearch: true,
            align: "center",
            width:100,
            ellipsis:true,
            valueEnum: getEnum("SUBJECTTYPE", "map")
        },
        {
            title: "企业规模",
            dataIndex: 'corpScale',
            key: "corpScale",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "所属行业",
            dataIndex: 'corpIndustry',
            key: "corpIndustry",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "所属子行业",
            dataIndex: 'corpSubIndustry',
            key: "corpSubIndustry",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "授权方应用id",
            dataIndex: 'agentId',
            key: "agentId",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "所属分销商账号id",
            dataIndex: 'authDistributorAccountId',
            key: "authDistributorAccountId",
            hideInSearch: true,
            width:100,
            ellipsis:true,
            align: "center",
        },
        {
            title: "授权状态",
            dataIndex: 'authStatus',
            key: "authStatus",
            align: "center",
            width:100,
            ellipsis:true,
            valueEnum(row) {
                return { "1": { text: <Badge status="success" text="授权成功" /> }, "-1": { text: <Badge status="error" text="取消授权" /> } }
            },
        },
        {
            title: "授权时间",
            dataIndex: 'createTime',
            key: "createTime",
            hideInSearch: true,
            align: "center",
            width:100,
            ellipsis:true,
        },
        {
            title: "关注二维码",
            tooltip: "授权企业在微信插件（原企业号）的二维码，可用于关注微信插件",
            dataIndex: 'corpWxQrcode',
            key: "corpWxQrcode",
            hideInSearch: true,
            align: "center",
            ellipsis:true,
            width: 120,
            render: (_, row) => {
                return <Image src={row?.corpWxQrcode} style={{ width: 20 }} />
            }
        },
        {
            title: "操作",
            dataIndex: 'option',
            valueType: 'option',
            align: "center",
            width: 90,
            render: (_, record) => {
                return <Space>
                    <Button onClick={() => { sync(record?.corpId) }} type="link" size="small">同步</Button>
                    <PopUp corpId={record?.corpId} corpName={record?.corpName} />
                </Space>
            },
        },
    ];
}

export function PopUpColumns(): ProColumns<any>[] {
    const { getEnum } = useModel("global")
    return [
        {
            title: "企微客服id",
            dataIndex: 'corpUserId',
            key: "corpUserId",
            hideInSearch: true,
            align: "center",
        },
        {
            title: "企微客服名称",
            dataIndex: 'name',
            key: "name",
            align: "center",
        },
        {
            title: "性别",
            dataIndex: 'gender',
            key: "gender",
            align: "center",
            hideInSearch: true,
            valueEnum(row) {
                return { 0: { text: <Tag >未知</Tag> }, 1: { text: <Tag color="green">男</Tag> }, 2: { text: <Tag color="red">女</Tag> } }
            },
        },
        {
            title: "分销商账号",
            dataIndex: 'distributorAccountName',
            key: "distributorAccountName",
            hideInSearch: true,
            align: "center",
        },
        {
            title: "状态",
            dataIndex: 'status',
            key: "status",
            hideInSearch: true,
            align: "center",
            valueEnum:()=>{
                let obj = getEnum("CORPSTATE", "obj")
                let colors = ["success","error","default","warning"]
                Object.keys(obj).forEach((key:any,index)=>{
                    obj[key] = {
                        text:<Tag color={colors[index]}>{obj[key].text}</Tag>
                    }
                })
                return obj
            }
        },
    ]
}