{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rating-summary",
  "type": "registry:component",
  "title": "Rating Summary",
  "description": "The average rating as a big number with stars and review total, beside five bars that fill in on mount.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "rating",
    "reviews",
    "summary",
    "bars",
    "stars",
    "distribution"
  ],
  "docs": "https://hyperblur.dev/effects/rating-summary",
  "files": [
    {
      "path": "registry/hyperblur/rating-summary.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/rating-summary.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface RatingCounts {\n  5: number;\n  4: number;\n  3: number;\n  2: number;\n  1: number;\n}\n\nexport interface RatingSummaryProps extends React.HTMLAttributes<HTMLDivElement> {\n  counts?: RatingCounts | number[];\n  color?: string;\n  showPercent?: boolean;\n}\n\nconst css = `\n.hb-rs {\n  box-sizing: border-box;\n  display: flex;\n  align-items: center;\n  gap: 20px;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 12px;\n  line-height: 1.4;\n}\n.hb-rs *, .hb-rs *::before, .hb-rs *::after { box-sizing: border-box; }\n.hb-rs-sum {\n  display: flex;\n  flex: none;\n  flex-direction: column;\n  align-items: flex-start;\n  gap: 6px;\n}\n.hb-rs-avg {\n  font-size: 44px;\n  font-weight: 600;\n  letter-spacing: -0.03em;\n  line-height: 1;\n  font-variant-numeric: tabular-nums;\n}\n.hb-rs-stars { display: inline-flex; }\n.hb-rs-star {\n  position: relative;\n  flex: none;\n  width: 14px;\n  height: 14px;\n}\n.hb-rs-star svg {\n  position: absolute;\n  inset: 0;\n  width: 14px;\n  height: 14px;\n  display: block;\n}\n.hb-rs-star-b { fill: rgba(255, 255, 255, 0.14); }\n.hb-rs-star-f {\n  position: absolute;\n  top: 0;\n  left: 0;\n  height: 100%;\n  overflow: hidden;\n}\n.hb-rs-star-f svg { fill: var(--hb-c); }\n.hb-rs-total { color: #8f8f8f; white-space: nowrap; }\n.hb-rs-bars {\n  display: grid;\n  flex: 1;\n  gap: 6px;\n  min-width: 0;\n  margin: 0;\n  padding: 0;\n  list-style: none;\n}\n.hb-rs-row {\n  position: relative;\n  display: grid;\n  grid-template-columns: 22px minmax(0, 1fr) 36px;\n  align-items: center;\n  gap: 8px;\n}\n.hb-rs-lab {\n  display: inline-flex;\n  align-items: center;\n  gap: 3px;\n  color: #bdbdbd;\n  font-variant-numeric: tabular-nums;\n}\n.hb-rs-lab svg { width: 10px; height: 10px; fill: #8f8f8f; }\n.hb-rs-track {\n  height: 6px;\n  overflow: hidden;\n  border-radius: 999px;\n  background: #262626;\n}\n.hb-rs-fill {\n  display: block;\n  height: 100%;\n  border-radius: 999px;\n  background: var(--hb-c);\n  transform-origin: left center;\n  animation: hb-rs-grow 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) both;\n  animation-delay: calc(var(--hb-i) * 70ms);\n}\n.hb-rs-val {\n  color: #8f8f8f;\n  text-align: right;\n  font-variant-numeric: tabular-nums;\n}\n.hb-rs-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@keyframes hb-rs-grow {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(1); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-rs-fill { animation: none; }\n}\n`;\n\nconst starPath =\n  \"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z\";\n\nconst sample: RatingCounts = { 5: 1700, 4: 420, 3: 100, 2: 50, 1: 40 };\n\nconst levels = [5, 4, 3, 2, 1] as const;\n\nfunction normalize(counts: RatingCounts | number[]): RatingCounts {\n  const pick = (n: 1 | 2 | 3 | 4 | 5, i: number) => {\n    const v = Array.isArray(counts) ? counts[i] : counts[n];\n    return typeof v === \"number\" && Number.isFinite(v) && v > 0 ? v : 0;\n  };\n  return { 5: pick(5, 0), 4: pick(4, 1), 3: pick(3, 2), 2: pick(2, 3), 1: pick(1, 4) };\n}\n\nexport function RatingSummary({\n  counts = sample,\n  color = \"#f5b301\",\n  showPercent = true,\n  className = \"\",\n  style,\n  ...rest\n}: RatingSummaryProps) {\n  const c = normalize(counts);\n  const total = levels.reduce((sum, n) => sum + c[n], 0);\n  const weighted = levels.reduce((sum, n) => sum + c[n] * n, 0);\n  const average = total > 0 ? weighted / total : 0;\n  const shown = average.toFixed(1);\n\n  const vars = {\n    \"--hb-c\": color,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div className={`hb-rs ${className}`} style={vars} {...rest}>\n      <style href=\"hb-rating-summary\" precedence=\"default\">{css}</style>\n      <div className=\"hb-rs-sum\">\n        <span className=\"hb-rs-avg\">{shown}</span>\n        <span className=\"hb-rs-stars\" role=\"img\" aria-label={`Average rating ${shown} out of 5`}>\n          {Array.from({ length: 5 }, (_, i) => {\n            const fill = Math.min(1, Math.max(0, average - i));\n            return (\n              <span key={i} className=\"hb-rs-star\" aria-hidden=\"true\">\n                <svg viewBox=\"0 0 24 24\" className=\"hb-rs-star-b\">\n                  <path d={starPath} />\n                </svg>\n                <span className=\"hb-rs-star-f\" style={{ width: `${fill * 100}%` }}>\n                  <svg viewBox=\"0 0 24 24\">\n                    <path d={starPath} />\n                  </svg>\n                </span>\n              </span>\n            );\n          })}\n        </span>\n        <span className=\"hb-rs-total\">{`${total.toLocaleString(\"en-US\")} ${total === 1 ? \"review\" : \"reviews\"}`}</span>\n      </div>\n      <ul className=\"hb-rs-bars\" role=\"list\">\n        {levels.map((n, i) => {\n          const pct = total > 0 ? (c[n] / total) * 100 : 0;\n          const rounded = Math.round(pct);\n          return (\n            <li key={n} className=\"hb-rs-row\">\n              <span className=\"hb-rs-sr\">{`${n} stars: ${rounded}%, ${c[n].toLocaleString(\"en-US\")} reviews`}</span>\n              <span className=\"hb-rs-lab\" aria-hidden=\"true\">\n                {n}\n                <svg viewBox=\"0 0 24 24\">\n                  <path d={starPath} />\n                </svg>\n              </span>\n              <span className=\"hb-rs-track\" aria-hidden=\"true\">\n                <span\n                  className=\"hb-rs-fill\"\n                  style={{ width: `${pct.toFixed(2)}%`, \"--hb-i\": i } as React.CSSProperties}\n                />\n              </span>\n              <span className=\"hb-rs-val\" aria-hidden=\"true\">\n                {showPercent ? `${rounded}%` : c[n].toLocaleString(\"en-US\")}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n    </div>\n  );\n}\n"
    }
  ]
}