import React, { FunctionComponent } from 'react';
import { Radio as AntdRadio } from 'antd';
import { IReactOption, IReactOptionsComponent } from '@wowpic/xform-types';

const RadioButton: FunctionComponent<IReactOptionsComponent> = ({
    options,
    onChange,
    ...props
}) => (
    <AntdRadio.Group onChange={(e) => onChange(e.target.value)} {...props}>
        {options.map(({ label, value, disabled }: IReactOption, index) => (
            <AntdRadio.Button
                key={index}
                value={value}
                disabled={disabled}>
                {label}
            </AntdRadio.Button>
        ))}
    </AntdRadio.Group>
);

export default RadioButton;
