/**
 * Custom hook for fetching school details with SWR
 */

'use client';

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

export function useSchoolDetails(urn: number | null) {
  const { data, error, isLoading, mutate } = useSWR<SchoolDetailsResponse>(
    urn ? `/schools/${urn}` : null,
    fetcher,
    {
      revalidateOnFocus: false,
      dedupingInterval: 30000, // 30 seconds
    }
  );

  return {
    schoolInfo: data?.school_info,
    yearlyData: data?.yearly_data || [],
    isLoading,
    error,
    mutate,
  };
}
