import { App, Button, Card, Checkbox, DatePicker, Divider, Form, Input, InputNumber, Modal, Select, Space } from 'antd';
import React, { useEffect, useState } from 'react';
import style from './index.less'
import { useAjax } from '@/Hook/useAjax';
import { GENDER_TYPE, sysExternalExcludeTagList } from '../../page/businessPlan/create/const';
import { addSiftPopulationConfigApi, updateSiftPopulationConfigApi } from '../../API/businessPlan/filterUser';
import dayjs from 'dayjs';
import MindTags from '../mindTags';
import SelectBook from '../SelectBook';
import SelectChapter from '../SelectChapter';
import { getCorpAllListApi } from '@/API/global';

interface NewFilterUserProps {
    configType: BUSINES_SPLAN_API.ConfigTypeProps
    bookCityList: { label: string, value: string }[]
    isBackVal?: boolean
    visible?: boolean
    value?: any,
    onClose?: () => void
    onChange?: (value?: any) => void
}

/**
 * 人群包编辑
 * @param param0 
 * @returns 
 */
const NewFilterUser: React.FC<NewFilterUserProps> = ({ bookCityList, configType = 'USER_GROUP', isBackVal = false, visible, value, onClose, onChange }) => {

    /***********************************/
    const { message } = App.useApp()
    const [form] = Form.useForm();
    const platformKey = Form.useWatch('platformKey', form)
    const lastBookNameList = Form.useWatch('lastBookNameList', form)
    const isRepeat = Form.useWatch('isRepeat', form)
    const isGroupRepeat = Form.useWatch('isGroupRepeat', form)
    const [isSave, setIsSave] = useState<boolean>(false)

    const addSiftPopulationConfig = useAjax((params) => addSiftPopulationConfigApi(params))
    const updateSiftPopulationConfig = useAjax((params) => updateSiftPopulationConfigApi(params))
    const getCorpAllList = useAjax((params) => getCorpAllListApi(params))
    /***********************************/

    useEffect(() => {
        if (isRepeat || isGroupRepeat)
            getCorpAllList.run({})
    }, [isRepeat, isGroupRepeat])

    useEffect(() => {
        if (value && Object.keys(value).length > 0) {
            console.log('value', value)
            const { beginTime, endTime, lastRechargeTimeMin, lastRechargeTimeMax, groupChatNames, groupChatBeginTime, groupChatEndTime, lastReadTimeMin, lastReadTimeMax, groupNameList, groupRepeatRang, ...params } = value
            if (beginTime) {
                params.beginTime = dayjs(beginTime)
            }
            if (endTime) {
                params.endTime = dayjs(endTime)
            }
            if (lastRechargeTimeMin && lastRechargeTimeMax) {
                params.lastRechargeTime = [dayjs(lastRechargeTimeMin), dayjs(lastRechargeTimeMax)]
            }
            if (lastReadTimeMin && lastReadTimeMax) {
                params.lastReadTime = [dayjs(lastReadTimeMin), dayjs(lastReadTimeMax)]
            }
            if (groupChatBeginTime && groupChatEndTime) {
                params.groupChatTime = [dayjs(groupChatBeginTime), dayjs(groupChatEndTime)]
            }
            if (groupChatNames?.length) {
                params.groupChatNames = groupChatNames.join(',')
            }
            if (params?.repeatOperateType || params?.repeatOperateType === 0) {
                if (params.repeatRang) {
                    params.repeatRang = Object.entries(params.repeatRang || {}).map(([corpId, corpName]: [string, string]) => `${corpId}&&${corpName}`)
                }
                params.isRepeat = true
            }

            if (params?.groupOperateType || params?.groupOperateType === 0) {
                params.groupNameList = groupNameList?.join(',')
                params.isGroupRepeat = true
                console.log('groupNameList', groupRepeatRang)
                if (!!groupRepeatRang) {
                    params.groupRepeatRang = Object.entries(groupRepeatRang || {}).map(([corpId, corpName]: [string, string]) => `${corpId}&&${corpName}`)
                }
            }
            form.setFieldsValue(params)
        }
    }, [value])

    const handleOk = () => {
        form.validateFields().then((values) => {
            console.log(values)
            const { configName, isRepeat, repeatRang, isGroupRepeat, groupRepeatRang, groupNameList, ...configContent } = values
            if (configContent && Object.keys(configContent).length > 0 && Object.keys(configContent).some(key => configContent[key] || configContent[key] === 0)) {
                const {
                    beginTime, endTime, lastRechargeTime, lastReadTime, groupChatNames, groupChatTime, firstAddGroupTime,
                    lastAddGroupTime, lastExitTime,
                    ...params
                } = configContent
                const dta = {
                    ...params
                }
                if (beginTime) {
                    dta.beginTime = dayjs(beginTime).format('YYYY-MM-DD')
                }
                if (endTime) {
                    dta.endTime = dayjs(endTime).format('YYYY-MM-DD')
                }
                if (lastRechargeTime?.length > 1) {
                    dta.lastRechargeTimeMin = dayjs(lastRechargeTime[0]).format('YYYY-MM-DD');
                    dta.lastRechargeTimeMax = dayjs(lastRechargeTime[1]).format('YYYY-MM-DD');
                }
                if (lastReadTime?.length > 1) {
                    dta.lastReadTimeMin = dayjs(lastReadTime[0]).format('YYYY-MM-DD');
                    dta.lastReadTimeMax = dayjs(lastReadTime[1]).format('YYYY-MM-DD');
                }
                if (groupChatNames) {
                    dta.groupChatNames = groupChatNames.split(/[,，\n\s]+/ig).filter((item: any) => item)
                }
                if (groupChatTime?.length > 1) {
                    dta.groupChatBeginTime = dayjs(groupChatTime[0]).format('YYYY-MM-DD');
                    dta.groupChatEndTime = dayjs(groupChatTime[1]).format('YYYY-MM-DD');
                }
                if (firstAddGroupTime?.length > 1) {
                    dta.firstAddGroupTimeMin = dayjs(firstAddGroupTime[0]).format('YYYY-MM-DD');
                    dta.firstAddGroupTimeMax = dayjs(firstAddGroupTime[1]).format('YYYY-MM-DD');
                }
                if (lastAddGroupTime?.length > 1) {
                    dta.lastAddGroupTimeMin = dayjs(lastAddGroupTime[0]).format('YYYY-MM-DD');
                    dta.lastAddGroupTimeMax = dayjs(lastAddGroupTime[1]).format('YYYY-MM-DD');
                }
                if (lastExitTime?.length > 1) {
                    dta.lastExitTimeMin = dayjs(lastExitTime[0]).format('YYYY-MM-DD');
                    dta.lastExitTimeMax = dayjs(lastExitTime[1]).format('YYYY-MM-DD');
                }
                if (repeatRang?.length) {
                    dta.repeatRang = repeatRang.reduce((pre, cur) => {
                        const [corpId, corpName] = cur.split('&&')
                        pre[corpId] = corpName
                        return pre
                    }, {})
                }
                if (groupRepeatRang?.length) {
                    dta.groupRepeatRang = groupRepeatRang.reduce((pre, cur) => {
                        const [corpId, corpName] = cur.split('&&')
                        pre[corpId] = corpName
                        return pre
                    }, {})
                }
                if (groupNameList) {
                    dta.groupNameList = groupNameList.split(/[,，\n\s]+/ig).filter((item: any) => item)
                }

                // 直接新增
                if (isBackVal && !isSave) {
                    onChange?.({
                        configName,
                        configContent: dta
                    })
                    return
                }

                if (value?.id) {
                    updateSiftPopulationConfig.run({
                        id: value?.id,
                        configName,
                        configType,
                        configContent: JSON.stringify(dta)
                    }).then((res) => {
                        console.log(res)
                        if (res?.data) {
                            message.success('修改成功')
                            onChange?.()
                        }
                    })
                } else {
                    addSiftPopulationConfig.run({
                        configName,
                        configType,
                        configContent: JSON.stringify(dta)
                    }).then((res) => {
                        console.log(res)
                        if (res?.data) {
                            message.success('新增成功')
                            if (isSave) {
                                onChange?.({
                                    configName,
                                    configContent: dta
                                })
                            } else {
                                onChange?.()
                            }
                        }
                    })
                }
            } else {
                message.error('请至少选择一项')
            }
        }).catch(() => {
            form.submit()
        });
    };

    const validateAnyFieldRequired = async (_, value) => {
        const values = form.getFieldsValue([
            'minCorpIdCount',
            'maxCorpIdCount',
            'minCorpUserIdCount',
            'maxCorpUserIdCount',
        ]);

        const hasValue = Object.values(values).some((v) => v !== undefined && v !== null && v !== '');

        if (!hasValue) {
            return Promise.reject(new Error('至少填写一个添加数值'));
        }

        return Promise.resolve();
    };

    const title = configType === 'GROUP_GROUP' ? '群人群包' : '用户人群包';
    return <Modal
        title={isBackVal ? <strong style={{ fontSize: 14 }}>
            {(value && Object.keys(value).length > 0) ? `修改${title}` : `新增${title}`}
        </strong> : <strong style={{ fontSize: 14 }}>{value?.id ? `修改${title}模板` : value?.isCopy ? `复制${title}模板` : `新增${title}模板`}</strong>}
        open={visible}
        onCancel={onClose}
        width={700}
        onOk={handleOk}
        footer={<Space>
            {isBackVal && <Checkbox onChange={(e) => setIsSave(e.target.checked)} checked={isSave}>是否保存到模板</Checkbox>}
            <Button onClick={onClose}>取消</Button>
            <Button type="primary" onClick={handleOk}>确定</Button>
        </Space>}
        styles={{
            body: { maxHeight: 500, overflow: 'hidden', overflowY: 'auto' }
        }}
        confirmLoading={addSiftPopulationConfig.loading || updateSiftPopulationConfig.loading}
    >
        <Form
            form={form}
            name="newFilterUser"
            labelAlign='left'
            labelCol={{ span: 5 }}
            colon={false}
            scrollToFirstError={{
                behavior: 'smooth',
                block: 'center'
            }}
            onFinishFailed={({ errorFields }) => {
                message.error(errorFields?.[0]?.errors?.[0])
            }}
            onFinish={handleOk}
            initialValues={{
                strategySettings: [{ inheritDto: [undefined] }],
            }}
            preserve={true}
        >
            <div className={style.newSpace}>
                <Form.Item
                    label={<strong>{title}名称</strong>}
                    name='configName'
                    rules={[
                        { required: true, message: '请输入人群包名称!' }
                    ]}
                >
                    <Input.TextArea placeholder="人群包名称" maxLength={30} showCount />
                </Form.Item>
            </div>

            {configType === 'GROUP_GROUP' ? <>
                <div className={style.newSpace}>
                    <Form.Item name="groupChatNames" label={<strong>群名称列表</strong>} style={{ marginBottom: 0 }}>
                        <Input.TextArea placeholder="群名称列表(多个，,空格换行隔开)" allowClear />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="groupChatTime" label={<strong>群创建时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["群创建时间开始", "群创建时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>群创建时长</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="groupChatHourMin" noStyle>
                                <InputNumber placeholder="最小值小时" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="groupChatHourMax" noStyle>
                                <InputNumber placeholder="最大值小时" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>群人数</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="groupChatUserMin" noStyle>
                                <InputNumber placeholder="最小值" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="groupChatUserMax" noStyle>
                                <InputNumber placeholder="最大值" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
            </> : <>
                <div className={style.newSpace}>
                    <Form.Item
                        label={<strong>智能标签</strong>}
                    >
                        <Card
                            styles={{
                                body: { padding: '6px 0 6px 16px' }
                            }}
                            style={{ background: '#fff', marginBottom: 10 }}
                        >
                            <Form.Item name="msgTagIds" noStyle style={{ marginBottom: 0 }}>
                                <MindTags />
                            </Form.Item>
                        </Card>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>排除智能标签</strong>}>
                        <Card
                            styles={{
                                body: { padding: '6px 0 6px 16px' }
                            }}
                            style={{ background: '#fff', marginBottom: 10 }}
                        >
                            <Form.Item name="msgExcludeTagIds" noStyle style={{ marginBottom: 0 }}>
                                <MindTags />
                            </Form.Item>
                        </Card>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="sysExternalExcludeTagNames" label={<strong>排除标签</strong>} style={{ marginBottom: 0 }}>
                        <Select
                            placeholder='请选择排除标签'
                            allowClear
                            mode='multiple'
                            filterOption={(input, option) =>
                                (option?.label as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                            showSearch
                            options={sysExternalExcludeTagList.map(item => ({ value: item, label: item }))}
                        />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="platformKey" label={<strong>书城</strong>} style={{ marginBottom: 0 }}>
                        <Select
                            placeholder='请选择书城'
                            allowClear
                            options={bookCityList}
                        />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="lastBookNameList" label={<strong>最近阅读书籍</strong>} style={{ marginBottom: 0 }}>
                        <SelectBook onChange={() => form.setFieldsValue({ lastChapterNameList: undefined })} platformKey={platformKey} />
                    </Form.Item>
                </div>
                {lastBookNameList?.length === 1 && <div className={style.newSpace}>
                    <Form.Item label={<strong>最近阅读章节</strong>} name='lastChapterNameList' tooltip="选择单本书才可选择章节">
                        <SelectChapter platformKey={platformKey} bookName={lastBookNameList?.[0]} />
                    </Form.Item>
                </div>}
                <div className={style.newSpace}>
                    <Form.Item name="platformUserId" label={<strong>书城用户ID</strong>} style={{ marginBottom: 0 }}>
                        <Input placeholder="书城用户ID" allowClear />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="rechargeBook" label={<strong>充值小说</strong>} style={{ marginBottom: 0 }}>
                        <Input placeholder="请输入充值小说" allowClear />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>关注时间</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="beginTime" noStyle>
                                <DatePicker placeholder='关注开始时间' />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="endTime" noStyle>
                                <DatePicker placeholder='关注结束时间' />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="genders" label={<strong>性别</strong>} style={{ marginBottom: 0 }}>
                        <Select
                            style={{ minWidth: 60 }}
                            maxTagCount={1}
                            mode='multiple'
                            placeholder='性别'
                            allowClear
                            options={Object.keys(GENDER_TYPE).map(key => ({ label: GENDER_TYPE[key as keyof typeof GENDER_TYPE], value: key }))}
                        />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>充值次数</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="rechargeCountMin" noStyle>
                                <InputNumber placeholder="最小充值次数" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="rechargeCountMax" noStyle>
                                <InputNumber placeholder="最大充值次数" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>充值金额</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="rechargeMoneyMin" noStyle>
                                <InputNumber placeholder="最低充值金额" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="rechargeMoneyMax" noStyle>
                                <InputNumber placeholder="最大充值金额" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="lastRechargeTime" label={<strong>最后充值时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["最后充值时间开始", "最后充值时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>首充金额</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="firstRechargeMoneyMin" noStyle>
                                <InputNumber placeholder="最低首充金额" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="firstRechargeMoneyMax" noStyle>
                                <InputNumber placeholder="最大首充金额" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>单笔最大充值金额</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="rechargeMoneyMaxMin" noStyle>
                                <InputNumber placeholder="最低单笔最大充值金额" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="rechargeMoneyMaxMax" noStyle>
                                <InputNumber placeholder="最大单笔最大充值金额" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>关注距今时间</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="subHourMin" noStyle>
                                <InputNumber placeholder="最小关注时间" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="subHourMax" noStyle>
                                <InputNumber placeholder="最大关注时间" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>关注距今天</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="subDayMin" noStyle>
                                <InputNumber placeholder="最小关注天" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="subDayMax" noStyle>
                                <InputNumber placeholder="最大关注天" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>最近一次充值距今(小时)</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="lastRechargeHourMin" noStyle>
                                <InputNumber placeholder="最小充值距今" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="lastRechargeHourMax" noStyle>
                                <InputNumber placeholder="最大充值距今" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="lastReadTime" label={<strong>最近阅读时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["最近阅读时间开始", "最近阅读时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>最近阅读至今(小时)</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="lastReadHourMin" noStyle>
                                <InputNumber placeholder="最近阅读至今小时差区间-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="lastReadHourMax" noStyle>
                                <InputNumber placeholder="最近阅读至今小时差区间-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="opers" label={<strong>手机系统</strong>} style={{ marginBottom: 0 }}>
                        <Select
                            placeholder='手机系统'
                            mode="multiple"
                            maxLength={1}
                            allowClear
                            options={[
                                { value: '0', label: '未知' },
                                { value: '1', label: '安卓' },
                                { value: '2', label: 'IOS' },
                            ]}
                        />
                    </Form.Item>
                </div>
                <Divider orientation="left">用户去重筛选</Divider>
                <div className={style.newSpace}>
                    <Form.Item name="isRepeat" label={<strong>用户去重筛选</strong>} style={{ marginBottom: 0 }} valuePropName='checked'>
                        <Checkbox>是否开启用户去重筛选</Checkbox>
                    </Form.Item>
                </div>
                {isRepeat && <>
                    <div className={style.newSpace}>
                        <Form.Item name="repeatRang" label={<strong>重粉范围</strong>} style={{ marginBottom: 0 }}>
                            <Select
                                showSearch
                                mode='multiple'
                                style={{ minWidth: 110 }}
                                maxTagCount={1}
                                placeholder="请选择主体"
                                filterOption={(input, option) =>
                                    ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
                                }
                                allowClear
                                options={getCorpAllList?.data?.data?.map((item: any) => ({ label: item.corpName, value: item.corpId + '&&' + item.corpName }))}
                            />
                        </Form.Item>
                    </div>
                    <div className={style.newSpace}>
                        <Form.Item name="repeatOperateType" label={<strong>重粉操作类型</strong>} style={{ marginBottom: 0 }} rules={[{ required: true, message: '请选择重粉操作类型' }]}>
                            <Select
                                placeholder='重粉操作类型'
                                allowClear
                                options={[
                                    { value: 0, label: '排除运营' },
                                    { value: 1, label: '去重运营' }
                                ]}
                            />
                        </Form.Item>
                    </div>
                    <div className={style.newSpace}>
                        <Form.Item label={<strong>添加主体</strong>} style={{ marginBottom: 0 }} required>
                            <Space>
                                <Form.Item name="minCorpIdCount" noStyle rules={[{ validator: validateAnyFieldRequired }]}>
                                    <InputNumber placeholder="添加主体最小数" style={{ width: 200 }} />
                                </Form.Item>
                                <span>-</span>
                                <Form.Item name="maxCorpIdCount" noStyle>
                                    <InputNumber placeholder="添加主体最大数" style={{ width: 200 }} />
                                </Form.Item>
                            </Space>
                        </Form.Item>
                    </div>
                    <div className={style.newSpace}>
                        <Form.Item label={<strong>添加客服</strong>} style={{ marginBottom: 0 }} required>
                            <Space>
                                <Form.Item name="minCorpUserIdCount" noStyle>
                                    <InputNumber placeholder="添加客服最小数" style={{ width: 200 }} />
                                </Form.Item>
                                <span>-</span>
                                <Form.Item name="maxCorpUserIdCount" noStyle>
                                    <InputNumber placeholder="添加客服最大数" style={{ width: 200 }} />
                                </Form.Item>
                            </Space>
                        </Form.Item>
                    </div>
                </>}
                <Divider orientation="left">群聊用户筛选</Divider>
                <div className={style.newSpace}>
                    <Form.Item name="firstAddGroupTime" label={<strong>首次拉群时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["首次拉群时间开始", "首次拉群时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="lastAddGroupTime" label={<strong>最近拉群时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["最近拉群时间开始", "最近拉群时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="lastExitTime" label={<strong>最近退群时间</strong>} style={{ marginBottom: 0 }}>
                        <DatePicker.RangePicker placeholder={["最近退群时间开始", "最近退群时间结束"]} />
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>首次拉群(最近N小时)</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="firstAddGroupHourRangeMin" noStyle>
                                <InputNumber placeholder="首次拉群-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="firstAddGroupHourRangeMax" noStyle>
                                <InputNumber placeholder="首次拉群-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>最近拉群(最近N小时)</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="lastAddGroupHourRangeMin" noStyle>
                                <InputNumber placeholder="最近拉群-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="lastAddGroupHourRangeMax" noStyle>
                                <InputNumber placeholder="最近拉群-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>最近退群(最近N小时)</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="lastExitHourRangeMin" noStyle>
                                <InputNumber placeholder="最近退群-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="lastExitHourRangeMax" noStyle>
                                <InputNumber placeholder="最近退群-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>进群次数</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="addGroupCountMin" noStyle>
                                <InputNumber placeholder="进群次数-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="addGroupCountMax" noStyle>
                                <InputNumber placeholder="进群次数-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>退群次数</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="exitGroupCountMin" noStyle>
                                <InputNumber placeholder="退群次数-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="exitGroupCountMax" noStyle>
                                <InputNumber placeholder="退群次数-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item label={<strong>留存群聊数</strong>} style={{ marginBottom: 0 }}>
                        <Space>
                            <Form.Item name="retentionGroupCountMin" noStyle>
                                <InputNumber placeholder="留存群聊数-最小" style={{ width: 200 }} />
                            </Form.Item>
                            <span>-</span>
                            <Form.Item name="retentionGroupCountMax" noStyle>
                                <InputNumber placeholder="留存群聊数-最大" style={{ width: 200 }} />
                            </Form.Item>
                        </Space>
                    </Form.Item>
                </div>
                <div className={style.newSpace}>
                    <Form.Item name="allCorp" label={<strong>查询所有公司</strong>} style={{ marginBottom: 0 }} valuePropName='checked'>
                        <Checkbox>是否查询所有公司</Checkbox>
                    </Form.Item>
                </div>
                <Divider orientation="left">群重名过滤</Divider>
                <div className={style.newSpace}>
                    <Form.Item name="isGroupRepeat" label={<strong>群重名过滤筛选</strong>} style={{ marginBottom: 0 }} valuePropName='checked'>
                        <Checkbox>是否开启群重名过滤筛选</Checkbox>
                    </Form.Item>
                </div>
                {isGroupRepeat && <>
                    <div className={style.newSpace}>
                        <Form.Item name="groupRepeatRang" label={<strong>群重名过滤范围</strong>} style={{ marginBottom: 0 }}>
                            <Select
                                showSearch
                                mode='multiple'
                                style={{ minWidth: 110 }}
                                maxTagCount={1}
                                placeholder="请选择主体"
                                filterOption={(input, option) =>
                                    ((option?.label ?? '') as string).toLowerCase().includes(input.toLowerCase())
                                }
                                allowClear
                                options={getCorpAllList?.data?.data?.map((item: any) => ({ label: item.corpName, value: item.corpId + '&&' + item.corpName }))}
                            />
                        </Form.Item>
                    </div>
                    <div className={style.newSpace}>
                        <Form.Item name="groupOperateType" label={<strong>群重名操作类型</strong>} style={{ marginBottom: 0 }} rules={[{ required: true, message: '请选择群重名操作类型' }]}>
                            <Select
                                placeholder='群重名操作类型'
                                allowClear
                                options={[
                                    { value: 0, label: '历史群' },
                                    { value: 1, label: '当前所在群' }
                                ]}
                            />
                        </Form.Item>
                    </div>
                    <div className={style.newSpace}>
                        <Form.Item name="groupNameList" label={<strong>群名称列表</strong>} style={{ marginBottom: 0 }} rules={[{ required: true, message: '请输入群名称列表' }]}>
                            <Input.TextArea placeholder="请输入群名称列表(多个,分割)" rows={2} />
                        </Form.Item>
                    </div>
                </>}
            </>}
        </Form>
    </Modal>
};

export default NewFilterUser;