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

import { type FormSwitcherCardProps } from './types';
import SwitcherCard from '.';

const FormSwitcherCard = ({
  name,
  switcherCardProps,
  rules,
  children,
}: FormSwitcherCardProps) => {
  return (
    <Controller
      render={({ field: { value, ref, ...field } }) => (
        <SwitcherCard
          open={Boolean(value)}
          onContentToggle={field.onChange}
          {...field}
          {...switcherCardProps}
        >
          {children}
        </SwitcherCard>
      )}
      name={name}
      rules={rules}
    />
  );
};

export default FormSwitcherCard;
