// src/hooks/useFlyerItems.ts
import type { Flyer } from '../types';
import { useFlyerItemsQuery } from './queries/useFlyerItemsQuery';

/**
 * A custom hook to fetch the items for a given flyer using TanStack Query (ADR-0005).
 *
 * This replaces the previous useApiOnMount implementation with TanStack Query
 * for automatic caching and better state management.
 *
 * @param selectedFlyer The flyer for which to fetch items.
 * @returns An object containing the flyer items, loading state, and any errors.
 *
 * @example
 * ```tsx
 * const { flyerItems, isLoading, error } = useFlyerItems(selectedFlyer);
 * ```
 */
export const useFlyerItems = (selectedFlyer: Flyer | null) => {
  const { data: flyerItems = [], isLoading, error } = useFlyerItemsQuery(selectedFlyer?.flyer_id);

  return { flyerItems, isLoading, error };
};
