{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "product-reviews-block",
  "title": "Product Reviews Block",
  "description": "A product review list: average rating, sorting, filter chips for photos, star level and the topics people mention most, review cards with verified badges, purchased variant, read more, photos, store replies and a helpful vote, plus 'show more' paging.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/product-reviews-block/product-reviews-block.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\nexport interface Review {\n  id: string;\n  author: string;\n  location: string;\n  date: string;\n  /** Sort key, newest has the highest number. */\n  order: number;\n  rating: number;\n  title: string;\n  body: string;\n  variant: string;\n  verified: boolean;\n  topics: string[];\n  helpful: number;\n  photo?: string;\n  reply?: string;\n}\n\nexport interface ProductReviewsBlockProps {\n  product?: string;\n  reviews?: Review[];\n  pageSize?: number;\n  onHelpful?: (id: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.68)\", line: \"rgba(255,255,255,0.12)\", card: \"#141414\", well: \"rgba(255,255,255,0.04)\", photo: \"#F1F1F1\", chip: \"rgba(255,255,255,0.06)\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", star: \"#F5B544\", accent: \"#7CDE6A\", ring: \"rgba(255,255,255,0.5)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.68)\", line: \"rgba(0,0,0,0.1)\", card: \"#F7F7F6\", well: \"rgba(0,0,0,0.03)\", photo: \"#F1F1F1\", chip: \"rgba(0,0,0,0.05)\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", star: \"#C9850B\", accent: \"#2F9E44\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst AVATAR = [\"#F472B6\", \"#60A5FA\", \"#A78BFA\", \"#34D399\", \"#FB923C\", \"#FBBF24\", \"#22D3EE\"];\nconst R = (id: string, author: string, location: string, date: string, order: number, rating: number, title: string, body: string, variant: string, topics: string[], helpful: number, extra: Partial<Review> = {}): Review => ({ id, author, location, date, order, rating, title, body, variant, verified: true, topics, helpful, ...extra });\nconst REVIEWS: Review[] = [\n  R(\"r1\", \"Maya P.\", \"London\", \"Oct 28, 2026\", 10, 5, \"Forget they're in\", \"I wear these for six hours on long-haul flights and forget they're in. Noise cancelling knocks out the engine drone completely, and the case still had two charges left when I landed. The fit took a day to get right with the medium tips.\", \"Black\", [\"Noise cancelling\", \"Comfort\", \"Battery\"], 48, { photo: \"/demo/wireless-earbuds.webp\", reply: \"Thanks Maya! Glad they made the flight easier. Safe travels.\" }),\n  R(\"r2\", \"Jonas B.\", \"Oslo\", \"Oct 22, 2026\", 9, 4, \"Great sound, case is a bit slippery\", \"Sound is warm without being boomy and calls are clear even outside. My only gripe is the matte case slips out of pockets easily. A silicone cover fixed it.\", \"Black\", [\"Sound\", \"Case\"], 31),\n  R(\"r3\", \"Elif D.\", \"Istanbul\", \"Oct 15, 2026\", 8, 5, \"Battery lasts all week\", \"I charge the case once a week with daily commutes and a few gym sessions. Switching between laptop and phone is instant.\", \"Stone\", [\"Battery\", \"Connectivity\"], 22),\n  R(\"r4\", \"Sam K.\", \"Portland\", \"Oct 9, 2026\", 7, 3, \"Good, not for big ears\", \"They sound good but the largest tips still feel loose during runs. Fine for desk work. Customer support sent me a free set of foam tips which helped.\", \"Black\", [\"Comfort\", \"Fit\"], 17, { reply: \"Hi Sam, thanks for the honest feedback. The foam tips are now included with every pair.\" }),\n  R(\"r5\", \"Grace L.\", \"Singapore\", \"Sep 30, 2026\", 6, 5, \"Best purchase this year\", \"Replaced my old over-ears for the office. Noise cancelling is genuinely good and they're light enough to wear all day.\", \"Stone\", [\"Noise cancelling\", \"Comfort\"], 12, { photo: \"/demo/wireless-earbuds.webp\" }),\n  R(\"r6\", \"Hugo B.\", \"Lyon\", \"Sep 24, 2026\", 5, 4, \"Solid all-rounder\", \"Clear calls, decent battery, the app is simple. Touch controls take some getting used to.\", \"Black\", [\"Sound\", \"Controls\"], 8),\n  R(\"r7\", \"Priya N.\", \"Bangalore\", \"Sep 18, 2026\", 4, 5, \"Comfortable for hours\", \"I have small ears and the small tips are perfect. No discomfort after a full workday of calls.\", \"Stone\", [\"Comfort\", \"Fit\"], 6),\n  R(\"r8\", \"Tom B.\", \"Berlin\", \"Sep 3, 2026\", 3, 2, \"Left bud disconnects\", \"The left bud dropped out a few times a day. Support replaced the pair quickly and the new ones have been fine so far.\", \"Black\", [\"Connectivity\"], 5),\n];\nconst SORTS = { helpful: \"Most helpful\", newest: \"Newest\", high: \"Highest rated\", low: \"Lowest rated\" } as const;\n\nfunction Stars({ value, color, size = 13 }: { value: number; color: string; size?: number }) {\n  return (\n    <span className=\"flex gap-0.5\" role=\"img\" aria-label={`${value} out of 5 stars`}>\n      {[1, 2, 3, 4, 5].map((i) => (\n        <svg key={i} width={size} height={size} viewBox=\"0 0 24 24\" fill={i <= value ? color : \"none\"} stroke={color} strokeWidth=\"1.6\" aria-hidden=\"true\">\n          <path d=\"m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.5 2.9 1-6.1L3.2 9.5l6.1-.9z\" />\n        </svg>\n      ))}\n    </span>\n  );\n}\n\nexport function ProductReviewsBlock({ product = \"Wireless Earbuds\", reviews = REVIEWS, pageSize = 4, onHelpful, theme = \"dark\", className }: ProductReviewsBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [topic, setTopic] = React.useState<string | null>(null);\n  const [stars, setStars] = React.useState<number | null>(null);\n  const [withPhotos, setWithPhotos] = React.useState(false);\n  const [sort, setSort] = React.useState<keyof typeof SORTS>(\"helpful\");\n  const [shown, setShown] = React.useState(pageSize);\n  const [expanded, setExpanded] = React.useState<Record<string, boolean>>({});\n  const [voted, setVoted] = React.useState<Record<string, boolean>>({});\n\n  const avg = reviews.reduce((a, r) => a + r.rating, 0) / reviews.length;\n  const topics = Array.from(new Set(reviews.flatMap((r) => r.topics)))\n    .map((t) => ({ t, n: reviews.filter((r) => r.topics.includes(t)).length }))\n    .sort((a, b) => b.n - a.n)\n    .slice(0, 6);\n  const list = reviews\n    .filter((r) => (!topic || r.topics.includes(topic)) && (!stars || r.rating === stars) && (!withPhotos || r.photo))\n    .sort((a, b) => (sort === \"newest\" ? b.order - a.order : sort === \"high\" ? b.rating - a.rating || b.order - a.order : sort === \"low\" ? a.rating - b.rating || b.order - a.order : b.helpful + (voted[b.id] ? 1 : 0) - (a.helpful + (voted[a.id] ? 1 : 0))));\n  const visible = list.slice(0, shown);\n  const reset = () => setShown(pageSize);\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const chip = (on: boolean) => ({ background: on ? p.buttonBg : p.chip, color: on ? p.buttonText : p.title, ...ring });\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }} aria-labelledby={`${uid}-t`}>\n      <div className=\"mx-auto max-w-4xl px-4 py-12 @[640px]:px-8\">\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <h2 id={`${uid}-t`} className=\"m-0 text-[28px] font-semibold tracking-[-0.03em] @[640px]:text-[34px]\">\n              Reviews\n            </h2>\n            <div className=\"mt-2 flex items-center gap-2.5 text-[13.5px]\" style={{ color: p.muted }}>\n              <span className=\"text-[22px] font-semibold tabular-nums\" style={{ color: p.title }}>\n                {avg.toFixed(1)}\n              </span>\n              <Stars value={Math.round(avg)} color={p.star} size={15} />\n              <span>\n                {reviews.length} reviews of {product}\n              </span>\n            </div>\n          </div>\n          <label className=\"sr-only\" htmlFor={`${uid}-sort`}>\n            Sort reviews\n          </label>\n          <select\n            id={`${uid}-sort`}\n            value={sort}\n            onChange={(e) => {\n              setSort(e.target.value as keyof typeof SORTS);\n              reset();\n            }}\n            className={cn(\"h-10 cursor-pointer rounded-full border px-4 text-[13px]\", focus)}\n            style={{ borderColor: p.line, background: p.bg, color: p.title, ...ring }}\n          >\n            {Object.entries(SORTS).map(([k, v]) => (\n              <option key={k} value={k}>\n                {v}\n              </option>\n            ))}\n          </select>\n        </div>\n\n        <div className=\"mt-5 flex flex-wrap gap-2\" role=\"group\" aria-label=\"Filter reviews\">\n          <button type=\"button\" aria-pressed={withPhotos} onClick={() => {\n              setWithPhotos((w) => !w);\n              reset();\n            }} className={cn(\"flex h-8 cursor-pointer items-center gap-1.5 rounded-full border-0 px-3 text-[12.5px] font-medium\", focus)} style={chip(withPhotos)}>\n            <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M4 6h16v13H4zM8 13l3 3 5-6 4 5\" />\n            </svg>\n            With photos\n          </button>\n          {[5, 4, 3].map((s) => (\n            <button key={s} type=\"button\" aria-pressed={stars === s} onClick={() => {\n                setStars((x) => (x === s ? null : s));\n                reset();\n              }} className={cn(\"h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px] font-medium tabular-nums\", focus)} style={chip(stars === s)}>\n              {s} ★\n            </button>\n          ))}\n          <span className=\"mx-1 hidden w-px self-stretch @[640px]:block\" style={{ background: p.line }} aria-hidden=\"true\" />\n          {topics.map(({ t, n }) => (\n            <button key={t} type=\"button\" aria-pressed={topic === t} onClick={() => {\n                setTopic((x) => (x === t ? null : t));\n                reset();\n              }} className={cn(\"h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px]\", focus)} style={chip(topic === t)}>\n              {t} <span className=\"tabular-nums opacity-60\">{n}</span>\n            </button>\n          ))}\n        </div>\n        <p className=\"m-0 mt-3 text-[12.5px]\" style={{ color: p.muted }} aria-live=\"polite\">\n          {list.length === reviews.length ? `Showing ${Math.min(shown, list.length)} of ${list.length}` : `${list.length} ${list.length === 1 ? \"review matches\" : \"reviews match\"}`}\n        </p>\n\n        <ul className=\"m-0 mt-4 list-none p-0\">\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            {visible.map((r, i) => {\n              const long = r.body.length > 170;\n              const open = !!expanded[r.id];\n              const isVoted = !!voted[r.id];\n              return (\n                <motion.li key={r.id} initial={reduce ? false : { opacity: 0, y: 12 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} transition={{ duration: 0.3, delay: reduce ? 0 : Math.min(i, 4) * 0.04 }} className=\"border-t py-6\" style={{ borderColor: p.line }}>\n                  <div className=\"grid grid-cols-1 gap-4 @[640px]:grid-cols-[180px_minmax(0,1fr)]\">\n                    <div className=\"flex items-center gap-3 @[640px]:flex-col @[640px]:items-start\">\n                      <span className=\"grid h-10 w-10 shrink-0 place-items-center rounded-full text-[13px] font-semibold text-[#0A0A0A]\" style={{ background: AVATAR[Number(r.id.replace(/\\D/g, \"\")) % AVATAR.length] }} aria-hidden=\"true\">\n                        {r.author[0]}\n                      </span>\n                      <span>\n                        <span className=\"block text-[14px] font-medium\">{r.author}</span>\n                        <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n                          {r.location}\n                        </span>\n                        {r.verified && (\n                          <span className=\"mt-1 flex items-center gap-1 text-[11.5px]\" style={{ color: p.accent }}>\n                            <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                              <path d=\"M12 3 5 6v6c0 4.4 3 7.6 7 9 4-1.4 7-4.6 7-9V6zM9 12l2 2 4-4\" />\n                            </svg>\n                            Verified buyer\n                          </span>\n                        )}\n                      </span>\n                    </div>\n                    <div className=\"min-w-0\">\n                      <div className=\"flex flex-wrap items-center gap-x-3 gap-y-1\">\n                        <Stars value={r.rating} color={p.star} />\n                        <span className=\"text-[12px]\" style={{ color: p.muted }}>\n                          {r.date} · {r.variant}\n                        </span>\n                      </div>\n                      <h3 className=\"m-0 mt-2 text-[15.5px] font-semibold\">{r.title}</h3>\n                      <p className=\"m-0 mt-1.5 text-[14px] leading-relaxed\" style={{ color: p.body }}>\n                        {long && !open ? `${r.body.slice(0, 170).trimEnd()}…` : r.body}\n                        {long && (\n                          <button type=\"button\" onClick={() => setExpanded((e) => ({ ...e, [r.id]: !open }))} aria-expanded={open} className={cn(\"ml-1.5 cursor-pointer border-0 bg-transparent p-0 text-[13px] font-medium underline-offset-2 hover:underline\", focus)} style={{ color: p.title, ...ring }}>\n                            {open ? \"Show less\" : \"Read more\"}\n                          </button>\n                        )}\n                      </p>\n                      {r.photo && (\n                        <span className=\"mt-3 block h-20 w-20 overflow-hidden rounded-xl\" style={{ background: p.photo }}>\n                          {/* eslint-disable-next-line @next/next/no-img-element */}\n                          <img src={r.photo} alt={`Photo from ${r.author}`} className=\"h-full w-full object-cover\" />\n                        </span>\n                      )}\n                      <div className=\"mt-3 flex flex-wrap gap-1.5\">\n                        {r.topics.map((t) => (\n                          <span key={t} className=\"rounded-md px-2 py-0.5 text-[11.5px]\" style={{ background: p.chip, color: p.muted }}>\n                            {t}\n                          </span>\n                        ))}\n                      </div>\n                      {r.reply && (\n                        <div className=\"mt-4 rounded-xl border-l-2 px-4 py-3 text-[13px]\" style={{ borderColor: p.accent, background: p.well }}>\n                          <p className=\"m-0 text-[12px] font-semibold\">Reply from Northline</p>\n                          <p className=\"m-0 mt-1 leading-relaxed\" style={{ color: p.body }}>\n                            {r.reply}\n                          </p>\n                        </div>\n                      )}\n                      <div className=\"mt-4 flex items-center gap-3 text-[12.5px]\" style={{ color: p.muted }}>\n                        <span>Helpful?</span>\n                        <button\n                          type=\"button\"\n                          aria-pressed={isVoted}\n                          onClick={() => {\n                            setVoted((v) => ({ ...v, [r.id]: !isVoted }));\n                            if (!isVoted) onHelpful?.(r.id);\n                          }}\n                          className={cn(\"flex h-8 cursor-pointer items-center gap-1.5 rounded-full border px-3 text-[12.5px]\", focus)}\n                          style={{ borderColor: isVoted ? p.accent : p.line, background: isVoted ? `${p.accent}1A` : \"transparent\", color: isVoted ? p.accent : p.title, ...ring }}\n                          aria-label={`Mark review by ${r.author} as helpful, ${r.helpful + (isVoted ? 1 : 0)} people found it helpful`}\n                        >\n                          <motion.svg key={String(isVoted)} width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill={isVoted ? \"currentColor\" : \"none\"} stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={reduce || !isVoted ? false : { scale: 0.4, rotate: -20 }} animate={{ scale: 1, rotate: 0 }} transition={{ type: \"spring\", stiffness: 500, damping: 14 }} aria-hidden=\"true\">\n                            <path d=\"M7 10v11H3V10zM7 10l4-7a2 2 0 0 1 3 2l-1 5h6a2 2 0 0 1 2 2.3l-1.3 7A2 2 0 0 1 17.7 21H7\" />\n                          </motion.svg>\n                          <span className=\"tabular-nums\">{r.helpful + (isVoted ? 1 : 0)}</span>\n                        </button>\n                      </div>\n                    </div>\n                  </div>\n                </motion.li>\n              );\n            })}\n          </AnimatePresence>\n        </ul>\n        {list.length === 0 && (\n          <div className=\"border-t py-12 text-center\" style={{ borderColor: p.line }}>\n            <p className=\"m-0 text-[14px]\">No reviews match these filters.</p>\n            <button\n              type=\"button\"\n              onClick={() => {\n                setTopic(null);\n                setStars(null);\n                setWithPhotos(false);\n              }}\n              className={cn(\"mt-3 cursor-pointer border-0 bg-transparent text-[13px] underline\", focus)}\n              style={{ color: p.body, ...ring }}\n            >\n              Clear filters\n            </button>\n          </div>\n        )}\n        {shown < list.length && (\n          <div className=\"border-t pt-6 text-center\" style={{ borderColor: p.line }}>\n            <button type=\"button\" onClick={() => setShown((s) => s + pageSize)} className={cn(\"h-11 cursor-pointer rounded-full border px-6 text-[13.5px] font-medium\", focus)} style={{ borderColor: p.line, background: \"transparent\", color: p.title, ...ring }}>\n              Show {Math.min(pageSize, list.length - shown)} more reviews\n            </button>\n          </div>\n        )}\n      </div>\n    </section>\n  );\n}\n\nexport default ProductReviewsBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}