{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "nonprofit-spend",
  "title": "Nonprofit: Where the money goes",
  "description": "A large heading beside the share that reaches a home rolling in a raised card, then one bar split by spending line and the lines in pounds and whole percentages that sum to 100 by largest remainder.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://eased.dev/r/eased-tokens.json",
    "https://eased.dev/r/eased-motion.json",
    "https://eased.dev/r/nonprofit-core.json",
    "https://eased.dev/r/number-roll.json"
  ],
  "files": [
    {
      "path": "src/registry/eased/templates/nonprofit/spend.tsx",
      "content": "\"use client\";\n\nimport { motion, useInView } from \"motion/react\";\nimport { useRef } from \"react\";\nimport { enter, instant, stagger, useSafeReducedMotion } from \"../../lib/motion\";\nimport { NumberRoll } from \"../../number-roll/number-roll\";\nimport { formatMoney, locale, sampleNote, spend } from \"./content\";\nimport { largestRemainder } from \"./giving\";\nimport { COLUMN, LABEL, NOTE, Reveal, SECTION } from \"./kit\";\n\n/** Each line's colour in the bar and its key: the three that reach a home in the sea's shades, the rest quiet. */\nconst TONE: Record<string, string> = {\n  filters: \"bg-(--nf-sea)\",\n  fitting: \"bg-(--nf-sea-deep)\",\n  testing: \"bg-(--nf-water)\",\n  fundraising: \"bg-(--nf-sun)\",\n  running: \"bg-line-strong\",\n};\n\n/** The split, worked out once from content: whole percentages that sum to 100, and the share that reaches a home. */\nexport const shares = largestRemainder(spend.lines.map((l) => l.amount));\nexport const spent = spend.lines.reduce((sum, l) => sum + l.amount, 0);\nexport const reaches = spend.lines.reduce((sum, l, i) => sum + (spend.reach.includes(l.id) ? shares[i] : 0), 0);\n\n/**\n * Where the money goes: a large heading and a short line on the left, the share that reaches a\n * home as the section's one big number in a raised card on the right, then a single bar split by\n * spending line across the column and the lines themselves with pounds and percentages. The\n * percentages are whole and sum to 100 by largest remainder, so the bar and the list always\n * agree. The first time it is in view the bar's parts fill from the left, 80ms apart, and the big\n * number rolls up; under reduced motion both are there at once.\n */\nexport function Spend({ className = \"\" }: { className?: string }) {\n  const section = useRef<HTMLElement>(null);\n  const seen = useInView(section, { once: true, amount: 0.3 });\n  const reduced = useSafeReducedMotion();\n  const on = seen || reduced;\n  return (\n    <section ref={section} aria-labelledby=\"spend-title\" className={`${COLUMN} ${SECTION} flex flex-col gap-group ${className}`}>\n      <div className=\"grid gap-group lg:grid-cols-[7fr_5fr] lg:items-stretch lg:gap-group-lg\">\n        <Reveal className=\"flex flex-col justify-between gap-group\">\n          <div className=\"flex flex-col gap-pad-sm\">\n            <p className={LABEL}>{spend.label}</p>\n            <h2 id=\"spend-title\" className=\"font-display text-[clamp(2.75rem,5.5vw,5rem)] leading-[1.02] font-semibold tracking-[-0.04em] text-balance text-text\">\n              {spend.title}\n            </h2>\n          </div>\n          <p className=\"max-w-sm text-ui-md text-pretty text-text-secondary\">{spend.body}</p>\n        </Reveal>\n        <Reveal index={1} className=\"flex min-h-72 flex-col justify-end gap-pad-xs rounded-surface border border-line-subtle bg-surface p-pad-lg shadow-raised\">\n          <NumberRoll\n            value={on ? reaches / 100 : 0}\n            format={{ style: \"percent\" }}\n            locale={locale}\n            className=\"font-display text-[clamp(4.5rem,10vw,8.5rem)] leading-[1.1] font-bold tracking-[-0.055em] text-brand-text tabular-nums\"\n            aria-hidden\n          />\n          <p className=\"text-ui-lg text-text-secondary\">{spend.reachLabel}</p>\n          <span className=\"sr-only\">{`${reaches}% ${spend.reachLabel}`}</span>\n        </Reveal>\n      </div>\n      <div className=\"flex flex-col gap-pad-md\">\n        <div aria-hidden className=\"flex h-16 w-full gap-1 overflow-hidden rounded-panel sm:h-20\">\n          {spend.lines.map((l, i) => (\n            <span key={l.id} className=\"relative h-full overflow-hidden rounded-control-xs\" style={{ width: `${shares[i]}%` }}>\n              <motion.span\n                className={`absolute inset-0 origin-left ${TONE[l.id]}`}\n                initial={false}\n                animate={{ scaleX: on ? 1 : 0 }}\n                transition={reduced ? instant : { ...enter, duration: 0.5, delay: i * stagger.line }}\n              />\n            </span>\n          ))}\n        </div>\n        <table className=\"w-full text-ui-md\">\n          <caption className=\"sr-only\">\n            {spend.label}, {spend.year}\n          </caption>\n          <thead className=\"sr-only\">\n            <tr>\n              {spend.columns.map((c) => (\n                <th key={c} scope=\"col\">\n                  {c}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {spend.lines.map((l, i) => (\n              <tr key={l.id} className=\"border-b border-line-subtle\">\n                <th scope=\"row\" className=\"py-3 pe-pad-sm text-left font-normal text-text\">\n                  <span className=\"flex items-center gap-2.5\">\n                    <span aria-hidden className={`size-3 shrink-0 rounded-[3px] ${TONE[l.id]}`} />\n                    {l.label}\n                  </span>\n                </th>\n                <td className=\"py-3 pe-pad-sm text-right whitespace-nowrap text-text-secondary tabular-nums max-sm:hidden\">{formatMoney(l.amount)}</td>\n                <td className=\"w-14 py-3 text-right font-medium text-text tabular-nums\">{shares[i]}%</td>\n              </tr>\n            ))}\n          </tbody>\n          <tfoot>\n            <tr>\n              <th scope=\"row\" className=\"pt-3 text-left font-medium text-text\">\n                {spend.total}\n              </th>\n              <td className=\"pt-3 pe-pad-sm text-right font-medium whitespace-nowrap text-text tabular-nums max-sm:hidden\">{formatMoney(spent)}</td>\n              <td className=\"pt-3 text-right font-medium text-text tabular-nums\">100%</td>\n            </tr>\n          </tfoot>\n        </table>\n        <p className={NOTE}>\n          {spend.year}. {sampleNote}\n        </p>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/eased/templates/nonprofit/spend.tsx"
    }
  ],
  "meta": {
    "template": "nonprofit",
    "kind": "template-section",
    "industries": [
      "health"
    ]
  },
  "type": "registry:block"
}