import type { SystemDefinition, CharacterValues, SheetWidget } from '../shared/types.ts'; import { computeDerived } from '../shared/derived.ts'; type Props = { system: SystemDefinition; values: CharacterValues; mode: 'design' | 'fill' | 'preview'; selectedWidgetId?: string | null; onSelectWidget?: (id: string) => void; onChangeValue?: (path: string, value: unknown) => void; }; function widgetContent( widget: SheetWidget, system: SystemDefinition, values: CharacterValues, mode: Props['mode'], onChangeValue?: Props['onChangeValue'], ) { const bind = widget.bind ?? ''; const [scope, key] = bind.split('.'); const editable = mode === 'fill'; if (widget.type === 'section') { return {String(widget.props?.title ?? widget.id)}; } if (widget.type === 'modBadge' || widget.type === 'number' || bind.startsWith('derived.')) { const derived = values.derived ?? {}; let display: string | number = '—'; if (scope === 'attr') display = (values.attributes?.[key!] as number) ?? '—'; if (scope === 'resource') display = values.resources?.[key!] ?? '—'; if (scope === 'derived') display = derived[key!] ?? '—'; if (editable && scope === 'attr' && typeof display === 'number') { return ( ); } return (
{String(widget.props?.label ?? key ?? widget.type)}
{display}
); } if (widget.type === 'dots') { const max = Number(widget.props?.max ?? 5); const current = scope === 'attr' ? Number(values.attributes?.[key!] ?? 0) : scope === 'skill' ? Number(values.skills?.[key!] ?? 0) : 0; return (
{String(widget.props?.label ?? key)}
{Array.from({ length: max }, (_, i) => (
); } if (widget.type === 'track' || widget.type === 'resourceBar') { const v = values.resources?.[key!] ?? 0; const max = Number(widget.props?.max ?? 10); return (