import { useEffect, useState, useMemo, useCallback } from "react";
import { getReviews } from "../services/reviewsService";
export function useReviews({ currentItemDescriptor, addSocketMessageListener, }) {
    const [reviews, setReviews] = useState([]);
    const loadReviews = useCallback(async () => {
        if (!currentItemDescriptor)
            return;
        const reviewsResult = await getReviews(currentItemDescriptor.id, currentItemDescriptor.language, currentItemDescriptor.version);
        if (reviewsResult.data) {
            setReviews(reviewsResult.data);
        }
    }, [currentItemDescriptor]);
    useEffect(() => {
        void loadReviews();
    }, [loadReviews]);
    useEffect(() => {
        return addSocketMessageListener((message) => {
            if (message.type === "reviews-updated") {
                void loadReviews();
            }
        });
    }, [addSocketMessageListener, loadReviews]);
    return useMemo(() => ({ reviews, loadReviews }), [reviews, loadReviews]);
}
//# sourceMappingURL=useReviews.js.map