import type { SegmentedProps, SpaceProps } from 'antd';
import { Form, Segmented as AntSegmented } from 'antd';
import type { BaseElementProps, BaseOption } from './types';

const { Item: FormItem } = Form;

type ElementProps = BaseElementProps<string | number> & {
  options: BaseOption[];
  spaceProps?: SpaceProps;
  style: SegmentedProps['style'];
};

export default function Segmented({
  value,
  setValue,
  options,
  status,
  isValid,
  help,
  spaceProps,
  style,
  ...props
}: ElementProps) {
  return (
    <FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
      <AntSegmented
        value={value}
        onChange={setValue}
        disabled={status === 'Disabled'}
        options={options}
        {...props}
      />
    </FormItem>
  );
}

export { type SegmentedProps } from 'antd';
