import { useEffect, useRef } from "react";
import { Link } from "react-router";
import { gsap } from "gsap";
import perfumes from "../data/perfumes";
import "../pages/LandingPage.css";
import "../style/navbar.css";
function LandingPage() {
const cardRefs = useRef([]);
useEffect(() => {
const cards = cardRefs.current.filter(Boolean);
const cardStates = cards
.map((card) => {
const hoverFill = card.querySelector(".product-hover-fill");
const hoverVideo = card.querySelector(".product-hover-video");
const productImage = card.querySelector(".product-image");
const arrow = card.querySelector(".arrow");
if (!hoverFill || !productImage || !arrow) {
return null;
}
gsap.set(hoverFill, { autoAlpha: 0, scale: 1.08 });
gsap.set(productImage, { autoAlpha: 1, scale: 1 });
gsap.set(arrow, { x: 0 });
return { card, hoverFill, hoverVideo, productImage, arrow };
})
.filter(Boolean);
const stopVideo = (video) => {
if (!video) return;
video.pause();
try {
video.currentTime = 0;
} catch {
// Ignore errors when setting currentTime
}
};
const playVideo = (video) => {
if (!video) return;
try {
video.currentTime = 0;
} catch {
// Ignore errors when setting currentTime
}
const playAttempt = video.play();
if (playAttempt && typeof playAttempt.catch === "function") {
playAttempt.catch(() => {});
}
};
const deactivate = (state) => {
gsap.killTweensOf([state.hoverFill, state.productImage, state.arrow]);
stopVideo(state.hoverVideo);
gsap.to(state.hoverFill, {
autoAlpha: 0,
scale: 1.08,
duration: 0.35,
ease: "power2.out",
overwrite: "auto",
});
gsap.to(state.productImage, {
scale: 1,
autoAlpha: 1,
duration: 0.35,
ease: "power2.out",
overwrite: "auto",
});
gsap.to(state.arrow, {
x: 0,
duration: 0.35,
ease: "power2.out",
overwrite: "auto",
});
};
const activate = (state) => {
cardStates.forEach((item) => {
if (item !== state) {
deactivate(item);
}
});
gsap.killTweensOf([state.hoverFill, state.productImage, state.arrow]);
playVideo(state.hoverVideo);
gsap.to(state.hoverFill, {
autoAlpha: 1,
scale: 1,
duration: 0.45,
ease: "power2.out",
overwrite: "auto",
});
gsap.to(state.productImage, {
scale: 0.92,
autoAlpha: 0.35,
duration: 0.45,
ease: "power2.out",
overwrite: "auto",
});
gsap.to(state.arrow, {
x: 8,
duration: 0.45,
ease: "power2.out",
overwrite: "auto",
});
};
const cardCleanups = cardStates.map((state) => {
const onEnter = () => activate(state);
const onLeave = () => deactivate(state);
state.card.addEventListener("pointerenter", onEnter);
state.card.addEventListener("pointerleave", onLeave);
return () => {
state.card.removeEventListener("pointerenter", onEnter);
state.card.removeEventListener("pointerleave", onLeave);
};
});
const resetAll = () => {
cardStates.forEach((state) => deactivate(state));
};
const onMouseOutWindow = (event) => {
if (!event.relatedTarget) {
resetAll();
}
};
window.addEventListener("blur", resetAll);
document.addEventListener("mouseout", onMouseOutWindow);
return () => {
window.removeEventListener("blur", resetAll);
document.removeEventListener("mouseout", onMouseOutWindow);
cardCleanups.forEach((cleanup) => cleanup());
};
}, []);
return (
WÄHLE EINE
ATMOSPHÄRE
{perfumes.map((item, index) => (
{
cardRefs.current[index] = el;
}}
>
{item.fillVideo ? (
) : (
)}
{item.id}
{item.name}
))}
DER SICHERE EINSTIEG
DISCOVERY SET
Alle 6 Düfte als 2ml Samples 2ml.
Jeden Duft eine Woche tragen.
Verstehen, was funktioniert.
);
}
export default LandingPage;