import { BaseForm } from './base-form';
import { useLogin } from './hooks/default';
import { useRefreshToken } from './hooks/token';
import { ButtonLoading, ButtonLogin } from './lib/buttons';
import { FormStateContext } from '@/context/form-state';
import { useContext } from 'react';

export function DefaultForm() {
  useRefreshToken();
  const { handleLogin } = useLogin();

  const {
    state: { step, user },
  } = useContext(FormStateContext);

  if (step === 'login' && user) {
    return <ButtonLoading />;
  }

  return (
    <BaseForm onSubmit={(data) => handleLogin(data)}>
      <ButtonLogin />
    </BaseForm>
  );
}
