import { Badge, Button, Popconfirm, Space, Typography} from "antd";
import { ColumnsType } from "antd/es/table";
import { tableDfixed } from "@/utils/tableDfixed";
import Details from "./details";

let obj: any = {
    "send_corp_group_send": "群发",
    "send_corp_moment_send": "朋友圈发送",
    "send_corp_pull_group": "拉群任务",
    "send_corp_pull_group_otherA": "转移客户——拉客户",
    "send_corp_pull_group_otherB": "转移客户——拉群",
    "send_corp_pull_group_task": "建群任务",
    "send_corp_pull_group_transfer_task": "进群拉人",
    "send_delete_friend_task": "删除单向好友",
    "send_pull_external_user_task": "拉客户",
    "send_pull_fix_user_task": "拉固定客户",
    "send_pull_corp_user_task": "拉成员",
    "send_user_msg": "聚合聊天消息",
    "send_update": "同步企微信息",
    "send_disband_group_chat":"群解散",
    "forward_corp_group_send":"转发消息"
}

export function TableConfig(handleMsg: (ids: number[]) => void): ColumnsType<any> {
    let arr: ColumnsType<any> = [
        {
            title: '企业名称',
            dataIndex: 'corpName',
            key: 'corpName',
            width: 150,
            ellipsis: true,
            render(_, records) {
                return records?.corpUserVO?.corpName
            },
        },
        {
            title: '企业ID',
            dataIndex: 'corpId',
            key: 'corpId',
            width: 150,
            ellipsis: true,
            render(value) {
                return value
            },
        },
        {
            title: '企微号ID',
            dataIndex: 'name',
            key: 'name',
            width: 120,
            ellipsis: true,
            render(_, records) {
                return records?.corpUserVO?.name
            },
        },
        {
            title: '企微号ID',
            dataIndex: 'corpUserId',
            key: 'corpUserId',
            width: 150,
            ellipsis: true,
            render(value) {
                return <Typography.Text ellipsis copyable>{value}</Typography.Text>
            },
        },
        {
            title: '设备编号',
            dataIndex: 'phoneUuid',
            key: 'phoneUuid',
            width: 150,
            ellipsis: true,
            render(value) {
                return value
            },
        },
        {
            title: '状态',
            dataIndex: 'status',
            key: 'status',
            width: 150,
            render(value) {
                return value ? <Badge status="success" text="已处理" /> : <Badge status="error" text="未处理" />
            },
        },
        {
            title: '告警记录日期',
            dataIndex: 'recordDate',
            key: 'recordDate',
            align: 'center',
            width: 120,
            ellipsis: true,
        },
        {
            title: '处理人',
            dataIndex: 'handlerByVO',
            key: 'handlerByVO',
            align: 'center',
            width: 100,
            ellipsis: true,
            render(value) {
                return value?.nickname || '--'
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            fixed: 'right',
            width: 120,
            render: (_, b: any) => {
                return <Space wrap>
                    {!b?.status && <Popconfirm
                        title="确定处理告警？"
                        onConfirm={() => { handleMsg([b.id]) }}
                    >
                        <Button type="link" style={{ padding: 0 }} danger>处理告警</Button>
                    </Popconfirm>}
                    <Details data={b} />
                </Space>
            }
        },
    ]
    return tableDfixed(arr)
}


export function DetailsTableConfig(): ColumnsType<any> {
    let arr: ColumnsType<any> = [
        {
            title: '任务名称',
            dataIndex: 'taskName',
            key: 'taskName',
            width: 150,
            ellipsis: true
        },
        {
            title: '消息类型',
            dataIndex: 'msgType',
            key: 'msgType',
            width: 120,
            align: 'center',
            render(value) {
                return obj?.[value] || '--'
            },
        },
        {
            title: '手机消息ID',
            dataIndex: 'phoneMsgId',
            key: 'phoneMsgId',
            width: 120,
            align: 'center'
        },
        {
            title: '记录时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 120,
            ellipsis: true,
        }
    ]
    return tableDfixed(arr)
}