import { useState, useEffect } from 'react';
import { getCuratorUsage } from '../../../api';

export default function useCuratorUsage(days = 30) {
    const [usage, setUsage] = useState(null);
    const [error, setError] = useState('');

    useEffect(() => {
        let alive = true;
        getCuratorUsage(days)
            .then(d => { if (alive) setUsage(d); })
            .catch(e => { if (alive) setError(e.message); });
        return () => { alive = false; };
    }, [days]);

    return { usage, error };
}
