/**
 * Custom hook for fetching metric definitions with SWR
 */

'use client';

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

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

  return {
    metrics: data?.metrics || [],
    metricsList: data?.metrics || [],
    getMetric: (key: string) => data?.metrics?.find(m => m.key === key),
    isLoading,
    error,
  };
}
