import { BidStrategyEnum } from '@/services/launchAdq/enum'
import React from 'react'
import { Badge, Space } from 'antd'
import '../index.less'
import { copy } from '@/utils/utils'
import { ADGROUP_STATUS } from '../const'
import SwitchStatus from './switchStatus'
import TimeSeriesLook from '@/pages/launchSystemNew/adq/ad/timeSeriesLook'
import CreativePreview from '../../adMonitorListV3/CreativePreview'
import { BID_MODE_ENUM, OPTIMIZATIONGOAL_ENUM } from '../../tencentAdPutIn/const'
function tableConfig(onChange: () => void, creativeHandle?: (id: number) => void): any {
    return [
        {
            title: '启停',
            dataIndex: 'configuredStatus',
            key: 'configuredStatus',
            align: 'center',
            width: 40,
            fixed: 'left',
            render: (a: string, b: any) => {
                return <SwitchStatus configuredStatus={a} accountId={b?.accountId} 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,
            render: (a: string) => {
                return a || '--'
            }
        },
        {
            title: '本地备注',
            dataIndex: 'remark',
            key: 'remark',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: string) => {
                return a || '--'
            }
        },
        {
            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: '投手',
            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 <a onClick={() => { creativeHandle?.(b?.adgroupId) }}>{a}</a>
                // return <InputUpdate title={a} dataIndex={'adgroupName'} record={b} handleSave={handleSave} />
            }
        },
        {
            title: '投放日期',
            dataIndex: 'beginDate',
            key: 'beginDate',
            align: 'center',
            width: 150,
            ellipsis: true,
            sorter: 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,
            align: 'right',
            ellipsis: true,
            render: (a: string, b: { bidMode: string, optimizationGoal: string }) => {
                return `${BID_MODE_ENUM[b?.bidMode as keyof typeof BID_MODE_ENUM]} ${a}元/${b?.bidMode === 'BID_MODE_CPM' ? '千次曝光' : b?.bidMode === 'BID_MODE_CPC' ? '点击' : OPTIMIZATIONGOAL_ENUM[b?.optimizationGoal as keyof typeof OPTIMIZATIONGOAL_ENUM]}`
            }
        },
        {
            title: '深度优化行为出价',
            dataIndex: 'deepConversionBehaviorBid',
            key: 'deepConversionBehaviorBid',
            width: 140,
            align: 'center',
            render: (a: string, b: 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 as keyof typeof BidStrategyEnum]
            }
        },
        {
            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: 'targetingTranslation',
            key: 'targetingTranslation',
            align: 'center',
            width: 80,
            render: (a: 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: 'systemStatus',
            key: 'systemStatus',
            align: 'center',
            width: 90,
            fixed: 'right',
            ellipsis: true,
            render: (a: string, b: any) => {
                return ADGROUP_STATUS[a as keyof typeof ADGROUP_STATUS]
            }
        },
        {
            title: '创意预览',
            dataIndex: 'dynamicCreativeList',
            key: 'dynamicCreativeList',
            width: 150,
            fixed: 'right',
            render: (a: any, b: any) => {
                return <Space><CreativePreview creativePreview={a?.map((item: { creativeComponents: any }) => ({ ...item?.creativeComponents })) || []} /><a onClick={() => { creativeHandle?.(b?.adgroupId) }}>详情</a></Space>
                // return <Space><BoxOther creativeComponents={a?.[0]?.creativeComponents || {}} /><a onClick={() => { creativeHandle?.(b?.adgroupId) }}>详情</a></Space>
            }
        },
        {
            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/index?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