{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rating-summary-breakdown",
  "title": "Rating Summary Breakdown",
  "description": "A ratings summary that explains the score: big average with stars, an all-time / last 90 days switch, clickable 5-to-1 star bars, a would-recommend ring with verified share, a 12-month trend line, attribute scores, a two-ended scale, topic chips with positive and negative counts and matching review snippets.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/rating-summary-breakdown/rating-summary-breakdown.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype Period = \"all\" | \"recent\";\nexport interface RatingPeriodData {\n  /** Number of ratings for 5, 4, 3, 2 and 1 stars, in that order. */\n  counts: [number, number, number, number, number];\n  recommend: number;\n  verified: number;\n  attributes: { label: string; score: number }[];\n  /** Monthly average rating, oldest first. */\n  trend: number[];\n}\nexport interface RatingSnippet {\n  id: string;\n  rating: number;\n  author: string;\n  text: string;\n  topics: string[];\n  recent: boolean;\n}\nexport interface RatingSummaryBreakdownProps {\n  product?: string;\n  data?: Record<Period, RatingPeriodData>;\n  /** Where the product sits on a two-ended scale, 0 to 1. */\n  scale?: { label: string; low: string; high: string; value: number };\n  topics?: { label: string; positive: number; negative: number }[];\n  snippets?: RatingSnippet[];\n  onFilter?: (filter: { stars: number | null; topic: string | null; period: Period }) => void;\n  onWriteReview?: () => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0A\",\n    card: \"#141414\",\n    title: \"#FFFFFF\",\n    muted: \"rgba(255,255,255,0.45)\",\n    body: \"rgba(255,255,255,0.62)\",\n    line: \"rgba(255,255,255,0.12)\",\n    track: \"rgba(255,255,255,0.08)\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\n    danger: \"#FF8A7A\",\n    star: \"#F5C451\",\n    buttonBg: \"#FFFFFF\",\n    buttonText: \"#111111\",\n    ghost: \"rgba(255,255,255,0.07)\",\n    ring: \"rgba(255,255,255,0.55)\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    card: \"#F7F7F7\",\n    title: \"#111111\",\n    muted: \"rgba(0,0,0,0.45)\",\n    body: \"rgba(0,0,0,0.62)\",\n    line: \"rgba(0,0,0,0.1)\",\n    track: \"rgba(0,0,0,0.07)\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\n    danger: \"#C0392B\",\n    star: \"#E0A100\",\n    buttonBg: \"#111111\",\n    buttonText: \"#FFFFFF\",\n    ghost: \"rgba(0,0,0,0.05)\",\n    ring: \"rgba(0,0,0,0.45)\",\n  },\n};\n\nconst DATA: Record<Period, RatingPeriodData> = {\n  all: {\n    counts: [612, 198, 61, 24, 17],\n    recommend: 92,\n    verified: 87,\n    attributes: [\n      { label: \"Sound\", score: 4.7 },\n      { label: \"Battery\", score: 4.4 },\n      { label: \"Comfort\", score: 4.5 },\n      { label: \"Value\", score: 4.3 },\n    ],\n    trend: [4.3, 4.35, 4.4, 4.38, 4.42, 4.45, 4.5, 4.48, 4.52, 4.55, 4.6, 4.62],\n  },\n  recent: {\n    counts: [140, 31, 9, 3, 2],\n    recommend: 95,\n    verified: 91,\n    attributes: [\n      { label: \"Sound\", score: 4.8 },\n      { label: \"Battery\", score: 4.6 },\n      { label: \"Comfort\", score: 4.5 },\n      { label: \"Value\", score: 4.4 },\n    ],\n    trend: [4.52, 4.55, 4.6, 4.62, 4.6, 4.64, 4.66, 4.63, 4.65, 4.68, 4.66, 4.7],\n  },\n};\nconst TOPICS = [\n  { label: \"Sound quality\", positive: 184, negative: 6 },\n  { label: \"Battery life\", positive: 121, negative: 22 },\n  { label: \"Fit\", positive: 96, negative: 31 },\n  { label: \"Case\", positive: 58, negative: 14 },\n  { label: \"App\", positive: 22, negative: 19 },\n];\nconst SNIPPETS: RatingSnippet[] = [\n  { id: \"s1\", rating: 5, author: \"Priya K.\", text: \"The sound quality is honestly better than my old over-ears. Bass is tight, not boomy.\", topics: [\"Sound quality\"], recent: true },\n  { id: \"s2\", rating: 5, author: \"Marco D.\", text: \"Battery life easily gets me through two days of commuting, and the case tops it up fast.\", topics: [\"Battery life\", \"Case\"], recent: true },\n  { id: \"s3\", rating: 4, author: \"Jenna L.\", text: \"Great sound, but the fit took a while to get right. The smallest tips fixed it.\", topics: [\"Sound quality\", \"Fit\"], recent: false },\n  { id: \"s4\", rating: 3, author: \"Owen T.\", text: \"Fine for the price. The app keeps asking me to update and forgets my EQ settings.\", topics: [\"App\"], recent: true },\n  { id: \"s5\", rating: 2, author: \"Sara M.\", text: \"Left bud falls out when I run. Sound is good when it stays in.\", topics: [\"Fit\", \"Sound quality\"], recent: false },\n  { id: \"s6\", rating: 1, author: \"Ben R.\", text: \"Case hinge broke after a month. Support replaced it, but annoying.\", topics: [\"Case\"], recent: false },\n  { id: \"s7\", rating: 4, author: \"Aiko S.\", text: \"Battery life is good, noise cancelling on the train is the real win.\", topics: [\"Battery life\"], recent: true },\n  { id: \"s8\", rating: 5, author: \"Luis F.\", text: \"Comfortable for hours and the case slips into any pocket.\", topics: [\"Fit\", \"Case\"], recent: true },\n];\n\nfunction Stars({ value, size = 16, color, empty }: { value: number; size?: number; color: string; empty: string }) {\n  const id = React.useId();\n  return (\n    <span className=\"inline-flex gap-0.5\" aria-hidden=\"true\">\n      {[0, 1, 2, 3, 4].map((i) => {\n        const fill = Math.max(0, Math.min(1, value - i));\n        return (\n          <svg key={i} width={size} height={size} viewBox=\"0 0 24 24\">\n            <defs>\n              <linearGradient id={`${id}-${i}`}>\n                <stop offset={`${fill * 100}%`} stopColor={color} />\n                <stop offset={`${fill * 100}%`} stopColor={empty} />\n              </linearGradient>\n            </defs>\n            <path d=\"m12 2.8 2.8 5.8 6.3.9-4.6 4.4 1.1 6.3L12 17.2l-5.6 3 1.1-6.3-4.6-4.4 6.3-.9z\" fill={`url(#${id}-${i})`} />\n          </svg>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function RatingSummaryBreakdown({\n  product = \"Wireless Earbuds\",\n  data = DATA,\n  scale = { label: \"Noise cancelling\", low: \"Light\", high: \"Strong\", value: 0.78 },\n  topics = TOPICS,\n  snippets = SNIPPETS,\n  onFilter,\n  onWriteReview,\n  theme = \"dark\",\n  className,\n}: RatingSummaryBreakdownProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [period, setPeriod] = React.useState<Period>(\"all\");\n  const [stars, setStars] = React.useState<number | null>(null);\n  const [topic, setTopic] = React.useState<string | null>(null);\n  const d = data[period];\n  const total = d.counts.reduce((a, b) => a + b, 0);\n  const avg = d.counts.reduce((a, c, i) => a + c * (5 - i), 0) / total;\n  const maxCount = Math.max(...d.counts);\n\n  React.useEffect(() => {\n    onFilter?.({ stars, topic, period });\n  }, [stars, topic, period, onFilter]);\n\n  const list = snippets.filter((s) => (period === \"all\" || s.recent) && (stars === null || s.rating === stars) && (topic === null || s.topics.includes(topic))).slice(0, 3);\n  // Trend sparkline geometry (pure arithmetic, same on server and client).\n  const W = 220;\n  const H = 56;\n  const lo = Math.min(...d.trend) - 0.05;\n  const hi = Math.max(...d.trend) + 0.05;\n  const pts = d.trend.map((v, i) => [(i / (d.trend.length - 1)) * W, H - ((v - lo) / (hi - lo)) * H] as const);\n  const path = pts.map(([x, y], i) => `${i ? \"L\" : \"M\"}${x.toFixed(1)},${y.toFixed(1)}`).join(\" \");\n  const ringC = 2 * 3.14159265 * 26;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const card = \"rounded-2xl border p-5\";\n\n  return (\n    <section aria-labelledby={`${uid}-h`} className={cn(\"relative w-full px-4 py-12 sm:px-8\", className)} style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.bg } as React.CSSProperties}>\n      <div className=\"mx-auto max-w-5xl\">\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <p className=\"m-0 text-[13px]\" style={{ color: p.muted }}>\n              {product}\n            </p>\n            <h2 id={`${uid}-h`} className=\"m-0 mt-1 text-[26px] font-semibold tracking-[-0.02em]\">\n              Ratings & reviews\n            </h2>\n          </div>\n          <div className=\"flex items-center gap-2\">\n            <div role=\"radiogroup\" aria-label=\"Period\" className=\"flex rounded-full border p-0.5\" style={{ borderColor: p.line }}>\n              {(\n                [\n                  [\"all\", \"All time\"],\n                  [\"recent\", \"Last 90 days\"],\n                ] as const\n              ).map(([k, l]) => (\n                <button\n                  key={k}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={period === k}\n                  onClick={() => setPeriod(k)}\n                  className={cn(\"h-8 cursor-pointer rounded-full border-0 px-3.5 text-[12.5px] font-medium\", focus)}\n                  style={period === k ? { background: p.buttonBg, color: p.buttonText } : { background: \"transparent\", color: p.body }}\n                >\n                  {l}\n                </button>\n              ))}\n            </div>\n            <button type=\"button\" onClick={() => onWriteReview?.()} className={cn(\"hidden h-9 cursor-pointer rounded-full border px-4 text-[13px] font-semibold sm:block\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title }}>\n              Write a review\n            </button>\n          </div>\n        </div>\n\n        <div className=\"mt-6 grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]\">\n          {/* Score + bars */}\n          <div className={card} style={{ background: p.card, borderColor: p.line }}>\n            <div className=\"flex flex-col gap-6 sm:flex-row sm:items-center\">\n              <div className=\"shrink-0 text-center sm:w-[150px]\">\n                <AnimatePresence mode=\"popLayout\" initial={false}>\n                  <motion.p\n                    key={avg.toFixed(1)}\n                    initial={reduce ? false : { y: 12, opacity: 0 }}\n                    animate={{ y: 0, opacity: 1 }}\n                    exit={reduce ? undefined : { y: -12, opacity: 0 }}\n                    className=\"m-0 text-[56px] leading-none font-semibold tracking-[-0.04em] tabular-nums\"\n                  >\n                    {avg.toFixed(1)}\n                  </motion.p>\n                </AnimatePresence>\n                <div className=\"mt-2 flex justify-center\">\n                  <Stars value={avg} color={p.star} empty={p.track} />\n                </div>\n                <p className=\"m-0 mt-1.5 text-[12.5px]\" style={{ color: p.muted }} aria-live=\"polite\">\n                  {String(total).replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")} ratings\n                </p>\n                <span className=\"sr-only\">\n                  {avg.toFixed(1)} out of 5 stars from {total} ratings\n                </span>\n              </div>\n              <ul className=\"m-0 flex flex-1 list-none flex-col gap-1.5 p-0\" aria-label=\"Filter by stars\">\n                {d.counts.map((c, i) => {\n                  const s = 5 - i;\n                  const on = stars === s;\n                  const pct = Math.round((c / total) * 100);\n                  return (\n                    <li key={s}>\n                      <button\n                        type=\"button\"\n                        aria-pressed={on}\n                        onClick={() => setStars(on ? null : s)}\n                        aria-label={`${s} stars, ${c} ratings, ${pct}%`}\n                        className={cn(\"flex w-full cursor-pointer items-center gap-3 rounded-lg border-0 px-2 py-1.5 transition-colors\", focus)}\n                        style={{ background: on ? p.ghost : \"transparent\", color: p.title, opacity: stars === null || on ? 1 : 0.45 }}\n                      >\n                        <span className=\"w-6 text-[12.5px] tabular-nums\" style={{ color: p.body }}>\n                          {s}★\n                        </span>\n                        <span className=\"h-2 flex-1 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                          <motion.span\n                            className=\"block h-full rounded-full\"\n                            style={{ background: s >= 4 ? p.star : s === 3 ? p.body : p.danger }}\n                            initial={reduce ? false : { width: 0 }}\n                            animate={{ width: `${(c / maxCount) * 100}%` }}\n                            transition={{ duration: reduce ? 0 : 0.6, delay: reduce ? 0 : i * 0.05, ease: [0.22, 1, 0.36, 1] }}\n                          />\n                        </span>\n                        <span className=\"w-9 text-right text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                          {pct}%\n                        </span>\n                      </button>\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          </div>\n\n          {/* Recommend + verified + trend */}\n          <div className={cn(card, \"flex flex-col gap-5\")} style={{ background: p.card, borderColor: p.line }}>\n            <div className=\"flex items-center gap-4\">\n              <div className=\"relative h-16 w-16 shrink-0\" role=\"img\" aria-label={`${d.recommend}% would recommend`}>\n                <svg width=\"64\" height=\"64\" viewBox=\"0 0 64 64\" className=\"-rotate-90\" aria-hidden=\"true\">\n                  <circle cx=\"32\" cy=\"32\" r=\"26\" fill=\"none\" stroke={p.track} strokeWidth=\"6\" />\n                  <motion.circle\n                    cx=\"32\"\n                    cy=\"32\"\n                    r=\"26\"\n                    fill=\"none\"\n                    stroke={p.accent}\n                    strokeWidth=\"6\"\n                    strokeLinecap=\"round\"\n                    strokeDasharray={ringC}\n                    initial={reduce ? false : { strokeDashoffset: ringC }}\n                    animate={{ strokeDashoffset: ringC * (1 - d.recommend / 100) }}\n                    transition={{ duration: reduce ? 0 : 0.8, ease: [0.22, 1, 0.36, 1] }}\n                  />\n                </svg>\n                <span className=\"absolute inset-0 flex items-center justify-center text-[14px] font-semibold tabular-nums\">{d.recommend}%</span>\n              </div>\n              <div>\n                <p className=\"m-0 text-[14.5px] font-semibold\">Would recommend</p>\n                <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.muted }}>\n                  {d.verified}% from verified purchases\n                </p>\n              </div>\n            </div>\n            <div>\n              <div className=\"flex items-baseline justify-between\">\n                <p className=\"m-0 text-[13px] font-medium\">Rating over 12 months</p>\n                <p className=\"m-0 text-[12.5px] tabular-nums\" style={{ color: d.trend[d.trend.length - 1] >= d.trend[0] ? p.accent : p.danger }}>\n                  {d.trend[d.trend.length - 1] >= d.trend[0] ? \"▲\" : \"▼\"} {Math.abs(d.trend[d.trend.length - 1] - d.trend[0]).toFixed(2)}\n                </p>\n              </div>\n              <svg viewBox={`0 0 ${W} ${H}`} preserveAspectRatio=\"none\" className=\"mt-2 block h-14 w-full\" role=\"img\" aria-label={`Monthly average went from ${d.trend[0]} to ${d.trend[d.trend.length - 1]}`}>\n                <motion.path key={period} d={`${path} L${W},${H} L0,${H} Z`} fill={p.accent} fillOpacity=\"0.12\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} />\n                <motion.path\n                  key={`${period}-l`}\n                  d={path}\n                  fill=\"none\"\n                  stroke={p.accent}\n                  strokeWidth=\"2\"\n                  vectorEffect=\"non-scaling-stroke\"\n                  initial={reduce ? false : { opacity: 0, y: 6 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  transition={{ duration: 0.9, ease: \"easeOut\" }}\n                />\n              </svg>\n            </div>\n          </div>\n\n          {/* Attributes */}\n          <div className={card} style={{ background: p.card, borderColor: p.line }}>\n            <p className=\"m-0 text-[13px] font-medium\">What owners rate</p>\n            <ul className=\"m-0 mt-4 grid list-none grid-cols-1 gap-3.5 p-0 sm:grid-cols-2\">\n              {d.attributes.map((a) => (\n                <li key={a.label}>\n                  <div className=\"flex justify-between text-[13px]\">\n                    <span style={{ color: p.body }}>{a.label}</span>\n                    <span className=\"font-semibold tabular-nums\">{a.score.toFixed(1)}</span>\n                  </div>\n                  <div className=\"mt-1.5 grid grid-cols-5 gap-1\" aria-hidden=\"true\">\n                    {[0, 1, 2, 3, 4].map((i) => (\n                      <span key={i} className=\"h-1.5 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                        <motion.span\n                          className=\"block h-full rounded-full\"\n                          style={{ background: p.title }}\n                          initial={reduce ? false : { width: 0 }}\n                          animate={{ width: `${Math.max(0, Math.min(1, a.score - i)) * 100}%` }}\n                          transition={{ duration: reduce ? 0 : 0.5, delay: reduce ? 0 : i * 0.05 }}\n                        />\n                      </span>\n                    ))}\n                  </div>\n                </li>\n              ))}\n            </ul>\n            <div className=\"mt-5 border-t pt-4\" style={{ borderColor: p.line }}>\n              <p className=\"m-0 text-[13px]\" style={{ color: p.body }}>\n                {scale.label}\n              </p>\n              <div className=\"relative mt-3 h-1.5 rounded-full\" style={{ background: p.track }} role=\"img\" aria-label={`${scale.label}: ${Math.round(scale.value * 100)}% toward ${scale.high}`}>\n                <motion.span\n                  className=\"absolute top-1/2 h-4 w-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2\"\n                  style={{ background: p.card, borderColor: p.title }}\n                  initial={reduce ? false : { left: \"50%\" }}\n                  animate={{ left: `${scale.value * 100}%` }}\n                  transition={{ type: \"spring\", stiffness: 120, damping: 14 }}\n                />\n              </div>\n              <div className=\"mt-2 flex justify-between text-[11.5px]\" style={{ color: p.muted }}>\n                <span>{scale.low}</span>\n                <span>{scale.high}</span>\n              </div>\n            </div>\n          </div>\n\n          {/* Topics + snippets */}\n          <div className={card} style={{ background: p.card, borderColor: p.line }}>\n            <p className=\"m-0 text-[13px] font-medium\">People mention</p>\n            <div className=\"mt-3 flex flex-wrap gap-1.5\">\n              {topics.map((t) => {\n                const on = topic === t.label;\n                return (\n                  <button\n                    key={t.label}\n                    type=\"button\"\n                    aria-pressed={on}\n                    onClick={() => setTopic(on ? null : t.label)}\n                    className={cn(\"flex h-8 cursor-pointer items-center gap-1.5 rounded-full border px-3 text-[12.5px]\", focus)}\n                    style={on ? { background: p.buttonBg, color: p.buttonText, borderColor: p.buttonBg } : { background: \"transparent\", color: p.title, borderColor: p.line }}\n                  >\n                    {t.label}\n                    <span className=\"text-[11px] tabular-nums\" style={{ color: on ? undefined : p.accent }}>\n                      +{t.positive}\n                    </span>\n                    <span className=\"text-[11px] tabular-nums\" style={{ color: on ? undefined : p.danger }}>\n                      −{t.negative}\n                    </span>\n                  </button>\n                );\n              })}\n            </div>\n            <div className=\"mt-4 flex items-center justify-between\">\n              <p className=\"m-0 text-[12.5px]\" style={{ color: p.muted }} aria-live=\"polite\">\n                {stars || topic ? `Showing ${[stars ? `${stars}★` : \"\", topic ?? \"\"].filter(Boolean).join(\" · \")}` : \"Most helpful\"}\n              </p>\n              {(stars || topic) && (\n                <button\n                  type=\"button\"\n                  onClick={() => {\n                    setStars(null);\n                    setTopic(null);\n                  }}\n                  className={cn(\"cursor-pointer rounded border-0 bg-transparent p-0 text-[12.5px] underline underline-offset-4\", focus)}\n                  style={{ color: p.body }}\n                >\n                  Clear\n                </button>\n              )}\n            </div>\n            <ul className=\"m-0 mt-3 flex list-none flex-col gap-3 p-0\">\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                {list.map((s) => (\n                  <motion.li key={s.id} layout={!reduce} initial={reduce ? false : { opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"rounded-xl p-3\" style={{ background: p.ghost }}>\n                    <div className=\"flex items-center justify-between gap-2\">\n                      <Stars value={s.rating} size={12} color={p.star} empty={p.track} />\n                      <span className=\"text-[11.5px]\" style={{ color: p.muted }}>\n                        {s.author}\n                      </span>\n                    </div>\n                    <p className=\"m-0 mt-1.5 text-[13px] leading-[1.5]\" style={{ color: p.body }}>\n                      {s.text}\n                    </p>\n                  </motion.li>\n                ))}\n              </AnimatePresence>\n              {!list.length && (\n                <li className=\"py-4 text-center text-[13px]\" style={{ color: p.muted }}>\n                  No reviews match that yet.\n                </li>\n              )}\n            </ul>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}