/**
 * Custom hook for fetching filter options with SWR
 */

'use client';

import useSWR from 'swr';
import { fetcher } from '@/lib/api';
import type { FiltersResponse } from '@/lib/types';

export function useFilters() {
  const { data, error, isLoading } = useSWR<FiltersResponse>(
    '/filters',
    fetcher,
    {
      revalidateOnFocus: false,
      dedupingInterval: 60000, // 1 minute
    }
  );

  return {
    filters: data,
    localAuthorities: data?.local_authorities || [],
    schoolTypes: data?.school_types || [],
    years: data?.years || [],
    isLoading,
    error,
  };
}
