import { useEffect, useState } from 'react'; import styles from './AnalogClock.module.css'; // ── SVG-Konstanten ──────────────────────────────────────────────────────────── const CX = 50; const CY = 50; const R = 43; /** Berechnet die Spitzenkoordinaten eines Uhrzeigers. */ function handTip( cx: number, cy: number, deg: number, length: number, ): { x: number; y: number } { // 0° = 12 Uhr, im Uhrzeigersinn const rad = ((deg - 90) * Math.PI) / 180; return { x: cx + length * Math.cos(rad), y: cy + length * Math.sin(rad), }; } // ── Komponente ──────────────────────────────────────────────────────────────── export function AnalogClock() { const [now, setNow] = useState(() => new Date()); useEffect(() => { const id = setInterval(() => setNow(new Date()), 1000); return () => clearInterval(id); }, []); const h = now.getHours() % 12; const m = now.getMinutes(); const s = now.getSeconds(); const hourDeg = h * 30 + m * 0.5; // 360° / 12h const minuteDeg = m * 6 + s * 0.1; // 360° / 60min const secondDeg = s * 6; // 360° / 60s const hTip = handTip(CX, CY, hourDeg, 26); const mTip = handTip(CX, CY, minuteDeg, 34); const sTip = handTip(CX, CY, secondDeg, 37); const sBase = handTip(CX, CY, secondDeg + 180, 10); // Gegengewicht const timeStr = now.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', }); const dateStr = now.toLocaleDateString('de-DE', { weekday: 'long', day: '2-digit', month: 'long', year: 'numeric', }); return (