import { Badge, Popconfirm, Space, Tag } from 'antd'
import React from 'react'
import { WarningTypeEnum } from './config'
import Look from './look'
import { OperationTypeObj } from './ruleLog'
import { copy } from '@/utils/utils'
function tableConfig(edit: (data: any) => void, del: (id: number) => void, log: (value: any) => void, details: (value: any) => void): any {
    return [
        {
            title: 'ID',
            dataIndex: 'id',
            key: 'id',
            align: 'center',
            width: 50,
        },
        {
            title: '规则名称',
            dataIndex: 'ruleName',
            key: 'ruleName',
            width: 120,
            ellipsis: true,
        },
        {
            title: '通知频率',
            dataIndex: 'notifyFrequency',
            key: 'notifyFrequency',
            align: 'center',
            width: 70,
            render: (a: string, b: any) => {
                return <span>{a}分钟</span>
            }
        },
        {
            title: '告警方式',
            dataIndex: 'warningType',
            key: 'warningType',
            align: 'center',
            width: 115,
            render: (a: string[], b: any) => {
                return a?.map((item, index) => <Tag color={['#f50', '#2db7f5'][index]} key={index}>{WarningTypeEnum[item]}</Tag>)
            }
        },
        {
            title: '是否默认规则',
            dataIndex: 'defaultRule',
            key: 'defaultRule',
            align: 'center',
            width: 80,
            render: (a: 0 | 1, b: any) => {
                return <Badge status={a ? 'success' : 'error'} text={a ? '是' : '否'} />
            }
        },
        {
            title: 'Enable?',
            dataIndex: 'enable',
            key: 'enable',
            align: 'center',
            width: 70,
            render: (a: 0 | 1, b: any) => {
                return <Badge status={{ '0': 'error', '1': 'success' }[a] as any} text={{ '0': '否', '1': '是' }[a]} />
            }
        },
        {
            title: '查看',
            dataIndex: 'rules',
            key: 'rules',
            align: 'center',
            width: 60,
            render: (a: any, b: any) => {
                return <Look rules={a}/>
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 80,
            render: (a: 0 | 1, b: any) => {
                return <Space>
                    <a onClick={() => edit(b)}>修改</a>
                    <a onClick={() => log(b)}>日志</a>
                    <a onClick={() => details(b)}>详情</a>
                    <Popconfirm
                        title="确定删除"
                        onConfirm={() => del(b?.id)}
                        okText="Yes"
                        cancelText="No"
                    >
                        <a style={{ color: 'red' }}>删除</a>
                    </Popconfirm>
                </Space>
            }
        },
    ]
}


export function ruleLogTableConfig(): any {

    return [
        {
            title: '广告账号',
            dataIndex: 'accountId',
            key: 'accountId',
            align: 'center',
            width: 80,
        },
        {
            title: '广告名字',
            dataIndex: 'adgroupName',
            key: 'adgroupName',
            width: 140,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '广告ID',
            dataIndex: 'adgroupId',
            key: 'adgroupId',
            width: 90,
            align: 'center',
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '操作内容',
            dataIndex: 'operationContext',
            key: 'operationContext',
            width: 120,
            ellipsis: true,
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '操作类型',
            dataIndex: 'operationType',
            key: 'operationType',
            width: 90,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return OperationTypeObj[a]
            }
        },
        {
            title: '操作执行状态',
            dataIndex: 'operationStatus',
            key: 'operationStatus',
            width: 95,
            align: 'center',
            render: (a: number, b: any) => {
                return a === 0 ? <Badge status="default" text="等待执行" /> : a === 100 ? <Badge status="success" text="发送成功" /> : <Badge status="error" text="发送失败" />
            }
        },
        {
            title: '操作发生时间',
            dataIndex: 'createTime',
            key: 'createTime',
            width: 140,
            align: 'center',
            ellipsis: true,
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '操作执行时间',
            dataIndex: 'executionTime',
            key: 'executionTime',
            width: 140,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '告警内容',
            dataIndex: 'sendMsg',
            key: 'sendMsg',
            width: 200,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '失败原因',
            dataIndex: 'failMsg',
            key: 'failMsg',
            width: 250,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
    ]
}

export function ruleAdLogTableConfig(): any {

    return [
        {
            title: '广告账号',
            dataIndex: 'accountId',
            key: 'accountId',
            align: 'center',
            width: 80,
        },
        {
            title: '规则名称',
            dataIndex: 'ruleName',
            key: 'ruleName',
            width: 140,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '规则ID',
            dataIndex: 'ruleId',
            key: 'ruleId',
            width: 90,
            align: 'center',
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '操作内容',
            dataIndex: 'operationContext',
            key: 'operationContext',
            width: 120,
            ellipsis: true,
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '操作类型',
            dataIndex: 'operationType',
            key: 'operationType',
            width: 90,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return OperationTypeObj[a]
            }
        },
        {
            title: '操作执行状态',
            dataIndex: 'operationStatus',
            key: 'operationStatus',
            width: 95,
            align: 'center',
            render: (a: number, b: any) => {
                return a === 0 ? <Badge status="default" text="等待执行" /> : a === 100 ? <Badge status="success" text="发送成功" /> : <Badge status="error" text="发送失败" />
            }
        },
        {
            title: '操作发生时间',
            dataIndex: 'createTime',
            key: 'createTime',
            width: 140,
            align: 'center',
            ellipsis: true,
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '操作执行时间',
            dataIndex: 'executionTime',
            key: 'executionTime',
            width: 140,
            ellipsis: true,
            align: 'center',
            render: (a: string, b: any) => {
                return a || '--'
            }
        },
        {
            title: '告警内容',
            dataIndex: 'sendMsg',
            key: 'sendMsg',
            width: 200,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
        {
            title: '失败原因',
            dataIndex: 'failMsg',
            key: 'failMsg',
            width: 250,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <a onClick={() => copy(a)}>{a || '--'}</a> 
            }
        },
    ]
}
export default tableConfig