{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "insights-04",
  "description": "A short weekly summary with a headline, three takeaways and buttons to say whether it helped.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/insights.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/insights/insights-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type InsightKind,\n  InsightLabel,\n  type InsightSegment,\n  InsightText,\n} from '@/registry/components/dashboardblocks/insights'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { useId, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ntype DigestFeedback = 'helpful' | 'not-helpful'\n\ninterface Takeaway {\n  kind: InsightKind\n  segments: InsightSegment[]\n}\n\ninterface Insights4Props extends BlockStateProps {\n  defaultFeedback?: DigestFeedback | null\n  headline: string\n  /** Called with `null` when the reader takes their feedback back. */\n  onFeedback?: (feedback: DigestFeedback | null) => void\n  period: string\n  /** Leave out, or pass none, to show the empty state. */\n  takeaways?: Takeaway[]\n}\n\nconst exampleProps: Insights4Props = {\n  headline: 'A strong week for signups, with a checkout dip to look into',\n  period: 'Weekly digest, Sep 14–20',\n  takeaways: [\n    {\n      kind: 'positive',\n      segments: [\n        'Signups ',\n        { text: 'up 24%', tone: 'positive' },\n        ' to 6,634. Organic search brought in ',\n        { text: '+812', tone: 'positive' },\n        ' after the new pricing page went live.',\n      ],\n    },\n    {\n      kind: 'anomaly',\n      segments: [\n        'Checkout conversions fell to ',\n        { text: '212', tone: 'negative' },\n        ' on Tuesday, ',\n        { text: '42% below', tone: 'negative' },\n        ' expected, while card payment errors spiked.',\n      ],\n    },\n    {\n      kind: 'neutral',\n      segments: [\n        'Mobile passed desktop for the first time, at ',\n        { text: '52%' },\n        ' of sessions.',\n      ],\n    },\n  ],\n}\n\nconst feedbackOptions = [\n  { label: 'Helpful', value: 'helpful' },\n  { label: 'Not helpful', value: 'not-helpful' },\n] as const\n\nconst Insights4 = (props: Insights4Props) => {\n  const {\n    defaultFeedback = null,\n    headline,\n    onFeedback,\n    period,\n    errorMessage,\n    status,\n    takeaways = [],\n  } = props\n  const unavailable = status !== undefined || takeaways.length === 0\n  const [feedback, setFeedback] = useState<DigestFeedback | null>(defaultFeedback)\n  const [announcement, setAnnouncement] = useState('')\n  const promptId = useId()\n\n  const choose = (value: DigestFeedback) => {\n    const next = feedback === value ? null : value\n    setFeedback(next)\n    setAnnouncement(next ? 'Thanks for your feedback' : 'Feedback removed')\n    onFeedback?.(next)\n  }\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider\n          errorMessage={errorMessage}\n          state={getBlockState(status, takeaways)}\n        >\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{headline}</h2>\n              <p className='text-muted-foreground text-sm'>{period}</p>\n            </header>\n            <BlockStateRows className='border-y' rows={3} />\n            {!unavailable && (\n              <ol className='flex flex-col divide-y border-y'>\n                {takeaways.map((takeaway, index) => (\n                  <li key={index} className='flex flex-col gap-1 py-3'>\n                    <InsightLabel className='text-xs' kind={takeaway.kind} />\n                    <InsightText segments={takeaway.segments} />\n                  </li>\n                ))}\n              </ol>\n            )}\n            <div className='flex flex-wrap items-center justify-between gap-x-4 gap-y-2'>\n              <p id={promptId} className='text-muted-foreground text-sm'>\n                Was this digest helpful?\n              </p>\n              <div role='group' aria-labelledby={promptId} className='flex gap-2'>\n                {feedbackOptions.map((option) => {\n                  const pressed = feedback === option.value\n                  return (\n                    <Button\n                      key={option.value}\n                      variant='outline'\n                      size='sm'\n                      aria-pressed={pressed}\n                      disabled={unavailable}\n                      onClick={() => choose(option.value)}\n                      className='aria-pressed:border-foreground/30 aria-pressed:bg-muted'\n                    >\n                      {option.value === 'helpful' ? (\n                        <IconPlaceholder\n                          lucide='ThumbsUpIcon'\n                          tabler='IconThumbUp'\n                          hugeicons='ThumbsUpIcon'\n                          phosphor='ThumbsUpIcon'\n                          remixicon='RiThumbUpLine'\n                          data-icon='inline-start'\n                          className={cn(pressed && 'fill-current')}\n                        />\n                      ) : (\n                        <IconPlaceholder\n                          lucide='ThumbsDownIcon'\n                          tabler='IconThumbDown'\n                          hugeicons='ThumbsDownIcon'\n                          phosphor='ThumbsDownIcon'\n                          remixicon='RiThumbDownLine'\n                          data-icon='inline-start'\n                          className={cn(pressed && 'fill-current')}\n                        />\n                      )}\n                      {option.label}\n                    </Button>\n                  )\n                })}\n              </div>\n              <p role='status' className='sr-only'>\n                {announcement}\n              </p>\n            </div>\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Insights4, exampleProps as insights4ExampleProps, type Insights4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/insights/insights-04.tsx"
    }
  ],
  "meta": {
    "shows": "A short weekly summary with a headline, three takeaways and buttons to say whether it helped.",
    "size": "half",
    "usedWith": [
      "insights-01",
      "activity-feed-04"
    ],
    "component": "Insights4",
    "props": "{ defaultFeedback?: null | \"helpful\" | \"not-helpful\"; headline: string; onFeedback?: (feedback: null | \"helpful\" | \"not-helpful\") => void; period: string; takeaways?: { kind: \"neutral\" | \"positive\" | \"negative\" | \"anomaly\"; segments: (string | { text: string; tone?: \"neutral\" | \"positive\" | \"negative\" })[] }[]; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
