import { type FC } from 'react';
import { Controller } from 'react-hook-form';

import { type FormSwitcherProps } from './types';
import Switcher from '.';

const FormSwitcher: FC<FormSwitcherProps> = ({
  name,
  switcherProps,
  rules,
}) => {
  return (
    <Controller
      name={name}
      rules={rules}
      render={({ field: { value, onChange } }) => (
        <Switcher
          {...switcherProps}
          value={Boolean(value)}
          onChange={onChange}
        />
      )}
    />
  );
};

export type { FormSwitcherProps };

export default FormSwitcher;
