import { AdStatusEnum, BidModeEnum, BidStrategyEnum, OptimizationGoalEnum, PromotedObjectType } from '@/services/launchAdq/enum'
import React from 'react'
import { Badge, Popover, Space } from 'antd'
import Box from '@/pages/adMonitor/adMonitorList/components/box'
import SwitchStatus from './switchStatus'
import TimeSeriesLook from './timeSeriesLook'
import { ReactComponent as RocketSvg } from '@/assets/rocket.svg'
import '../index.less'
import { copy } from '@/utils/utils'
import InputUpdate from './inputUpdate'
function tableConfig(
    onChange: () => void,
    details: (data: any) => void,
    handleSave: (data: any) => void,
    handleSaveDaily: (data: any) => void
): any {
    return [
        {
            title: '启停',
            dataIndex: 'configuredStatus',
            key: 'configuredStatus',
            align: 'center',
            width: 40,
            fixed: 'left',
            render: (a: string, b: any) => {
                return <SwitchStatus configuredStatus={a} isDeleted={b?.isDeleted} adgroupId={b?.adgroupId} onChange={onChange} />
            }
        },
        {
            title: '所属账号',
            dataIndex: 'accountId',
            key: 'accountId',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: string) => {
                return <Space>
                    <a onClick={() => copy(a)} >{a}</a>
                </Space>
            }
        },
        {
            title: '腾讯备注',
            dataIndex: 'memo',
            key: 'memo',
            align: 'center',
            width: 80,
            ellipsis: true,
        },
        {
            title: '本地备注',
            dataIndex: 'remark',
            key: 'remark',
            align: 'center',
            width: 80,
            ellipsis: true,
        },
        {
            title: '广告ID',
            dataIndex: 'adgroupId',
            key: 'adgroupId',
            align: 'center',
            width: 100,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <Space>
                    <a onClick={() => copy(a)} >{a}</a>
                </Space>
            }
        },
        {
            title: '所属计划ID',
            dataIndex: 'campaignId',
            key: 'campaignId',
            align: 'center',
            width: 100,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <Space >
                    <a onClick={() => copy(a)} >{a}</a>
                </Space>
            }
        },
        {
            title: '投手',
            dataIndex: 'putUserName',
            key: 'putUserName',
            align: 'center',
            width: 70,
            ellipsis: true
        },
        {
            title: '广告名称',
            dataIndex: 'adgroupName',
            key: 'adgroupName',
            width: 280,
            ellipsis: true,
            render: (a: string, b: any) => {
                return <InputUpdate title={a} dataIndex={'adgroupName'} record={b} handleSave={handleSave} />
            }
        },
        {
            title: '推广目标类型',
            dataIndex: 'promotedObjectType',
            key: 'promotedObjectType',
            align: 'center',
            width: 75,
            ellipsis: true,
            render: (a: string | number) => {
                return PromotedObjectType[a]
            }
        },
        {
            title: '投放日期',
            dataIndex: 'beginDate',
            key: 'beginDate',
            align: 'center',
            width: 150,
            ellipsis: true,
            render: (a: string, b: { endDate: string }) => {
                return b?.endDate ? a + '~' + b.endDate : a + '~' + '长期投放'
            }
        },
        {
            title: '投放时间',
            dataIndex: 'timeSeries',
            key: 'timeSeries',
            align: 'center',
            width: 55,
            render: (a: string, b: { endDate: string }) => {
                return <TimeSeriesLook timeSeries={a} />
            }
        },
        {
            title: '首日开始投放时间',
            dataIndex: 'firstDayBeginTime',
            key: 'firstDayBeginTime',
            align: 'center',
            width: 70,
        },
        {
            title: '出价',
            dataIndex: 'bidAmount',
            key: 'bidAmount',
            width: 140,
            ellipsis: true,
            render: (a: string, b: { bidMode: string, optimizationGoal: string }) => {
                return `${BidModeEnum[b?.bidMode]} ${a}元/${b?.bidMode === 'BID_MODE_CPM' ? '千次曝光' : b?.bidMode === 'BID_MODE_CPC' ? '点击' : OptimizationGoalEnum[b?.optimizationGoal]}`
            }
        },
        {
            title: '深度优化ROI',
            dataIndex: 'expectedRoi',
            key: 'expectedRoi',
            width: 70,
            align: 'center',
            ellipsis: true,
            render: (a: string, b: { deepConversionSpec: any }) => {
                return b?.deepConversionSpec?.deepConversionWorthSpec?.expectedRoi || '--'
            }
        },
        {
            title: '出价类型',
            dataIndex: 'smartBidType',
            key: 'smartBidType',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: string, b: { endDate: string }) => {
                return a === 'SMART_BID_TYPE_CUSTOM' ? '手动出价' : '自动出价'
            }
        },
        {
            title: '出价类型',
            dataIndex: 'bidStrategy',
            key: 'bidStrategy',
            align: 'center',
            width: 70,
            ellipsis: true,
            render: (a: string, b: { endDate: string }) => {
                return BidStrategyEnum[a]
            }
        },
        {
            title: '广告组日预算(元)',
            dataIndex: 'dailyBudget',
            key: 'dailyBudget',
            align: 'center',
            width: 70,
            render: (a: string, b: any) => {
                return <InputUpdate title={a} isNum={true} dataIndex={'dailyBudget'} record={b} handleSave={handleSaveDaily} />
            }
        },
        {
            title: '是否开启自动版位功能',
            dataIndex: 'automaticSiteEnabled',
            key: 'automaticSiteEnabled',
            align: 'center',
            width: 80,
            render: (a: any, b: any) => {
                return a ? '开' : '关'
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createdTime',
            key: 'createdTime',
            align: 'center',
            width: 140,
            ellipsis: true,
        },
        {
            title: '是否已删除',
            dataIndex: 'isDeleted',
            key: 'isDeleted',
            align: 'center',
            width: 60,
            render: (a: any, b: any) => {
                return <Badge status={!a ? "processing" : "error"} text={a ? '是' : '否'} />
            }
        },
        {
            title: '广告状态',
            dataIndex: 'status',
            key: 'status',
            align: 'center',
            width: 70,
            fixed: 'right',
            ellipsis: true,
            render: (a: string, b: any) => {
                return b?.rejectMessageList?.filter((str: any) => str)?.length > 0 ? <Popover
                    style={{ width: 500 }}
                    overlayStyle={{ width: 500, fontSize: 12 }}
                    placement="left"
                    content={b?.rejectMessageList?.map((str: string, eq: number) => {
                        return str ? <><strong style={{ fontSize: 13 }}>{eq + 1}:</strong>{str}<br /></> : ""
                    })}>
                    {AdStatusEnum[a]}
                </Popover> :
                    AdStatusEnum[a]
            }
        },
        {
            title: '创意预览',
            dataIndex: 'creativePreview',
            key: 'creativePreview',
            width: 70,
            align: 'center',
            fixed: 'right',
            render: (a: any, b: any) => {
                return <Box b={[{ creativePreview: a }]} />
            }
        },
        {
            title: '广告详情',
            dataIndex: 'costSpeed',
            key: 'costSpeed',
            align: 'center',
            width: 80,
            className: 'padding2',
            fixed: 'right',
            render: (a: any, b: any) => {
                return <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', lineHeight: 'normal', fontSize: 10 }}>
                    <RocketSvg /> <a onClick={() => details(b)} style={{ marginLeft: 10 }}>详情</a>
                </div>
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 65,
            align: 'center',
            fixed: 'right',
            render: (a: any, b: any) => {
                return <a style={{ color: '#1890ff' }} onClick={() => window.open(`https://ad.qq.com/atlas/${b?.accountId}/admanage/adgroup?tab=adgroup&query={%22operation_status%22:[%22CALCULATE_STATUS_EXCLUDE_DEL%22],%22system_status%22:[],%22search_name%22:%22${b.adgroupId}%22}`)} target="_blank">腾讯广告</a>
            }
        },
    ]
}
export default tableConfig