'use client'; import { useId } from 'react'; import styles from './battle-wheel.module.css'; export type BattleWheelProps = { value: number; onChange: (value: number) => void; max: number; step: number; disabled?: boolean; id?: string; }; const point = (angle: number, radius: number) => ({ x: 100 + Math.sin((angle * Math.PI) / 180) * radius, y: 100 - Math.cos((angle * Math.PI) / 180) * radius, }); /** The parent supplies the dial limits and labels the numeric input by its ID. */ export function BattleWheel({ value, onChange, max, step, disabled = false, id = 'forces-dialed', }: BattleWheelProps) { const graphicId = useId(); const rimId = `${graphicId}-rim`; const faceId = `${graphicId}-face`; const fraction = max > 0 ? Math.min(1, Math.max(0, value / max)) : 0; const angle = -135 + fraction * 270; // This caps decorative detail only; the native controls keep the supplied step. const divisions = Math.min(80, Math.max(1, Math.ceil(max / step))); const labels = [ ...new Set( [0, 0.25, 0.5, 0.75, 1].map((position) => Math.min(max, Math.round((max * position) / step) * step), ), ), ]; return (
onChange(Number(event.target.value))} />
onChange(Number(event.target.value))} />
); }