'use client';
import Image from 'next/image';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Navigation, Pagination, Scrollbar, A11y, Autoplay } from 'swiper';
import { v4 } from 'uuid';
import Link from 'next/link';
import { Queries } from '@/api/queries';
import { useQuery } from '@tanstack/react-query';
import Loader from '../Loader';
import LinkBlock from './LinkBlock';
import { VideoItemModel } from '@/models/videoItem.model';
const SmallSwiperVideos = () => {
const { data, isFetching, error } = useQuery({
queryKey: ['small_slider_videos'],
queryFn: () => Queries.getLastVideos(),
});
if (isFetching) return ;
if (error) return
{JSON.stringify(error)}
;
function chooseRandomItems(inputArray: VideoItemModel[]) {
// Check if the input array has at least 5 items
if (inputArray.length < 5) {
throw new Error('Input array must have at least 5 items');
}
// Use the Fisher-Yates (Knuth) shuffle algorithm to shuffle the array
for (let i = inputArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[inputArray[i], inputArray[j]] = [inputArray[j], inputArray[i]];
}
// Return the first 5 items from the shuffled array
return inputArray.slice(0, 5);
}
return (
{/* PAY ATTENTION [data] is wrapped in an array */}
{data?.data
? chooseRandomItems(data.data).map((item, index) => (
{item.banner_url ? (