import { ColumnsType } from "antd/lib/table";
import React from "react";
import AstraSupportHour from "./astraSupport‌Hour";
import { Space, Statistic } from "antd";
import AstraGroupHourEle from "./astraGroupHourEle";
import AstraGroupIndexEle from "./astraGroupIndexEle";
import DoubleDelDetails from "./doubleDelDetails";
import { POOLTYPEEle } from "../tencenTasset/corpWechat/csgroup/const";
import { FormOutlined } from "@ant-design/icons";
import GroupUserInfo from "../tencenTasset/corpWechat/csgroup/components/group/groupUserInfo";

/** 客服号加粉 */
export const CorpUserDayListTableConfig = (updateLimitAddFansOfDay: (data: any) => void): ColumnsType<never> => {

    return [
        {
            title: '日期',
            dataIndex: 'day',
            key: 'day',
            width: 80,
            ellipsis: true,
            align: 'center',
            fixed: 'left',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '企业名称',
            dataIndex: 'corpName',
            key: 'corpName',
            width: 100,
            ellipsis: true,
            fixed: 'left',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: '企业ID',
            dataIndex: 'corpId',
            key: 'corpId',
            width: 180,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服号名称',
            dataIndex: 'corpUserName',
            key: 'corpUserName',
            width: 100,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: '客服号ID',
            dataIndex: 'corpUserId',
            key: 'corpUserId',
            width: 100,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服号当前所在部门名称',
            dataIndex: 'localCorpUserDepartment',
            key: 'localCorpUserDepartment',
            width: 120,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服号当前归属的客服池',
            dataIndex: 'poolType',
            key: 'poolType',
            width: 140,
            ellipsis: true,
            align: 'center',
            render(value) {
                return POOLTYPEEle[value as keyof typeof POOLTYPEEle] || '--'
            },
        },
        {
            title: '新增用户数',
            dataIndex: 'addUserCount',
            key: 'addUserCount',
            width: 100,
            align: 'right',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12, color: (value >= 60 && value < 100) ? 'orange' : value > 100 ? 'red' : '#000000D9' }}>{value}</span>
            },
        },
        {
            title: '退出人数',
            dataIndex: 'outUserCount',
            key: 'outUserCount',
            width: 100,
            align: 'right',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '当前粉丝总数',
            dataIndex: 'corpExternalUserCount',
            key: 'corpExternalUserCount',
            width: 100,
            align: 'right',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服号单日限制加粉数量',
            dataIndex: 'limitAddFansOfDay',
            key: 'limitAddFansOfDay',
            width: 100,
            align: 'right',
            sorter: true,
            render(value, record: any) {
                return <Space>
                    <span style={{ fontSize: 12 }}>{(value || value === 0) ? value : '--'}</span>
                    {record?.signId && <a onClick={() => updateLimitAddFansOfDay(record)}><FormOutlined /></a>}
                </Space>
            },
        },
        {
            title: '客服号单日剩余加粉数量',
            dataIndex: 'remainAddFansOfDay',
            key: 'remainAddFansOfDay',
            width: 100,
            align: 'right',
            sorter: true,
            render(value) {
                return <span style={((value || value === 0) && value < 5) ? { fontSize: 12, color: 'red' } : { fontSize: 12 }}>{(value || value === 0) ? value : '--'}</span>
            },
        },
        {
            title: '客服号最新加粉时间',
            dataIndex: 'lastAddFansTime',
            key: 'lastAddFansTime',
            width: 130,
            align: 'center',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: '客服号最新加粉距今时间',
            dataIndex: 'lastAddFansAgoTimeStr',
            key: 'lastAddFansAgoTimeStr',
            width: 100,
            align: 'right',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: 'dn双删详情',
            dataIndex: 'dnOutUserCount',
            key: 'dnOutUserCount',
            width: 100,
            align: 'center',
            render(value, record: any) {
                return value && Object.keys(value).length > 0 ? <DoubleDelDetails
                    dnOutUserCount={value}
                    day={record.day}
                    corpName={record.corpName}
                    corpUserName={record.corpUserName}
                /> : '--'
            },
        },
        {
            title: '数据更新时间',
            dataIndex: 'dataTime',
            key: 'dataTime',
            width: 140,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },

        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 140,
            align: 'center',
            fixed: 'right',
            render(_, record: any) {
                return <Space>
                    <GroupUserInfo groupData={{
                        localCorpId: record.corpId,
                        csgroupName: record.corpName
                    }} />
                    <AstraSupportHour
                        corpName={record.corpName}
                        corpUserName={record.corpUserName}
                        data={{
                            corpId: record.corpId,
                            corpUserId: record.corpUserId,
                            day: record.day
                        }}
                    />
                </Space>
            },
        }
    ]
}

