import { Card, Form } from "antd";
import React, { useContext } from "react";
import { DispatchAd } from "./newCreateAd";
import DeliveryMethod from "./deliveryMethod";
import NewRadio from "@/pages/launchSystemV3/components/NewRadio";
import { SMART_DELIVERY_PLATFORM_ENUM } from "../../const";


const AdgroupsPutInType: React.FC = () => {

    /****************************************/
    const { form, putInType, setOGPparams, OGPParams } = useContext(DispatchAd)!;
    const deliveryMethod = Form.useWatch('deliveryMethod', form);
    /****************************************/

    return <Card
        title={<strong style={{ fontSize: 18 }}>投放方式</strong>}
        className="cardResetCss"
    >
        <Form.Item
            name="deliveryMethod"
            label={<strong>投放方式</strong>}
            rules={[{ required: true, message: '请选择投放方式!' }]}
            help="智能投放属于白名单功能，请确认账户已拥有权限后开启"
        >
            <DeliveryMethod
                data={[{ label: '常规投放', value: 'NORMAL', desc: '常规的3.0广告新建' }, { label: '智能投放', value: 'SMART', desc: '行业化的智能投放工具', disabled: putInType === 'GAME' }]}
                onChange={(v) => {
                    if (v === 'NORMAL') {
                        // 重置
                        form.resetFields()
                        form.setFieldsValue({
                            marketingTargetType: 'MARKETING_TARGET_TYPE_FICTION',
                            marketingCarrierType: 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT'
                        })
                        setOGPparams({ ...OGPParams, marketingGoal: 'MARKETING_GOAL_PRODUCT_SALES' });
                    } else {
                        form.setFieldsValue({
                            smartDeliveryPlatform: 'SMART_DELIVERY_PLATFORM_EDITION_FICTION',
                            marketingGoal: "MARKETING_GOAL_PRODUCT_SALES",
                            marketingCarrierType: 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT',
                            siteSet: null,
                            isConversion: true,          // 开启转化归因新链路 固定不可改
                            automaticSiteEnabled: true,  // 开启智能版位 固定不可改
                            explorationStrategy: 'AUTOMATIC_EXPLORATION',  // 探索策略 自动探索
                            searchExpandTargetingSwitch: 'SEARCH_EXPAND_TARGETING_SWITCH_OPEN', //定向拓展 
                            bidMode: 'BID_MODE_OCPM',   // 计费方式
                            // searchExpansionWitch: 'SEARCH_EXPANSION_SWITCH_OPEN',   // 搜索扩量开关，ADX 程序化广告不可填写提交 看看后期添加
                            // bidAmount: 150,   //看看后期添加
                            // marketingSubGoal: 'MARKETING_SUB_GOAL_UNKNOWN', // 看后期添加  二级营销目的
                        })
                    }
                }}
            />
        </Form.Item>

        {deliveryMethod === 'SMART' && <Form.Item style={{ marginBottom: 0 }} name="smartDeliveryPlatform" label={<strong>投放场景</strong>} rules={[{ required: true, message: '请选择投放场景!' }]}>
            <NewRadio data={(Object.keys(SMART_DELIVERY_PLATFORM_ENUM) as Array<keyof typeof SMART_DELIVERY_PLATFORM_ENUM>).map((key) => ({ label: SMART_DELIVERY_PLATFORM_ENUM[key], value: key }))} />
        </Form.Item>}
    </Card>
}

export default React.memo(AdgroupsPutInType);