import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { adminApi } from '../apis';
import { adminKeys } from '../keys';
import { ADMIN_GC_TIME, ADMIN_HOLIDAYS_STALE_TIME, ADMIN_PAGE_SIZE } from '../constants';
import type { HolidayFilters } from '../types';

/** The `iranian_holidays` calendar for a date range. The filter object keys the cache separately. */
export function useHolidays(filters: HolidayFilters, page = 1) {
  return useQuery({
    queryKey: adminKeys.holidayList(filters, { page, pageSize: ADMIN_PAGE_SIZE }),
    queryFn: () => adminApi.listHolidays(filters, { page, pageSize: ADMIN_PAGE_SIZE }),
    staleTime: ADMIN_HOLIDAYS_STALE_TIME,
    gcTime: ADMIN_GC_TIME,
    placeholderData: keepPreviousData,
  });
}
