/**
 * Hook for calculating My Requests statistics
 */

import { useMemo } from 'react';
import { MyRequest, MyRequestsStats } from '../types/myRequests.types';

interface UseMyRequestsStatsOptions {
  requests: MyRequest[];
  totalRecords?: number;
}

export function useMyRequestsStats({ requests, totalRecords }: UseMyRequestsStatsOptions): MyRequestsStats {
  const stats = useMemo(() => {
    return {
      total: totalRecords || requests.length,
      pending: requests.filter((r) => r.status === 'pending').length,
      paused: requests.filter((r) => r.status === 'paused').length,
      approved: requests.filter((r) => r.status === 'approved').length,
      rejected: requests.filter((r) => r.status === 'rejected').length,
      draft: requests.filter((r) => r.status === 'draft').length,
      closed: requests.filter((r) => r.status === 'closed').length,
    };
  }, [requests, totalRecords]);

  return stats;
}

