import { useAuthStore } from '../store/authStore';
import { TokenStorage } from '@/services/tokenStorage';
import { useUser } from './useUser';

export const useAuth = () => {
  const { isAuthenticated, logout: storeLogout } = useAuthStore();
  const { data: user } = useUser();

  const logout = async () => {
    // Le store gère déjà le logout via la méthode logout
    await storeLogout();
  };

  const accessToken = TokenStorage.getAccessToken();

  return {
    user: user ?? null,
    accessToken: accessToken || null,
    refreshToken: TokenStorage.getRefreshToken() || null,
    isAuthenticated,
    logout,
  };
};
