{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "feedback-01",
  "description": "The average rating as stars, the number of ratings and the share of each star, with the change on the last period and the share rating 4 or 5.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/feedback.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/use-reveal.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/feedback/feedback-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { chartFadedColor } from '@/registry/components/dashboardblocks/chart'\nimport {\n  StarRating,\n  getCsat,\n  getRatingSummary,\n} from '@/registry/components/dashboardblocks/feedback'\nimport { KPIChange, KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport { useReveal } from '@/registry/hooks/use-reveal'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Feedback1Props extends BlockStateProps {\n  /** Follows the previous average in the change sentence, such as `last quarter`. */\n  comparison?: string\n  /** How many 1, 2, 3, 4 and 5-star ratings. Leave out to show the empty state. */\n  counts?: number[]\n  description: string\n  previousAverage?: number\n  title: string\n}\n\nconst exampleProps: Feedback1Props = {\n  comparison: 'last quarter',\n  counts: [86, 64, 171, 612, 1_491],\n  description: 'App Store and Google Play ratings from the last 90 days.',\n  previousAverage: 4.31,\n  title: 'Ratings',\n}\n\nconst SATISFIED_COLOR = 'var(--color-chart-2)'\n\nconst Feedback1 = (props: Feedback1Props) => {\n  const {\n    comparison = 'last period',\n    counts = [],\n    description,\n    previousAverage,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const { average, shares, total } = getRatingSummary(counts)\n  const csat = getCsat(counts)\n  const { ref, revealed } = useReveal<HTMLDivElement>(true)\n  const state = getBlockState(status, counts)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\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'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <div\n              ref={ref}\n              className='flex flex-col gap-6 border-t pt-4 @md:flex-row @md:items-center @md:gap-10'\n            >\n              <div className='flex flex-col gap-1'>\n                {state && <KPIValue />}\n                {!state && (\n                  <>\n                    <p className='flex items-baseline'>\n                      <span className='text-4xl font-light tracking-tight tabular-nums'>\n                        {formatNumber(average, {\n                          maximumFractionDigits: 1,\n                          minimumFractionDigits: 1,\n                        })}\n                      </span>\n                      <span className='text-muted-foreground ml-1 text-base font-normal tracking-normal'>\n                        out of 5\n                      </span>\n                    </p>\n                    <StarRating value={average} />\n                    <p className='text-muted-foreground text-sm tabular-nums'>\n                      From {formatNumber(total)} ratings\n                    </p>\n                  </>\n                )}\n                {state === 'loading' && (\n                  <BlockReady className='text-sm'>{null}</BlockReady>\n                )}\n                {(state === 'loading' || previousAverage !== undefined) && (\n                  <KPIChange\n                    comparison={comparison}\n                    previous={previousAverage}\n                    value={average}\n                  />\n                )}\n              </div>\n              {state === 'loading' && <BlockStateRows className='flex-1' rows={5} />}\n              {!state && (\n                <ol className='flex flex-1 flex-col-reverse gap-2'>\n                  {counts.map((count, index) => (\n                    <li key={index} className='flex items-center gap-3 text-sm'>\n                      <span className='text-muted-foreground w-12 shrink-0 tabular-nums'>\n                        {index + 1} {index === 0 ? 'star' : 'stars'}\n                      </span>\n                      <span\n                        aria-hidden\n                        className='bg-muted h-2 flex-1 overflow-hidden rounded-full'\n                      >\n                        <span\n                          className='block h-full rounded-full transition-[width] duration-700 ease-out motion-reduce:transition-none'\n                          style={{\n                            backgroundColor:\n                              index >= counts.length - 2\n                                ? SATISFIED_COLOR\n                                : chartFadedColor(SATISFIED_COLOR),\n                            width: `${revealed ? shares[index] * 100 : 0}%`,\n                          }}\n                        />\n                      </span>\n                      <span className='w-10 shrink-0 text-right font-medium tabular-nums'>\n                        {formatPercent(shares[index], { maximumFractionDigits: 0 })}\n                      </span>\n                      <span className='text-muted-foreground hidden w-12 shrink-0 text-right tabular-nums @md:inline'>\n                        {formatNumber(count)}\n                      </span>\n                    </li>\n                  ))}\n                </ol>\n              )}\n            </div>\n            {state === 'loading' && (\n              <BlockReady className='border-t pt-3 text-sm'>{null}</BlockReady>\n            )}\n            {!state && (\n              <p className='text-muted-foreground border-t pt-3 text-sm'>\n                <span className='text-foreground font-medium tabular-nums'>\n                  {formatPercent(csat, { maximumFractionDigits: 0 })}\n                </span>{' '}\n                rate it 4 or 5 stars, the share most teams report as CSAT.\n              </p>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Feedback1, exampleProps as feedback1ExampleProps, type Feedback1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/feedback/feedback-01.tsx"
    }
  ],
  "meta": {
    "shows": "The average rating as stars, the number of ratings and the share of each star, with the change on the last period and the share rating 4 or 5.",
    "size": "half",
    "usedWith": [
      "feedback-03",
      "feedback-04"
    ],
    "component": "Feedback1",
    "props": "{ comparison?: string; counts?: number[]; description: string; previousAverage?: number; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
