import { useMutation } from '@tanstack/react-query';
import { authApi } from '../api/authApi';
import { useAuthStore } from '../store/authStore';
import { LoginCredentials, AuthResponse } from '../types/index';

export const useLogin = () => {
  const loginStore = useAuthStore((state) => state.login);

  return useMutation<AuthResponse, Error, LoginCredentials>({
    mutationFn: authApi.login,
    onSuccess: (data) => {
      loginStore(data);
    },
  });
};