/* eslint-disable @next/next/no-img-element */ "use client"; import Link from "next/link"; import { IconWithText } from "../components/IconWithText"; import { useEffect, useRef, useState } from "react"; import useEmblaCarousel from "embla-carousel-react"; import Autoplay from "embla-carousel-autoplay"; import { useInView } from "motion/react"; type ProjectLinkProps = { icon: string; text: string; desc: string; url: string; preview: string[]; }; export const ProjectLink = ({ icon, text, desc, url, preview, }: ProjectLinkProps) => { const [shouldUseCarousel] = useState(preview ? preview.length > 1 : false); const [emblaRef, emblaApi] = useEmblaCarousel({ loop: true }, [ Autoplay({ delay: 5000, playOnInit: false }), ]); const ref = useRef(null); const isInView = useInView(ref); useEffect(() => { if (!shouldUseCarousel) return; if (!emblaApi) return; const autoplay = emblaApi?.plugins()?.autoplay; if (!autoplay) return; if (!isInView) { autoplay.stop(); } else { autoplay.play(); } }, [shouldUseCarousel, emblaApi, isInView]); return (