"use client";
import { motion, useMotionValue, useTransform } from 'motion/react';
import { useState, useEffect } from 'react';
import './Stack.css';
function CardRotate({ children, onSendToBack, sensitivity, disableDrag = false }) {
const x = useMotionValue(0);
const y = useMotionValue(0);
const rotateX = useTransform(y, [-100, 100], [60, -60]);
const rotateY = useTransform(x, [-100, 100], [-60, 60]);
function handleDragEnd(_, info) {
if (Math.abs(info.offset.x) > sensitivity || Math.abs(info.offset.y) > sensitivity) {
onSendToBack();
} else {
x.set(0);
y.set(0);
}
}
if (disableDrag) {
return (
)
},
{
id: 2,
content: (
)
},
{
id: 3,
content: (
)
},
{
id: 4,
content: (
)
}
];
}
});
useEffect(() => {
if (cards.length) {
setStack(cards.map((content, index) => ({ id: index + 1, content })));
}
}, [cards]);
const sendToBack = id => {
setStack(prev => {
const newStack = [...prev];
const index = newStack.findIndex(card => card.id === id);
const [card] = newStack.splice(index, 1);
newStack.unshift(card);
return newStack;
});
};
useEffect(() => {
if (autoplay && stack.length > 1 && !isPaused) {
const interval = setInterval(() => {
const topCardId = stack[stack.length - 1].id;
sendToBack(topCardId);
}, autoplayDelay);
return () => clearInterval(interval);
}
}, [autoplay, autoplayDelay, stack, isPaused]);
return (