import React from 'react';
import { Checkbox, Form } from 'antd';
import type { CheckboxProps } from 'antd/es/checkbox';
import type { FormItemProps } from 'antd/es/form';

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

export default function FormCheckbox({
    name,
    label,
    help,
    valuePropName = 'checked',
    rules,
    ...checkboxProps
}: FormCheckboxProps) {
    return (
        <Form.Item
            name={name}
            label={label}
            valuePropName={valuePropName}
            rules={rules}
            help={help}
        >
            <Checkbox {...checkboxProps}>{checkboxProps.children}</Checkbox>
        </Form.Item>
    );
}
