import { BidStrategyEnum } from '@/services/launchAdq/enum'
import React from 'react'
import { Badge, Space, Tag } from 'antd'
import '../index.less'
import { copy } from '@/utils/utils'
import { ADGROUP_STATUS, AUTO_ACQUISTION_STATUS, GOAL_ENUM } from '../const'
import SwitchStatus from './switchStatus'
import TimeSeriesLook from '@/pages/launchSystemNew/adq/ad/timeSeriesLook'
import CreativePreview from '../../adMonitorListV3/CreativePreview'
import { BID_MODE_ENUM, BID_SCENE_NORMAL_ENUM, COST_GUARANTEE_STATUS_ENUM, MARKETING_CARRIER_TYPE_ENUM, MARKETING_GOAL_ENUM, MARKETING_TARGET_TYPE_ENUM, MARKETING_TARGET_TYPE_GAME_ENUM, OPTIMIZATIONGOAL_ENUM, SITE_SET_ENUM, SMART_DELIVERY_GOAL_ENUM } from '../../tencentAdPutIn/const'
function tableConfig(onChange: () => void, useType: string, 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: 'smartDeliveryPlatform',
            key: 'smartDeliveryPlatform',
            align: 'center',
            width: 40,
            fixed: 'left',
            render: (a: string) => {
                return <Badge status={a ? "processing" : "error"} text={a ? '是' : '否'} />
            }
        },
        {
            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, smartDeliveryPlatform?: string, smartDeliverySceneSpec?: any }) => {
                if (b?.smartDeliveryPlatform && b?.smartDeliverySceneSpec) {
                    const goalDto = SMART_DELIVERY_GOAL_ENUM[b.smartDeliverySceneSpec?.smartDeliveryGoal as keyof typeof SMART_DELIVERY_GOAL_ENUM]
                    return `${goalDto?.smartDeliveryGoalSpec?.map(item => {
                        const field_name = item.field_name
                        const data = b.smartDeliverySceneSpec?.smartDeliveryGoalSpec?.[goalDto?.smartDeliveryGoalSpecName]?.[item.field_name]
                        return `${item.title}： ${field_name?.includes('Roi') ? data : data / 100}${item?.unitTips || ''}`
                    })}`
                }
                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: 'right',
            ellipsis: true,
            render: (a: string, b: any) => {
                return b?.deepConversionSpec?.deepConversionWorthSpec?.expectedRoi ? b?.deepConversionSpec?.deepConversionWorthSpec?.expectedRoi + '/' + GOAL_ENUM[b?.deepConversionSpec?.deepConversionWorthSpec?.goal as keyof typeof GOAL_ENUM] : '--'
            }
        },
        {
            title: '出价类型',
            dataIndex: 'smartBidType',
            key: 'smartBidType',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: string, b: { endDate: string }) => {
                return a === 'SMART_BID_TYPE_CUSTOM' ? '手动出价' : '自动出价'
            }
        },
        {
            title: ['GAME', 'GAME_IAA'].includes(useType) ? '出价场景' : '出价策略',
            dataIndex: 'bidStrategy',
            key: 'bidStrategy',
            align: 'center',
            width: 70,
            ellipsis: true,
            render: (a: string, b: { bidScene: string }) => {
                if (['GAME', 'GAME_IAA'].includes(useType)) {
                    return BID_SCENE_NORMAL_ENUM[b?.bidScene as keyof typeof BID_SCENE_NORMAL_ENUM] || '--'
                }
                return BidStrategyEnum[a as keyof typeof BidStrategyEnum]
            }
        },
        {
            title: '一键起量',
            dataIndex: 'autoAcquisitionEnabled',
            key: 'autoAcquisitionEnabled',
            align: 'center',
            width: 70,
            render: (a: boolean) => {
                return a ? <Tag color="success">开启</Tag> : <Tag color="error">关闭</Tag>
            }
        },
        {
            title: '一键起量状态',
            dataIndex: 'autoAcquisitionStatus',
            key: 'autoAcquisitionStatus',
            align: 'center',
            width: 120,
            ellipsis: true,
            render: (a: string) => AUTO_ACQUISTION_STATUS[a as keyof typeof AUTO_ACQUISTION_STATUS]
        },
        {
            title: '一键起量预算',
            dataIndex: 'autoAcquisitionBudget',
            key: 'autoAcquisitionBudget',
            align: 'right',
            width: 70
        },
        {
            title: '广告组日预算(元)',
            dataIndex: 'dailyBudget',
            key: 'dailyBudget',
            align: 'center',
            width: 70
        },
        {
            title: '营销目的',
            dataIndex: 'marketingGoal',
            key: 'marketingGoal',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                return MARKETING_GOAL_ENUM[a as keyof typeof MARKETING_GOAL_ENUM]
            }
        },
        {
            title: '推广产品类型',
            dataIndex: 'marketingTargetType',
            key: 'marketingTargetType',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                if (['GAME', 'GAME_IAA'].includes(useType)) {
                    return MARKETING_TARGET_TYPE_GAME_ENUM[a as keyof typeof MARKETING_TARGET_TYPE_GAME_ENUM] || '--'
                }
                return MARKETING_TARGET_TYPE_ENUM[a as keyof typeof MARKETING_TARGET_TYPE_ENUM]
            }
        },
        {
            title: '营销载体类型',
            dataIndex: 'marketingCarrierType',
            key: 'marketingCarrierType',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                return MARKETING_CARRIER_TYPE_ENUM[a as keyof typeof MARKETING_CARRIER_TYPE_ENUM]
            }
        },
        {
            title: '是否开启自动版位功能',
            dataIndex: 'automaticSiteEnabled',
            key: 'automaticSiteEnabled',
            align: 'center',
            width: 80,
            render: (a: any, b: any) => {
                return a ? '开' : '关'
            }
        },
        {
            title: '版位选择',
            dataIndex: 'siteSet',
            key: 'siteSet',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                return a ? a.map((item: string | number) => SITE_SET_ENUM[item as keyof typeof SITE_SET_ENUM]).toString() : '--'
            }
        },
        {
            title: '定向条件描述',
            dataIndex: 'targetingTranslation',
            key: 'targetingTranslation',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                return a || '--'
            }
        },
        {
            title: '成本保障状态',
            dataIndex: 'costGuaranteeStatus',
            key: 'costGuaranteeStatus',
            align: 'center',
            width: 80,
            ellipsis: true,
            render: (a: any) => {
                return COST_GUARANTEE_STATUS_ENUM[a as keyof typeof COST_GUARANTEE_STATUS_ENUM]
            }
        },
        {
            title: '成本保障赔付金额',
            dataIndex: 'costGuaranteeMoney',
            key: 'costGuaranteeMoney',
            align: 'right',
            width: 70
        },
        {
            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: 'smartTargetingStatus',
            key: 'smartTargetingStatus',
            align: 'center',
            width: 90,
            fixed: 'right',
            render: (a: string) => {
                return a === 'SMART_TARGETING_NONE' ? <Tag color="success">关闭</Tag> : a === 'SMART_TARGETING_AUTO' ? <Tag color='error'>开启</Tag> : '--'
            }
        },
        {
            title: '创意预览',
            dataIndex: 'dynamicCreativeList',
            key: 'dynamicCreativeList',
            width: 150,
            fixed: 'right',
            render: (a: any, b: any) => {
                if (a?.length) {
                    let deliveryMode: string[] = []
                    let creativePreview = a?.map((item: { creativeComponents: any, deliveryMode: string }) => {
                        deliveryMode.push(item.deliveryMode)
                        return { ...item?.creativeComponents }
                    })
                    return <Space><CreativePreview creativePreview={creativePreview} deliveryMode={deliveryMode} /><a onClick={() => { creativeHandle?.(b?.adgroupId) }}>详情</a></Space>
                }
                return null
                // 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