import React from 'react';
import { Radio } from 'antd';
import { FormItemHeight } from '../constants';

interface IProps {
  label?: string;
  value?: string | number;
  options?: {
    label: string | number;
    value: string | number;
  }[];
  width?: number | string;
  disabled?: boolean;
  onChange?: (value: string | number) => void;
}

const SelectField: React.FC<IProps> = props => {
  const { label = '', value, onChange, options = [], width, disabled } = props;
  return (
    <div className="group">
      <label>{label}</label>
      <Radio.Group
        value={value}
        style={{
          width,
          height: FormItemHeight,
        }}
        disabled={disabled}
        onChange={e => {
          onChange?.(e.target.value);
        }}
      >
        {options.map(item => (
          <Radio key={`${item.value}-${item.label}`} value={item.value}>
            {item.label}
          </Radio>
        ))}
      </Radio.Group>
    </div>
  );
};

export default SelectField;
