import { Checkbox, DatePicker, Form, Input, InputNumber, Radio } from "antd";
import React from "react";
import { DISPLAYTYPEHUASHENG } from "../../const";
import { RangePickerProps } from "antd/es/date-picker";
import dayjs from "dayjs";

/**
 * 免费赠币活动
 * @returns 
 */
const GiftActivityLinkDTO: React.FC<BOOKLINK.BookLinkChildProps> = ({ restField, name, itemData }) => {

    const disabledDate: RangePickerProps['disabledDate'] = current => {
        return current && current < dayjs().endOf('day');
    };

    return <>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'activityName']}
            label={<strong>活动名称</strong>}
            rules={[{ required: true, message: '请输入活动名称!' }]}
        >
            <Input placeholder="请输入活动名称" style={{ width: '100%' }} allowClear />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'freeAmount']}
            label={<strong>活动挡位</strong>}
            rules={[{ required: true, message: '请选择活动挡位!' }]}
        >
            <Radio.Group
                buttonStyle="solid"
                options={[50, 100, 200, 300, 500, 800, 1000].map(i => ({ label: i + '书币', value: i }))}
            />
        </Form.Item>

        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'activityTime']}
            label={<strong>活动时间</strong>}
            rules={[
                { required: true, message: '请选择活动时间!' },
                {
                    validator: (_: any, value: [dayjs.Dayjs, dayjs.Dayjs]) => {
                        if (!value || value.length < 2) {
                            return Promise.reject('请选择完整日期范围');
                        }
                        if (value[0].isSame(value[1], 'day')) {
                            return Promise.reject('开始和结束日期不能相同');
                        }
                        return Promise.resolve();
                    }
                }
            ]}
        >
            <DatePicker.RangePicker disabledDate={disabledDate} />
        </Form.Item>

        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'status']}
            label={<strong>活动状态</strong>}
            rules={[{ required: true, message: '请选择活动状态!' }]}
        >
            <Radio.Group
                optionType='button'
                buttonStyle="solid"
                options={[
                    { value: 'normal', label: '上架' },
                    { value: 'del', label: '下架' }
                ]}
            />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'display']}
            label={<strong>活动展示位</strong>}
        >
            <Checkbox.Group options={Object.keys(DISPLAYTYPEHUASHENG).map(key => ({ label: DISPLAYTYPEHUASHENG[key], value: key }))} />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'userType']}
            label={<strong>展示粉丝</strong>}
            rules={[{ required: true, message: '请选择展示粉丝!' }]}
        >
            <Radio.Group
                optionType='button'
                buttonStyle="solid"
                options={[
                    { value: 1, label: '全部粉丝' },
                    { value: 2, label: '条件粉丝' }
                ]}
            />
        </Form.Item>
        {itemData?.giftActivityLinkDTO?.userType === 2 && <>
            <Form.Item
                {...restField}
                name={[name, 'giftActivityLinkDTO', 'charge']}
                label={<strong>充值状态</strong>}
                rules={[{ required: true, message: '请选择充值状态!' }]}
            >
                <Radio.Group
                    optionType='button'
                    buttonStyle="solid"
                    options={[
                        { value: 0, label: '不限' },
                        { value: 1, label: '已充值' },
                        { value: 2, label: '未充值' }
                    ]}
                />
            </Form.Item>
            <Form.Item
                {...restField}
                name={[name, 'giftActivityLinkDTO', 'commonType']}
                label={<strong>关注时间</strong>}
                rules={[{ required: true, message: '请选择关注时间!' }]}
            >
                <Radio.Group
                    optionType='button'
                    buttonStyle="solid"
                    options={[
                        { value: 0, label: '不限' },
                        { value: 1, label: '24小时以上' },
                        { value: 2, label: '48小时以上' },
                        { value: 3, label: '72小时以上' }
                    ]}
                />
            </Form.Item>
        </>}
    </>
}

export default React.memo(GiftActivityLinkDTO);