import React from 'react';
import { Switch, Form } from 'antd';
import type { SwitchProps } from 'antd/es/switch';
import type { FormItemProps } from 'antd/es/form';

interface FormSwitchProps extends Omit<SwitchProps, 'name'>, Omit<FormItemProps, 'name' | 'children'> {
    name: string | (string | number)[];
    label?: string;
    help?: string;
    valuePropName?: string;
}

export default function FormSwitch({
    name,
    label,
    help,
    valuePropName = 'checked',
    rules,
    ...switchProps
}: FormSwitchProps) {
    return (
        <Form.Item
            name={name}
            label={label}
            valuePropName={valuePropName}
            rules={rules}
            help={help}
        >
            <Switch {...switchProps} />
        </Form.Item>
    );
}
