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

const { Item: FormItem } = Form;

type ElementProps = BaseElementProps<number | string> & {
  options: BaseOption[];
};

function Segmented({
  value,
  setValue,
  options,
  status,
  validateStatus,
  help,
  ...props
}: ElementProps) {
  return (
    <FormItem hasFeedback help={help} validateStatus={validateStatus}>
      <AntSegmented
        disabled={status === 'Disabled'}
        onChange={setValue}
        onResize={undefined}
        onResizeCapture={undefined}
        options={options}
        value={value}
        {...props}
      />
    </FormItem>
  );
}

export default Segmented as FC<Partial<SegmentedProps>>;
