import { memo, useEffect, useMemo, useRef, useState } from 'react' import { cn } from 'ui' const ROWS = 4 const COLS = 6 const TOTAL = ROWS * COLS const ServerLightCell = memo(function ServerLightCell({ index, isActive, }: { index: number isActive: boolean }) { const row = Math.floor(index / COLS) const col = index % COLS return (
) }) const GRID_STYLE = { gridTemplateColumns: `repeat(${COLS}, 1fr)`, gridTemplateRows: `repeat(${ROWS}, 1fr)`, } as const const CELL_INDICES = Array.from({ length: TOTAL }, (_, i) => i) function randomDelay() { return 400 + Math.random() * 1400 } function randomOnDuration() { return 200 + Math.random() * 800 } export function ServerLightGrid() { const [active, setActive] = useState>(() => new Set()) const timers = useRef>>(new Map()) useEffect(() => { if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return const timerMap = timers.current function scheduleBlink(index: number) { const offDelay = randomDelay() const timer = setTimeout(() => { setActive((prev) => { const next = new Set(prev) next.add(index) return next }) const onDuration = randomOnDuration() const offTimer = setTimeout(() => { setActive((prev) => { const next = new Set(prev) next.delete(index) return next }) scheduleBlink(index) }, onDuration) timerMap.set(index, offTimer) }, offDelay) timerMap.set(index, timer) } for (let i = 0; i < TOTAL; i++) { scheduleBlink(i) } return () => { timerMap.forEach(clearTimeout) timerMap.clear() } }, []) const cells = useMemo( () => CELL_INDICES.map((i) => ), [active] ) return (
{cells}
) }