import { Checkbox, DatePicker, Form, Input, InputNumber, Select } from "antd";
import React from "react";
import { DISPLAYTYPE, RESOURCETTYPE } from "../../const";

/**
 * 模板直赠活动
 * @returns 
 */
const GiftActivityLinkDTO: React.FC<BOOKLINK.BookLinkChildProps> = ({ restField, name }) => {


    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', 'resourceType']}
            label={<strong>赠送道具</strong>}
            rules={[{ required: true, message: '请选择赠送道具!' }]}
        >
            <Select
                showSearch
                placeholder="请选择赠送道具"
                filterOption={(input, option) =>
                    ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
                }
                allowClear
                options={Object.keys(RESOURCETTYPE).map(key => ({ label: RESOURCETTYPE[key], value: key }))}
            />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'freeAmount']}
            label={<strong>赠送书券量</strong>}
            rules={[{ required: true, message: '请输入赠送书券量!' }]}
        >
            <InputNumber placeholder="请输入" min={1} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'expire']}
            label={<strong>书券有效期</strong>}
            rules={[{ required: true, message: '请输入书券有效期1-7天!' }]}
        >
            <InputNumber placeholder="请输入书券有效期1-7天" suffix="天" precision={0} max={7} min={1} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'totalGift']}
            label={<strong>赠送名额</strong>}
            rules={[{ required: true, message: '请输入赠送名额!' }]}
        >
            <InputNumber placeholder="请输入" min={0} style={{ width: '100%' }} />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'activityTime']}
            label={<strong>活动时间</strong>}
            rules={[{ required: true, message: '请选择活动时间!' }]}
        >
            <DatePicker.RangePicker />
        </Form.Item>
        <Form.Item
            {...restField}
            name={[name, 'giftActivityLinkDTO', 'display']}
            label={<strong>活动展示位</strong>}
        >
            <Checkbox.Group options={Object.keys(DISPLAYTYPE).filter(key => key === '1').map(key => ({ label: DISPLAYTYPE[key], value: key }))} />
        </Form.Item>
    </>
}

export default React.memo(GiftActivityLinkDTO);