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

const { Item: FormItem } = Form;

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

export type { SwitchProps };
