import { useEffect } from "react";
import { EUnleashFlags, useUnleash } from "../ab/unleash/useUnleash";

export const preloadImages = (images: string[]) => {
    if (!images.length) return;
    images.forEach((image) => {
        const img = new Image();
        img.src = image
    });
}

export const usePreloadImages = (images: string[]) => {
    const { isReady, variant } = useUnleash({
        flag: EUnleashFlags.preloadImages
    })

    useEffect(() => {
        if (!isReady || variant === "no") return;
        preloadImages(images)
    }, [images, isReady, variant])
}