"use client";

import { useQueryClient } from "@tanstack/react-query";
import { useRouter } from "next/navigation";

import { clearAuthCookie } from "@/lib/auth/session";
import { ROUTES } from "@/lib/constants/routes";

/**
 * Client-side logout — the backend has no logout endpoint (JWT is stateless),
 * so clearing the cookie + cached queries and returning to login is the whole
 * flow.
 */
export function useLogout() {
  const queryClient = useQueryClient();
  const router = useRouter();

  return () => {
    clearAuthCookie();
    queryClient.clear();
    router.replace(ROUTES.AUTH.LOGIN);
  };
}
