import { WarningTypeEnum } from '@/components/EarlyWarning/config'
import Look from '@/components/EarlyWarning/look'
import { Badge, Space, Tag } from 'antd'
import React from 'react'
function tableConfigEw(type: string, addBlack: (valud: any) => void, remove: (value: any) => void, removeBlack: (value: any) => void, log: (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: '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) => {
                switch (type) {
                    case 'DEFAULT':
                        return <Space>
                            <a onClick={() => { addBlack(b) }}>加入黑名单</a>
                            <a onClick={() => { log(b) }}>告警日志</a>
                        </Space>
                    case 'ADGROUP':
                        return <Space>
                            <a onClick={() => { remove(b) }}>移除规则</a>
                            <a onClick={() => { log(b) }}>告警日志</a>
                        </Space>
                    case 'ACCOUNT':
                        return <Space>
                            <a onClick={() => { addBlack(b) }}>加入黑名单</a>
                            <a onClick={() => { log(b) }}>告警日志</a>
                        </Space>
                    case 'ADGROUP_BLACK_LIST':
                        <Space>
                            <a onClick={() => { removeBlack(b) }}>加入黑名单</a>
                        </Space>
                    default:
                        return null
                }
            }
        },
    ]
}
export default tableConfigEw