import type { BaseElementProps } from './types';
import type { SwitchProps } from 'antd';
import { Form, Switch as AntSwitch } from 'antd';
import type { FC } from 'react';

const { Item: FormItem } = Form;

function Switch({ value, setValue, status, isValid, help, ...props }: BaseElementProps<boolean>) {
  return (
    <FormItem hasFeedback help={help} validateStatus={isValid === false ? 'error' : ''}>
      <AntSwitch checked={value} disabled={status === 'Disabled'} onChange={setValue} {...props} />
    </FormItem>
  );
}

export default Switch as FC<SwitchProps>;
