import { useState, useLayoutEffect, useEffect, useCallback, useMemo } from 'react'; import { AnimatePresence, motion } from 'framer-motion'; const getUrlIndex = () => parseInt(window.location.hash.split('#')[1] || 0, 10); export function Slides({ children }) { const visible = useMemo(() => children.filter((child) => !child.props.hidden), [children]); const [slide, setSlide] = useState(getUrlIndex() % visible.length); useEffect(() => { window.location.hash = '#' + slide; }, [slide]); const next = useCallback(() => setSlide((s) => (s + 1) % visible.length), [visible]); const prev = useCallback(() => setSlide((s) => (s + visible.length - 1) % visible.length), [visible]); useLayoutEffect(() => { const handleKeyPress = async (e) => { if (e.ctrlKey && e.altKey) { if (e.code === 'ArrowRight') { next(); } else if (e.code === 'ArrowLeft') { prev(); } e.preventDefault(); } }; window.addEventListener('keydown', handleKeyPress, true); return () => window.removeEventListener('keydown', handleKeyPress, true); }, [slide]); return (