import { FundStatusEnum } from "@/services/launchAdq/enum"
import { EditOutlined, FileSearchOutlined, SettingOutlined, SwapOutlined, UploadOutlined, UserSwitchOutlined } from "@ant-design/icons"
import { Badge, Button, Popconfirm, Space, Tooltip } from "antd"
import React from "react"
import DivideIntoGroups from "./divideIntoGroups"
import './index.less'
import OpenV3 from "../components/openV3"
import OpenV3All from "../components/openV3All"
import { AdUnitType_Enum } from "../const"
export function columnsMp(
    edit: (params: any) => void,
    setOpenServer: (data: any) => void,
    del: (groupId: number, accountId: number) => void,
    checkAccount: (value: any[]) => void,
    changeRecord: (accountId: number, id: number) => void,
    putUserHandle: (data: any) => void,
    v3Change: () => void,
    activeKey: string,
    userId: string | undefined,
    groupId?: number,
    getAdAccountList?: any
): any {
    return [
        {
            title: 'ID',
            dataIndex: 'id',
            key: 'id',
            align: 'center',
            width: 55,
            fixed: 'left'
        },
        {
            title: '广告主ID',
            dataIndex: 'accountId',
            key: 'accountId',
            align: 'center',
            width: 80,
            fixed: 'left'
        },
        {
            title: '类型',
            dataIndex: 'sourceType',
            key: 'sourceType',
            align: 'center',
            width: 60,
            render: (a: any, b: any) => {
                return <span>{a == 0 ? '微信' : 'QQ'}</span>
            }
        },
        {
            title: '是否业务单元账号',
            dataIndex: 'adUnitAccount',
            key: 'adUnitAccount',
            align: 'center',
            width: 75,
            render: (a: boolean) => {
                return <span>{a ? '是' : '否'}</span>
            }
        },
        {
            title: '业务单元账号ID',
            dataIndex: 'adUnitAccountId',
            key: 'adUnitAccountId',
            align: 'center',
            width: 75,
            render: (a: any) => {
                return <span>{a || '--'}</span>
            }
        },
        {
            title: '业务单元类型',
            dataIndex: 'adUnitType',
            key: 'adUnitType',
            align: 'center',
            width: 75,
            render: (a: string) => {
                return AdUnitType_Enum[a as keyof typeof AdUnitType_Enum] || '--'
            }
        },
        {
            title: '投手',
            dataIndex: 'putUserInfo',
            key: 'putUserInfo',
            width: 70,
            align: 'center',
            ellipsis: true,
            render: (a: any, b: any) => {
                return <span>{a?.nickname || '-1'}</span>
            }
        },
        {
            title: '投放助理',
            dataIndex: 'accountUsers',
            key: 'accountUsers',
            width: 70,
            align: 'center',
            ellipsis: true,
            render: (a: any[], b: any) => {
                return a && a?.length > 0 ? a.map((item: { putUserName: string, putUseId: number }) => item.putUserName).toString() : '-1'
            }
        },
        {
            title: '投放信息',
            dataIndex: 'putResourceName',
            key: 'putResourceName',
            width: 110,
            align: 'center',
            ellipsis: true,
        },
        {
            title: '腾讯备注',
            dataIndex: 'memo',
            key: 'memo',
            align: 'center',
            width: 100,
            ellipsis: true,
        },
        {
            title: '本地备注',
            dataIndex: 'remark',
            key: 'remark',
            align: 'center',
            width: 100,
            ellipsis: true,
        },
        {
            title: '告警名称',
            dataIndex: 'warningRuleList',
            key: 'warningRuleList',
            align: 'center',
            width: 90,
            ellipsis: true,
            render: (a: any[], b: any) => {
                return a?.length > 0 ? a?.[0]?.ruleName : '--'
            }
        },
        // {
        //     title: '公众号信息',
        //     dataIndex: 'wechatAccountName',
        //     key: 'wechatAccountName',
        //     width: 150,
        //     align: 'center',
        //     render: (a: any, b: any) => {
        //         return <div className="verticalCenter">
        //             <div><strong>{a}</strong></div>
        //             <div style={{ color: "rgb(136, 136, 136)", fontSize: 13 }}>{b?.wechatAccountId}</div>
        //         </div>
        //     }
        // },
        {
            title: '企业名称',
            dataIndex: 'corporationName',
            key: 'corporationName',
            width: 150,
            align: 'center',
            ellipsis: true
        },
        {
            title: '服务商',
            dataIndex: 'serviceProviderName',
            key: 'serviceProviderName',
            width: 150,
            align: 'center',
            ellipsis: true
        },
        // {
        //     title: '服务商ID列表',
        //     dataIndex: 'agencyIdList',
        //     key: 'agencyIdList',
        //     width: 130,
        //     align: 'center',
        //     render: (a: any) => {
        //         return <Tooltip title={a}>
        //             <div className="name-wrapper">
        //                 <p>{ a }</p>
        //             </div>
        //         </Tooltip>
        //     }
        // },
        {
            title: '行业ID',
            dataIndex: 'systemIndustryId',
            key: 'systemIndustryId',
            width: 105,
            align: 'center',
            render: (a: any) => {
                return <Tooltip title={a}>
                    <div className="name-wrapper">{a}</div>
                </Tooltip>
            }
        },
        {
            title: '是否有效',
            dataIndex: 'enabled',
            key: 'enabled',
            align: 'center',
            width: 60,
            render: (a: any, b: any) => {
                return <Badge status={a ? "processing" : "error"} text={a ? '是' : '否'} />
            }
        },
        {
            title: '授权时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 150
        },
        {
            title: '日限额(分)',
            dataIndex: 'dailyBudget',
            key: 'dailyBudget',
            align: 'center',
            width: 80
        },
        {
            title: '资金状态',
            dataIndex: 'fundStatus',
            key: 'fundStatus',
            align: 'center',
            width: 80,
            render: (a: string | number) => {
                return FundStatusEnum[a as keyof typeof FundStatusEnum]
            }
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 300,
            fixed: 'right',
            render: (a: any, b: any) => {
                return <Space>
                    {(Object.keys(b)?.includes('addV3') && !b.addV3 && !b?.adUnitAccount) && <OpenV3 accountId={b?.accountId} onChange={v3Change} />}
                    <OpenV3All adUnitAccount={b?.adUnitAccount} accountId={b?.accountId} onChange={v3Change} />
                    <Tooltip title="配置服务商">
                        <Button size="small" style={{ color: "#00bcd4" }} onClick={() => setOpenServer([b])} icon={<SettingOutlined />}></Button>
                    </Tooltip>
                    <Tooltip title="备注">
                        <Button size="small" style={{ color: '#52c41a' }} onClick={() => edit(b)} icon={<EditOutlined />}></Button>
                    </Tooltip>
                    <Tooltip title="切号">
                        <Button size="small" style={{ color: '#ea5506' }} onClick={() => checkAccount([b])} icon={<SwapOutlined />}></Button>
                    </Tooltip>
                    <Tooltip title="变更记录">
                        <Button size="small" style={{ color: '#4d5aaf' }} onClick={() => changeRecord(b?.accountId, b?.id)} icon={<FileSearchOutlined />}></Button>
                    </Tooltip>
                    {activeKey === '1' && <>
                        {userId == b?.putUserInfo?.userId?.toString() && <Tooltip title="指派投放助理">
                            <Button size="small" style={{ color: '#0eb83a' }} onClick={() => putUserHandle([b])} icon={<UserSwitchOutlined />}></Button>
                        </Tooltip>}
                        {!groupId && <DivideIntoGroups groupIds={b?.groupIds} getAdAccountList={getAdAccountList} accountId={b?.accountId} />}
                    </>}
                    {groupId && <Popconfirm
                        title={`是否把${b?.accountId}移出该分组?`}
                        onConfirm={() => { del(groupId, b?.accountId) }}
                        okText="是"
                        cancelText="否"
                    >
                        <Tooltip title="移出分组">
                            <Button size="small" style={{ color: 'red' }}><UploadOutlined /></Button>
                        </Tooltip>
                    </Popconfirm>}
                </Space>
            }
        },
    ]
}