

import { Row, Col, Popconfirm, Badge } from "antd"
import WidthEllipsis from "@/components/widthEllipsis"
import React from "react"
import { conditionEnum, dataEnum, executeScopeEnum, monitorTimeEnum, operateTypeEnum, ruleDimensionEnum } from "./configModal"
import EnableConfig from "./enableConfig"

function columnsPos(
    accountList: any[],
    getChannelChoiceList: any,
    edit: (value: any, isCopy?: boolean) => void,
    del: (value: any) => void,
    handle: (value: any, type: string) => void,
) {

    let newArr: any = [
        {
            title: '规则名称',
            dataIndex: 'ruleName',
            key: 'ruleName',
            align: 'center',
            width: 100,
            fixed: true,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '规则类型',
            dataIndex: 'ruleType',
            key: 'ruleType',
            align: 'center',
            width: 90,
            fixed: true,
            render: (a: number, b: any) => {
                return {1: '个人规则'}[1]
            }
        },
        {
            title: '部门',
            dataIndex: 'department',
            key: 'department',
            align: 'center',
            width: 100,
            render: (a: number, b: any) => {
                return { 1: '游戏投放' }[a]
            }
        },
        {
            title: '游戏',
            dataIndex: 'gameName',
            key: 'gameName',
            align: 'center',
            width: 100,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '媒体',
            dataIndex: 'mediaType',
            key: 'mediaType',
            align: 'center',
            width: 100,
            render: (a: number) => {
                return { 1: '腾讯', 2: '头条' }[a]
            }
        },
        {
            title: '规则维度',
            dataIndex: 'ruleDimension',
            key: 'ruleDimension',
            width: 90,
            align: 'center',
            render: (a: number) => {
                return ruleDimensionEnum.find(item => item.value === a)?.label
            }
        },
        {
            title: '生效范围',
            dataIndex: 'effectiveScope',
            key: 'effectiveScope',
            width: 250,
            render: (a: number[], b: any) => {
                return <WidthEllipsis value={a?.map(item => {
                    if (b?.ruleDimension === 2) {
                        return getChannelChoiceList?.data?.find((i: { id: number }) => i.id === item)?.agentName
                    } else if (b?.ruleDimension === 3) {
                        let data = accountList?.find(i => i.value === item)
                        return data.label.toString() + (data.corporationName ? `_${data.corporationName}` : '')
                    }
                    return undefined
                }).toString()} />
            }
        },
        {
            title: '账号白名单',
            dataIndex: 'accountWhitelist',
            key: 'accountWhitelist',
            align: 'center',
            width: 120,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '广告白名单',
            dataIndex: 'adWhitelist',
            key: 'adWhitelist',
            align: 'center',
            width: 120,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '执行范围',
            dataIndex: 'executeScope',
            key: 'executeScope',
            align: 'center',
            width: 100,
            render: (a: number, b: any) => {
                return executeScopeEnum.find(item => item.value === a)?.label
            }
        },
        {
            title: '告警动作类型',
            dataIndex: 'operateType',
            key: 'operateType',
            align: 'center',
            width: 100,
            render: (a: number, b: any) => {
                return operateTypeEnum.find(item => item.value === a)?.label
            }
        },
        {
            title: '规则条件',
            dataIndex: 'ruleCondition',
            key: 'ruleCondition',
            width: 300,
            render: (a: any[], b: any) => {
                return <WidthEllipsis value={a.map(item => {
                    let monitorTimeName = monitorTimeEnum.find(i => i.value === item.monitorTimeType)?.label
                    let dataName = dataEnum.find(i => i.value === item.dataType)?.label
                    let conditionName = conditionEnum.find(i => i.value === item.conditionType)?.label
                    return `${monitorTimeName}-${dataName}-${conditionName}-${item.dataNum}`
                }).toString()} />
            }
        },
        {
            title: '创建人',
            dataIndex: 'createByName',
            key: 'createByName',
            align: 'center',
            width: 80,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 135,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '更新人',
            dataIndex: 'updateByName',
            key: 'updateByName',
            align: 'center',
            width: 80,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '更新时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            align: 'center',
            width: 135,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '规则启用状态',
            dataIndex: 'isStart',
            key: 'isStart',
            align: 'center',
            width: 60,
            fixed: 'right',
            render: (a: boolean, b: any) => {
                return <EnableConfig value={b} />
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 150,
            fixed: 'right',
            render: (a: string, b: any) => (
                <Row justify='center' gutter={[10, 0]}>
                    <Col><a style={{ fontSize: "12px" }} onClick={() => { edit(b) }}>修改</a></Col>
                    {/* <Col><a style={{ fontSize: "12px" }} onClick={() => { edit(b, true) }}>复制</a></Col> */}
                    <Col><a style={{ fontSize: "12px" }} onClick={() => { handle([b], 'bmd') }}>添加白名单</a></Col>
                    <Col>
                        <Popconfirm
                            title="确定删除?"
                            onConfirm={() => { del(b.id) }}
                            okText="是"
                            cancelText="否"
                        >
                            <a style={{ fontSize: "12px", color: 'red' }}>删除</a>
                        </Popconfirm>
                    </Col>
                </Row>
            )
        }
    ]
    return newArr
}


export default columnsPos