import { useCallback, useState } from 'react';
import { useUnreadPolling } from '../hook/useUnreadPolling';
import { apiFetch } from '../../../../../lib/fetch/apiClient';
const normalizeUnreadCount = (count) => {
    const normalized = Number(count || 0);
    return Number.isFinite(normalized) && normalized > 0 ? Math.floor(normalized) : 0;
};
export function useNotificationUnreadPolling(intervalMs = 5000, enabled = true) {
    const [unreadCount, setUnreadCount] = useState(0);
    const fetchUnreadCount = useCallback(async () => {
        try {
            const data = (await apiFetch('/inapp-noti/notification/unread-count', {
                method: 'GET',
            }));
            setUnreadCount(normalizeUnreadCount(data === null || data === void 0 ? void 0 : data.unread_count));
        }
        catch (error) {
            console.error('Error fetching unread count:', error);
        }
    }, []);
    const applyUnreadCount = useCallback((count) => {
        setUnreadCount(normalizeUnreadCount(count));
    }, []);
    useUnreadPolling(fetchUnreadCount, intervalMs, enabled);
    return {
        unreadCount,
        refetchUnreadCount: fetchUnreadCount,
        applyUnreadCount,
    };
}
//# sourceMappingURL=useNotificationUnreadPolling.js.map