import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { partnerCenterApi } from '../apis';
import { centerKeys } from '../keys';
import { PARTNER_GC_TIME, PARTNER_LIST_STALE_TIME, PARTNER_PAGE_SIZE } from '../constants';
import type { PartnerCenterFilters } from '../types';

/** Admin list of partner centers (no IBAN, sponsored-nurse counts). Filters + page key the cache. */
export function usePartnerCenters(filters: PartnerCenterFilters, page = 1) {
  return useQuery({
    queryKey: centerKeys.list(filters, { page, pageSize: PARTNER_PAGE_SIZE }),
    queryFn: () => partnerCenterApi.listCenters(filters, { page, pageSize: PARTNER_PAGE_SIZE }),
    staleTime: PARTNER_LIST_STALE_TIME,
    gcTime: PARTNER_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
