"use client";
import React, { useEffect, useState } from "react";
import { cn } from "~/lib/utils";
import ButtonEvent from "../ui/buttons/ButtonEvent";
import UserAvatarBadge from "../core/users/UserAvatarBadge";
import LinkOrAhref from "../ui/buttons/LinkOrAhref";
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import { useLocaleFormatters } from "~/locale/format";
export type InfiniteMovingCardItem = {
company?: string;
companyUrl?: string;
title?: string;
quote: string;
name: string;
personalWebsite?: string;
avatar: string;
role?: string;
createdAt?: Date;
quoteUrl?: string;
};
function Stars({ color = "text-yellow-400" }: { color?: string }) {
return (
{[0, 1, 2, 3, 4].map((item) => (
))}
);
}
export const InfiniteMovingCards = ({
items,
direction = "left",
speed = "fast",
pauseOnHover = true,
className,
}: {
items: InfiniteMovingCardItem[];
direction?: "left" | "right";
speed?: "fast" | "normal" | "slow";
pauseOnHover?: boolean;
className?: string;
}) => {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const containerRef = React.useRef(null);
const scrollerRef = React.useRef(null);
useEffect(() => {
addAnimation();
}, []);
const [start, setStart] = useState(false);
function addAnimation() {
if (containerRef.current && scrollerRef.current) {
const scrollerContent = Array.from(scrollerRef.current.children);
scrollerContent.forEach((item) => {
const duplicatedItem = item.cloneNode(true);
if (scrollerRef.current) {
scrollerRef.current.appendChild(duplicatedItem);
}
});
getDirection();
getSpeed();
setStart(true);
}
}
const getDirection = () => {
if (containerRef.current) {
if (direction === "left") {
containerRef.current.style.setProperty("--animation-direction", "forwards");
} else {
containerRef.current.style.setProperty("--animation-direction", "reverse");
}
}
};
const getSpeed = () => {
if (containerRef.current) {
if (speed === "fast") {
containerRef.current.style.setProperty("--animation-duration", "20s");
} else if (speed === "normal") {
containerRef.current.style.setProperty("--animation-duration", "40s");
} else {
containerRef.current.style.setProperty("--animation-duration", "100s");
}
}
};
const colors = [
"text-green-400",
"text-yellow-400",
"text-purple-400",
"text-blue-400",
"text-red-400",
"text-cyan-400",
"text-indigo-400",
"text-pink-400",
"text-rose-400",
"text-violet-400",
"text-lime-400",
"text-emerald-400",
];
return (
{items.map((testimonial, idx) => {
let randomColor = "text-yellow-400";
if (idx < colors.length) {
randomColor = colors[idx];
} else {
const randomIdx = Math.floor(Math.random() * colors.length);
randomColor = colors[randomIdx];
}
return (
-
{testimonial.quoteUrl && (
)}
{/* {testimonial.name} */}
{testimonial.title}
{/* */}
{testimonial.quote}
{/* */}
{testimonial.avatar ? (

) : (
)}
{testimonial.name}
{testimonial.role && {t(testimonial.role)}
}
{testimonial.company && (
<>
@
{testimonial.companyUrl ? (
{testimonial.company}
) : (
testimonial.company
)}
>
)}
{testimonial.createdAt && (
)}
);
})}
);
};