{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "insight-digest-card",
  "title": "Insight Digest Card",
  "description": "A short digest written by an AI agent: one sentence to remember, findings ranked by impact, the evidence behind each, and a way to turn it into a task.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/insight-digest-card/insight-digest-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type InsightKind = \"win\" | \"risk\" | \"watch\";\n\nexport interface InsightEvidence {\n  label: string;\n  value: string;\n}\n\nexport interface DigestInsight {\n  id: string;\n  kind: InsightKind;\n  title: string;\n  /** A short figure, e.g. \"+$12.4k\". */\n  impact: string;\n  why: string;\n  /** Recent values, drawn as a small area chart. */\n  series: number[];\n  seriesLabel: string;\n  evidence: InsightEvidence[];\n}\n\nexport interface InsightDigestCardProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  /** Who wrote it and from what. */\n  byline?: string;\n  /** The one sentence to remember. */\n  headline?: string;\n  insights?: DigestInsight[];\n  onCreateTask?: (insight: DigestInsight) => void;\n  onDismiss?: (insight: DigestInsight) => void;\n}\n\ntype Outcome = \"task\" | \"dismissed\";\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\n\nconst KINDS: Record<InsightKind, { label: string; color: string }> = {\n  win: { label: \"Win\", color: \"#27A644\" },\n  risk: { label: \"Risk\", color: \"#EB5757\" },\n  watch: { label: \"Watch\", color: \"#FC7840\" },\n};\n\nconst PALETTES = {\n  dark: {\n    card: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    row: \"rgba(255,255,255,0.05)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    row: \"rgba(8,9,10,0.04)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_INSIGHTS: DigestInsight[] = [\n  {\n    id: \"checkout\",\n    kind: \"risk\",\n    title: \"Checkout is failing on older iPhones\",\n    impact: \"−$21k\",\n    why: \"The new address field doesn't load on iOS 15, so those buyers can't finish paying.\",\n    seriesLabel: \"Completed checkouts, older iPhones\",\n    series: [62, 60, 63, 61, 58, 44, 31, 28, 27, 29],\n    evidence: [\n      { label: \"Drop since release\", value: \"−54%\" },\n      { label: \"Orders lost this week\", value: \"312\" },\n      { label: \"Error reports\", value: \"87\" },\n    ],\n  },\n  {\n    id: \"search\",\n    kind: \"win\",\n    title: \"Search is bringing in more trials\",\n    impact: \"+$12.4k\",\n    why: \"Three comparison pages now rank on page one, and those visitors start trials twice as often.\",\n    seriesLabel: \"Trials from search\",\n    series: [31, 33, 32, 36, 38, 41, 44, 43, 47, 52],\n    evidence: [\n      { label: \"Trials this week\", value: \"+18%\" },\n      { label: \"Top page\", value: \"/compare\" },\n      { label: \"Trial rate\", value: \"6.1%\" },\n    ],\n  },\n  {\n    id: \"annual\",\n    kind: \"win\",\n    title: \"Annual pricing is winning\",\n    impact: \"+$7.9k\",\n    why: \"Showing the yearly price first moved more new customers on to annual plans.\",\n    seriesLabel: \"Share of annual plans\",\n    series: [22, 23, 22, 25, 27, 28, 30, 31, 33, 34],\n    evidence: [\n      { label: \"Annual share\", value: \"34%\" },\n      { label: \"Change\", value: \"+12 points\" },\n      { label: \"Refunds\", value: \"No change\" },\n    ],\n  },\n  {\n    id: \"support\",\n    kind: \"watch\",\n    title: \"Support replies are slowing down\",\n    impact: \"+41 min\",\n    why: \"Tickets rose after Tuesday's release, and the first reply now takes longer in the evenings.\",\n    seriesLabel: \"First reply time, minutes\",\n    series: [38, 36, 40, 37, 42, 55, 61, 68, 74, 79],\n    evidence: [\n      { label: \"First reply\", value: \"1h 19m\" },\n      { label: \"Open tickets\", value: \"146\" },\n      { label: \"Busiest window\", value: \"18:00 to 21:00\" },\n    ],\n  },\n];\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\nfunction Area({ series, color }: { series: number[]; color: string }) {\n  const id = React.useId();\n  const max = Math.max(...series);\n  const min = Math.min(...series);\n  const span = max - min || 1;\n  const x = (i: number) => Math.round((i / (series.length - 1)) * 1000) / 10;\n  const y = (v: number) => Math.round((90 - ((v - min) / span) * 80) * 10) / 10;\n  const line = series.map((v, i) => `${i ? \"L\" : \"M\"}${x(i)} ${y(v)}`).join(\" \");\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 100 100\"\n      preserveAspectRatio=\"none\"\n      className=\"block h-14 w-full\"\n    >\n      <defs>\n        <linearGradient id={id} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n          <stop offset=\"0\" stopColor={color} stopOpacity=\"0.2\" />\n          <stop offset=\"1\" stopColor={color} stopOpacity=\"0\" />\n        </linearGradient>\n      </defs>\n      <path d={`${line} L100 100 L0 100 Z`} fill={`url(#${id})`} />\n      <path\n        d={line}\n        fill=\"none\"\n        stroke={color}\n        strokeWidth=\"1.5\"\n        vectorEffect=\"non-scaling-stroke\"\n      />\n    </svg>\n  );\n}\n\nexport function InsightDigestCard({\n  theme = \"dark\",\n  title = \"This week's digest\",\n  byline = \"Written by Scout from 6 sources, Monday 08:00\",\n  headline = \"Search is working, but older iPhones are costing you more than it brings in.\",\n  insights = DEFAULT_INSIGHTS,\n  onCreateTask,\n  onDismiss,\n  className,\n  style,\n  ...rest\n}: InsightDigestCardProps) {\n  const c = PALETTES[theme];\n  const [selected, setSelected] = React.useState(insights[0]?.id ?? \"\");\n  const [outcomes, setOutcomes] = React.useState<Record<string, Outcome>>({});\n  const open = insights.filter((i) => !outcomes[i.id]).length;\n\n  const settle = (insight: DigestInsight, outcome: Outcome) => {\n    setOutcomes((prev) => ({ ...prev, [insight.id]: outcome }));\n    if (outcome === \"task\") onCreateTask?.(insight);\n    else onDismiss?.(insight);\n  };\n\n  const undo = (id: string) => {\n    setOutcomes((prev) => {\n      const next = { ...prev };\n      delete next[id];\n      return next;\n    });\n  };\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <header className=\"p-5 @2xl:p-6\">\n        <div\n          className=\"flex items-center justify-between gap-3 text-[12.5px] leading-[18px] tracking-[-0.008em] tabular-nums\"\n          style={{ color: c.sub }}\n        >\n          <span className=\"truncate\">{title}</span>\n          <span aria-live=\"polite\" className=\"shrink-0\">\n            {open} of {insights.length} open\n          </span>\n        </div>\n        <h3 className=\"m-0 mt-2 max-w-[640px] text-[20px] leading-[28px] font-[590] tracking-[-0.018em] text-balance\">\n          {headline}\n        </h3>\n        <p\n          className=\"m-0 mt-1.5 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n          style={{ color: c.faint }}\n        >\n          {byline}\n        </p>\n      </header>\n\n      <div\n        className=\"grid border-t @2xl:grid-cols-[minmax(0,1fr)_minmax(0,1.05fr)]\"\n        style={{ borderColor: c.border }}\n      >\n        <ul className=\"m-0 flex list-none flex-col gap-0.5 p-3\">\n          {insights.map((insight) => {\n            const kind = KINDS[insight.kind];\n            const outcome = outcomes[insight.id];\n            return (\n              <li key={insight.id}>\n                <button\n                  type=\"button\"\n                  data-finding={insight.id}\n                  aria-current={selected === insight.id ? \"true\" : undefined}\n                  onClick={() => setSelected(insight.id)}\n                  className={`flex w-full cursor-pointer items-center gap-2.5 rounded-lg border-0 bg-transparent px-2.5 py-2 text-left motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                  style={{\n                    background:\n                      selected === insight.id ? c.row : \"transparent\",\n                  }}\n                >\n                  <Dot size={8} color={outcome ? c.faint : kind.color} />\n                  <span className=\"min-w-0 flex-1\">\n                    <span\n                      className=\"block truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                      style={{ color: outcome ? c.sub : c.text }}\n                    >\n                      {insight.title}\n                    </span>\n                    <span\n                      className=\"block truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                      style={{ color: c.faint }}\n                    >\n                      {outcome === \"task\"\n                        ? \"Task created\"\n                        : outcome === \"dismissed\"\n                          ? \"Dismissed\"\n                          : kind.label}\n                    </span>\n                  </span>\n                  <span\n                    className=\"shrink-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] tabular-nums\"\n                    style={{ color: outcome ? c.faint : c.soft }}\n                  >\n                    {insight.impact}\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n\n        {/* Every finding shares one cell, so picking one never changes the card's height. */}\n        <div\n          className=\"grid border-t p-5 @2xl:border-t-0 @2xl:border-l\"\n          style={{ borderColor: c.border }}\n        >\n          {insights.map((insight) => {\n            const on = selected === insight.id;\n            const outcome = outcomes[insight.id];\n            const color = KINDS[insight.kind].color;\n            return (\n              <article\n                key={insight.id}\n                aria-hidden={!on}\n                inert={!on}\n                className={`flex min-w-0 flex-col [grid-area:1/1] motion-safe:transition-opacity motion-safe:duration-200 ${on ? \"visible opacity-100\" : \"invisible opacity-0\"}`}\n              >\n                <p\n                  className=\"m-0 min-h-[60px] text-[13.5px] leading-[20px] tracking-[-0.011em]\"\n                  style={{ color: c.soft }}\n                >\n                  {insight.why}\n                </p>\n                <p\n                  className=\"m-0 mt-3 truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                  style={{ color: c.faint }}\n                >\n                  {insight.seriesLabel}\n                </p>\n                <div className=\"mt-1.5\">\n                  <Area series={insight.series} color={color} />\n                </div>\n                <dl className=\"m-0 mt-2\">\n                  {insight.evidence.map((item) => (\n                    <div\n                      key={item.label}\n                      className=\"flex items-center justify-between gap-4 border-t py-1.5 text-[13px] leading-[20px] tracking-[-0.011em]\"\n                      style={{ borderColor: c.border }}\n                    >\n                      <dt className=\"truncate\" style={{ color: c.sub }}>\n                        {item.label}\n                      </dt>\n                      <dd className=\"m-0 shrink-0 font-[510] tabular-nums\">\n                        {item.value}\n                      </dd>\n                    </div>\n                  ))}\n                </dl>\n                <div className=\"mt-auto grid pt-3\">\n                  <div\n                    className={`flex gap-2 [grid-area:1/1] ${outcome ? \"invisible\" : \"\"}`}\n                  >\n                    <button\n                      type=\"button\"\n                      data-dismiss=\"\"\n                      tabIndex={outcome ? -1 : 0}\n                      onClick={() => settle(insight, \"dismissed\")}\n                      className={`h-9 flex-1 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n                      style={{ background: c.chip, color: c.soft }}\n                    >\n                      Dismiss\n                    </button>\n                    <button\n                      type=\"button\"\n                      data-task=\"\"\n                      tabIndex={outcome ? -1 : 0}\n                      onClick={() => settle(insight, \"task\")}\n                      className={`h-9 flex-1 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n                      style={{ background: c.btn, color: c.btnText }}\n                    >\n                      Turn into a task\n                    </button>\n                  </div>\n                  <div\n                    className={`flex items-center justify-between gap-3 [grid-area:1/1] ${outcome ? \"\" : \"invisible\"}`}\n                  >\n                    <p className=\"m-0 flex min-w-0 items-center gap-2 text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                      <Dot\n                        size={8}\n                        color={outcome === \"task\" ? ACCENT : c.faint}\n                      />\n                      <span className=\"truncate\">\n                        {outcome === \"task\" ? \"Task created\" : \"Dismissed\"}\n                      </span>\n                    </p>\n                    <button\n                      type=\"button\"\n                      data-undo=\"\"\n                      tabIndex={outcome ? 0 : -1}\n                      onClick={() => undo(insight.id)}\n                      className={`h-9 shrink-0 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n                      style={{ background: c.chip, color: c.soft }}\n                    >\n                      Undo\n                    </button>\n                  </div>\n                </div>\n              </article>\n            );\n          })}\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}