import type { CharacterValues, SheetWidget, SystemDefinition } from '../shared/types.ts'; import { computeDerived } from '../shared/derived.ts'; type Props = { widget: SheetWidget; system: SystemDefinition; }; /** Compact in-widget preview for design mode (no nested canvas). */ export function WidgetPreview({ widget, system }: Props) { const values: CharacterValues = { attributes: Object.fromEntries( (system.bricks.attributes ?? []).map((a) => [a.key, typeof a.default === 'number' ? a.default : 10]), ), skills: Object.fromEntries( (system.bricks.skills ?? []).map((a) => [a.key, typeof a.default === 'number' ? a.default : 0]), ), resources: Object.fromEntries((system.bricks.resources ?? []).map((a) => [a.key, a.default ?? 0])), meta: { notes: '…', title: system.name }, }; const derived = computeDerived(system.bricks.derived ?? [], values); const bind = widget.bind ?? ''; const [, key] = bind.split('.'); if (widget.type === 'section') { return {String(widget.props?.title ?? 'Section')}; } if (widget.type === 'dots') { const max = Number(widget.props?.max ?? 5); const cur = Number(values.attributes?.[key!] ?? 2); return (
{String(widget.props?.label ?? key)}
{Array.from({ length: max }, (_, i) => ( ))}
); } if (widget.type === 'track' || widget.type === 'resourceBar') { const v = Number(values.resources?.[key!] ?? 5); const max = Number(widget.props?.max ?? 10); return (
{String(widget.props?.label ?? key)}
); } if (widget.type === 'skillList') { return (
{(system.bricks.skills ?? []).slice(0, 4).map((s) => (
{s.label}: {String(values.skills?.[s.key] ?? 0)}
))} …
); } if (widget.type === 'notes' || widget.type === 'text') { return
{String(values.meta?.notes ?? 'Notes')}
; } if (bind.startsWith('derived.')) { return (
{String(widget.props?.label ?? key)}
{derived[key!] ?? 0}
); } if (bind.startsWith('attr.')) { return (
{String(widget.props?.label ?? key)}
{String(values.attributes?.[key!] ?? 10)}
); } return
{widget.type}
; }