import { useState } from 'react'; import { X, Minus, Plus } from 'lucide-react'; import { newId } from '@/lib/ids'; import { getSystem, applyRest } from '@/lib/rules'; import { spendResource, regainResource } from '@/lib/mechanics'; import type { CharacterResource } from '@/lib/schemas'; import { Button } from '@/components/ui/Button'; import { Input, Select } from '@/components/ui/Input'; import { NumberField } from '@/components/ui/NumberField'; import { SheetSection, type SectionProps } from './common'; const RECOVERY_LABEL: Record = { short: 'Short rest', long: 'Long rest', daily: 'Daily', none: 'Manual', }; export function ResourcesSection({ c, update }: SectionProps) { const [name, setName] = useState(''); const sys = getSystem(c.system); const addResource = () => { if (name.trim() === '') return; const r: CharacterResource = { id: newId(), name: name.trim(), current: 1, max: 1, recovery: 'long' }; update({ resources: [...c.resources, r] }); setName(''); }; const patch = (id: string, p: Partial) => update({ resources: c.resources.map((r) => (r.id === id ? { ...r, ...p } : r)) }); const remove = (id: string) => update({ resources: c.resources.filter((r) => r.id !== id) }); const rest = (optId: string) => { const opt = sys.restOptions.find((o) => o.id === optId); if (opt) update(applyRest(c, opt)); }; return ( {sys.restOptions.map((o) => ( ))} } >
{c.resources.length === 0 ? (

No tracked resources. Add rage, ki, sorcery points, focus points, etc.

) : (
    {c.resources.map((r) => (
  • patch(r.id, { name: e.target.value })} aria-label="Resource name" /> {r.current} /{r.max} patch(r.id, { max: v, current: Math.min(v, r.current) })} aria-label="Max" />
  • ))}
)}
); }