// 客服号消息

/** 客服组加粉 */
export const CorpUserLogTableConfig = (): ColumnsType<never> => {

    return [
        {
            title: 'UUID',
            dataIndex: 'uuid',
            key: 'uuid',
            width: 200,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '本地客服组ID',
            dataIndex: 'localCsgroupId',
            key: 'localCsgroupId',
            width: 60,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '策略ID',
            dataIndex: 'policyId',
            key: 'policyId',
            width: 60,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '操作类型',
            dataIndex: 'operType',
            key: 'operType',
            width: 85,
            align: 'center',
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '下线用户ID',
            dataIndex: 'outlineCorpUserId',
            key: 'outlineCorpUserId',
            width: 90,
            align: 'center',
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '下线用户归属池',
            dataIndex: 'outlinePoolType',
            key: 'outlinePoolType',
            width: 140,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{POOLTYPEEle[value as keyof typeof POOLTYPEEle] || '--'}</span>
            },
        },
        {
            title: '操作状态',
            dataIndex: 'operStatus',
            key: 'operStatus',
            width: 150,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: '操作原因',
            dataIndex: 'operMsg',
            key: 'operMsg',
            width: 450,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value || '--'}</span>
            },
        },
        {
            title: '数据更新时间',
            dataIndex: 'dataTime',
            key: 'dataTime',
            width: 120,
            ellipsis: true,
            align: 'center',
            sorter: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        }
    ]
}

/** 客服组加粉 */
export const LocalCsgroupDayListTableConfig = (): ColumnsType<never> => {

    return [
        {
            title: '日期',
            dataIndex: 'day',
            key: 'day',
            width: 80,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '企业名称',
            dataIndex: 'corpName',
            key: 'corpName',
            width: 100,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '本地客服组名称',
            dataIndex: 'localCsgroupName',
            key: 'localCsgroupName',
            width: 100,
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '本地客服组ID',
            dataIndex: 'localCsgroupId',
            key: 'localCsgroupId',
            width: 75,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },

        // {
        //     title: '消耗',
        //     dataIndex: 'cost',
        //     key: 'cost',
        //     width: 100,
        //     align: 'right',
        //     render(value) {
        //         return <Statistic value={value || 0} />
        //     },
        // },
        // {
        //     title: '加粉次数(广告)',
        //     dataIndex: 'scanFollowCount',
        //     key: 'scanFollowCount',
        //     width: 100,
        //     align: 'right',
        //     render(value) {
        //         return <span style={{ fontSize: 12 }}>{value}</span>
        //     },
        // },
        // {
        //     title: '加粉人数(广告)',
        //     dataIndex: 'scanFollowUserCount',
        //     key: 'scanFollowUserCount',
        //     width: 100,
        //     align: 'right',
        //     render(value) {
        //         return <span style={{ fontSize: 12 }}>{value}</span>
        //     },
        // },
        {
            title: '加粉人数',
            dataIndex: 'addUserCount',
            key: 'addUserCount',
            width: 100,
            align: 'right',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服组当日限制加粉数',
            dataIndex: 'limitAddFansOfDay',
            key: 'limitAddFansOfDay',
            width: 100,
            align: 'right',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '客服组当日剩余加粉数',
            dataIndex: 'surplusAddFansOfDay',
            key: 'surplusAddFansOfDay',
            width: 100,
            align: 'right',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '数据更新时间',
            dataIndex: 'dataTime',
            key: 'dataTime',
            width: 140,
            ellipsis: true,
            align: 'center',
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            },
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 250,
            ellipsis: true,
            render(_, record: any) {
                return <Space>
                    <AstraGroupHourEle
                        localCsgroupName={record.localCsgroupName}
                        data={{
                            day: record.day,
                            localCsgroupId: record.localCsgroupId
                        }}
                    />
                    <AstraGroupIndexEle
                        localCsgroupName={record.localCsgroupName}
                        data={{
                            day: record.day,
                            localCsgroupId: record.localCsgroupId
                        }}
                    />
                </Space>
            }
        }
    ]
}