// GET /pantry/activity — recent orders/inventory events for the activity feed.
import { useState, useEffect } from 'react';
import { statsAPI } from '../utils/api';

export interface Activity {
  id: string;
  type: string;
  description: string;
  createdAt: string;
  userId: string;
  metadata?: any;
  user?: {
    id: string;
    fullName?: string;
  };
}

export const useActivity = () => {
  const [activities, setActivities] = useState<Activity[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  const fetchActivity = async () => {
    try {
      setLoading(true);
      setError(null);
      const data = await statsAPI.getActivity();
      setActivities(data.activities || []);
    } catch (err: any) {
      setError(err.message || 'Failed to fetch activity');
      setActivities([]);
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    fetchActivity();
  }, []);

  return { activities, loading, error, refetch: fetchActivity };
};

