import { useCallback, useEffect, useState } from "react";
export function useQuota(params) {
    const { showError } = params;
    const [quotaInfo, setQuotaInfo] = useState(null);
    const isQuotaExceeded = useCallback(() => {
        if (!quotaInfo)
            return false;
        const { usage, limits } = quotaInfo;
        if (limits.totalTokens > 0 && usage.totalTokens >= limits.totalTokens)
            return true;
        if (limits.totalImages > 0 && usage.totalImages >= limits.totalImages)
            return true;
        return false;
    }, [quotaInfo]);
    const getQuotaWarningMessage = useCallback(() => {
        if (!quotaInfo)
            return null;
        const { usage, limits } = quotaInfo;
        const warnings = [];
        if (limits.totalTokens > 0) {
            const tokenPercentage = (usage.totalTokens / limits.totalTokens) * 100;
            if (tokenPercentage >= 100)
                warnings.push(`Token limit exceeded (${usage.totalTokens}/${limits.totalTokens})`);
            else if (tokenPercentage >= 90)
                warnings.push(`Token usage high: ${Math.round(tokenPercentage)}% (${usage.totalTokens}/${limits.totalTokens})`);
        }
        if (limits.totalImages > 0) {
            const imagePercentage = (usage.totalImages / limits.totalImages) * 100;
            if (imagePercentage >= 100)
                warnings.push(`Image limit exceeded (${usage.totalImages}/${limits.totalImages})`);
            else if (imagePercentage >= 90)
                warnings.push(`Image usage high: ${Math.round(imagePercentage)}% (${usage.totalImages}/${limits.totalImages})`);
        }
        return warnings.length > 0 ? warnings.join(", ") : null;
    }, [quotaInfo]);
    useEffect(() => {
        const warningMessage = getQuotaWarningMessage();
        if (warningMessage) {
            const exceeded = isQuotaExceeded();
            showError({
                summary: exceeded ? "AI Quota Exceeded" : "AI Quota Warning",
                details: warningMessage,
            });
        }
    }, [quotaInfo, getQuotaWarningMessage, isQuotaExceeded, showError]);
    return {
        quotaInfo,
        setQuotaInfo,
        isQuotaExceeded,
        getQuotaWarningMessage,
    };
}
//# sourceMappingURL=useQuota.js.map