/** * BoostMedia AI Content Generator Admin - useStats Hook * * @package BoostMedia_AI * @license GPL-2.0-or-later */ import { useState, useEffect, useCallback } from 'react' import type { DashboardStats, ApiError } from '../types' import { endpoints, getErrorMessage } from '../api/client' interface UseStatsReturn { stats: DashboardStats | null loading: boolean error: ApiError | null refetch: () => Promise } export function useStats(): UseStatsReturn { const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchStats = useCallback(async () => { setLoading(true) setError(null) try { const response = await endpoints.getStats() setStats(response.data as DashboardStats) } catch (err) { setStats(null) setError({ message: getErrorMessage(err, 'Failed to load stats') } as ApiError) } finally { setLoading(false) } }, []) useEffect(() => { fetchStats() }, [fetchStats]) return { stats, loading, error, refetch: fetchStats } }