"use client"; import { useEffect, useRef, useState } from "react"; import { getRoomBackground, type RoomBackgroundId, } from "@/lib/room-backgrounds"; import { cn } from "@/lib/utils"; type ParallaxRoomBackgroundProps = { roomId: RoomBackgroundId; className?: string; interactive?: boolean; }; export function ParallaxRoomBackground({ roomId, className, interactive = true, }: ParallaxRoomBackgroundProps) { const containerRef = useRef(null); const [offset, setOffset] = useState({ x: 0, y: 0 }); const room = getRoomBackground(roomId); useEffect(() => { if (!interactive) { return; } const container = containerRef.current; if (!container) { return; } const handlePointerMove = (event: PointerEvent) => { const rect = container.getBoundingClientRect(); const x = ((event.clientX - rect.left) / rect.width - 0.5) * 2; const y = ((event.clientY - rect.top) / rect.height - 0.5) * 2; setOffset({ x, y }); }; container.addEventListener("pointermove", handlePointerMove); return () => { container.removeEventListener("pointermove", handlePointerMove); }; }, [interactive]); return (
{room.layers.map((layer, index) => (
))}
); }