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 },
  } = useContext(FormStateContext);

  if (step === 'refresh-token') {
    return <ButtonLoading>Подождите...</ButtonLoading>;
  }

  return (
    <BaseForm onSubmit={(data) => handleLogin(data)}>
      <ButtonLogin>Войти</ButtonLogin>
    </BaseForm>
  );
}
