"use client";

import { useQuery } from "@tanstack/react-query";
import { useAuthSession } from "@/features/auth";
import { queryKeys } from "@/core/api";
import { ordersService } from "@/features/orders/api/orders.api";
import type { OrderSummary } from "@customer-portal/domain/orders";

export function useOrdersList() {
  const { isAuthenticated } = useAuthSession();

  return useQuery<OrderSummary[]>({
    queryKey: queryKeys.orders.list(),
    queryFn: () => ordersService.getMyOrders(),
    enabled: isAuthenticated,
    refetchOnWindowFocus: false,
    refetchOnReconnect: false,
  });
}

export type UseOrdersListResult = ReturnType<typeof useOrdersList>;
