"use client";

import { keepPreviousData, useQuery } from "@tanstack/react-query";

import { listProvidersApi } from "@/lib/api/provider.api";
import { queryKeys } from "@/lib/constants/query-keys";
import type { ProviderListParams } from "@/types/provider";

/**
 * Paginated provider list for the admin list screen (server-mode DataTable).
 *
 * `keepPreviousData` keeps the current page rendered while the next one loads,
 * so paging/searching doesn't flash the table back to skeletons.
 */
export function useProviders(params: ProviderListParams) {
  return useQuery({
    queryKey: queryKeys.providers.list(params),
    queryFn: () => listProvidersApi(params),
    placeholderData: keepPreviousData,
  });
}
