import React, { PropsWithChildren } from 'react';
import { useFormContext } from 'react-hook-form';
import { Button } from '@/components/ui/button';

type FormResetProps = {
  asChild?: boolean;
} & PropsWithChildren;

export const FormReset: React.FC<FormResetProps> = ({ children, asChild }) => {
  const {
    reset,
    formState: { isSubmitting, isDirty }
  } = useFormContext();

  return (
    <Button
      type='button'
      variant='outline'
      onClick={() => reset()}
      disabled={isSubmitting || !isDirty}
      asChild={asChild}
    >
      {children}
    </Button>
  );
};
