import { h, render } from 'https://esm.sh/preact@10'; import { useState, useLayoutEffect, useRef } from 'https://esm.sh/preact@10/hooks'; import { html } from 'https://esm.sh/htm@3/preact'; const IMAGES = [ { src: '/modules/custom/riverside_pt/images/hero.jpg', alt: 'Physical therapy session' }, { src: '/modules/custom/riverside_pt/images/Frame_6.png', alt: 'Patient care' }, { src: '/modules/custom/riverside_pt/images/hero.jpg', alt: 'Rehabilitation' }, { src: '/modules/custom/riverside_pt/images/Frame_6.png', alt: 'Our facility' }, ]; function Carousel() { const [index, setIndex] = useState(0); const [itemWidth, setItemWidth] = useState(0); const containerRef = useRef(/** @type {HTMLDivElement | null} */ (null)); useLayoutEffect(() => { const update = () => { if (containerRef.current) setItemWidth(containerRef.current.offsetWidth / 1.5); }; update(); window.addEventListener('resize', update); return () => window.removeEventListener('resize', update); }, []); const prev = () => setIndex(i => Math.max(0, i - 1)); const next = () => setIndex(i => Math.min(IMAGES.length - 1, i + 1)); return html`