import React, { FunctionComponent } from 'react';
import { Checkbox as AntdCheckbox } from 'antd';
import { IReactOptionsComponent } from '@wowpic/xform-types';

const Checkbox: FunctionComponent<IReactOptionsComponent> = ({
    onChange,
    value,
    ...props
}) => {
    if (props.options && props.options.length > 0) {
        return (
            <AntdCheckbox.Group value={value} onChange={onChange} {...props} />
        );
    }
    return (
        <AntdCheckbox checked={value} onChange={(e) => onChange(e.target.checked)} {...props} />
    );
};

export default Checkbox;
