import { toggleEqualHeight } from "../shared/helpFn"; import TemplateOne from "../shared/templates/templateCards/templateOne"; import { Swiper, SwiperSlide } from "swiper/react"; // Import Swiper styles import "swiper/css"; import "swiper/css/pagination"; // import required modules import { Autoplay, Navigation } from "swiper/modules"; import { SwiperNavButton } from "../shared/templates/templates-parts/templates-parts"; import { Fragment, useEffect, useRef, useState } from "@wordpress/element"; import Marquee from "react-fast-marquee"; import { breakpoint } from "../../controls/controls"; const Render = ({ attributes, posts, page = "frontend" }) => { const { uniqueId, timelineLayout, imagePosition, equalHeightEnable, // postTimelineNavArrow, carouselArrowStyle, dynamicClassNames, postTimelineAutoPlay, postTimelineAutoPlayDelay, carouselPauseOnHover, carouselDirection, carouselStyle, contentVerticalPosition, carouselColumn, carouselGap, carouselSpeed, postTimelineTickerSpeed, navArrowVisibilityOnHover, catTabCategoryPosition, contentOrientation, carouselNavArrow, align, imageFeaturedImg, catTabCategoryEnable, titleShow, excerptShow, showReadMoreButton, socialShareEnableSocial, metaDataArray, } = attributes; const swiperNevNextRef = useRef(null); const swiperNevPrevRef = useRef(null); const spTickerRef = useRef(null); const [getLargeItemHeight, setGetLargeItemHeight] = useState(0); const [swiperKeys, setSwiperKeys] = useState(null); const deviceType = breakpoint(); const [tickerWidth, setTickerWidth] = useState(spTickerRef && spTickerRef.current?.clientWidth); // Equalizing the post cards height. useEffect(() => { setTimeout(() => { toggleEqualHeight(uniqueId, equalHeightEnable); let timelineThreeCardElement = spTickerRef?.current ? spTickerRef?.current?.querySelectorAll(".sp-smart-post-card") : []; timelineThreeCardElement = Array.from(timelineThreeCardElement); let largeItemHeight = 0; timelineThreeCardElement.forEach((element) => { if (element && element.clientHeight > largeItemHeight) { largeItemHeight = element.clientHeight; } }); if (largeItemHeight) { setGetLargeItemHeight(largeItemHeight + 60); } }, 50); }, [ equalHeightEnable, uniqueId, posts, align, imageFeaturedImg, catTabCategoryEnable, titleShow, excerptShow, showReadMoreButton, socialShareEnableSocial, metaDataArray, ]); useEffect(() => { setSwiperKeys(Math.random(Math.random * 10)); }, [postTimelineAutoPlay]); const equalHeightClass = equalHeightEnable ? "sp-equal-height-wrapper" : ""; const [selectedPostId, setSelectedPostId] = useState(null); useEffect(() => { const handleClickOutside = (event) => { if (spTickerRef.current && !spTickerRef.current.contains(event.target)) { setSelectedPostId(null); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); useEffect(() => { // Template Card Width for Ticker layout on conditional device type. const timeOut = setTimeout(() => { let newData = spTickerRef && spTickerRef.current?.clientWidth; setTickerWidth(newData); newData = newData && newData / carouselColumn.device?.[deviceType] - 20; setTickerWidth(newData); }, 0); return () => clearTimeout(timeOut); }, [deviceType, carouselColumn]); return (