{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "photo-review-gallery",
  "title": "Photo Review Gallery",
  "description": "A customer photo wall for a product: a mosaic with a featured photo and quote, All / 5 stars / Verified filters, a +N tile, a lightbox with the photo, rating, review, verified badge, helpful vote, thumbnails, arrow keys and swipe, plus an Add your photos button that previews picked images.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/photo-review-gallery/photo-review-gallery.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, type PanInfo } 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 PhotoReview {\n  id: string;\n  image: string;\n  /** CSS object-position, to frame the subject. */\n  focus?: string;\n  /** Zoom into the photo (1 = as is). */\n  zoom?: number;\n  /** Optional CSS filter, e.g. a warmer phone camera. */\n  tone?: string;\n  author: string;\n  rating: number;\n  date: string;\n  text: string;\n  verified: boolean;\n  helpful: number;\n}\nexport interface PhotoReviewGalleryProps {\n  product?: string;\n  photos?: PhotoReview[];\n  /** Total customer photos, shown in the heading (defaults to photos.length). */\n  total?: number;\n  onHelpful?: (photo: PhotoReview) => void;\n  onUpload?: (files: File[]) => 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    tile: \"#F1F1F1\",\n    accent: \"#7CDE6A\",\n    accentText: \"#0B1A08\",\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    scrim: \"rgba(0,0,0,0.86)\",\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    tile: \"#F1F1F1\",\n    accent: \"#2F9E44\",\n    accentText: \"#FFFFFF\",\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    scrim: \"rgba(10,10,10,0.88)\",\n  },\n};\n\nconst W = \"/demo/blocks/product-detail\";\nconst PHOTOS: PhotoReview[] = [\n  { id: \"p1\", image: `${W}/watch-2.webp`, author: \"Daniel O.\", rating: 5, date: \"Oct 28\", text: \"Even nicer in person. The matte case doesn’t show fingerprints at all.\", verified: true, helpful: 41 },\n  { id: \"p2\", image: `${W}/watch-3.webp`, focus: \"50% 40%\", zoom: 1.35, tone: \"sepia(0.18) saturate(1.1)\", author: \"Hana M.\", rating: 5, date: \"Oct 21\", text: \"Close-up of the dial. The indices catch the light really nicely.\", verified: true, helpful: 18 },\n  { id: \"p3\", image: `${W}/watch-1.webp`, tone: \"brightness(0.96) contrast(1.05)\", author: \"Chris P.\", rating: 4, date: \"Oct 19\", text: \"Strap is stiff for the first week, then it softens up. Size is perfect on a small wrist.\", verified: true, helpful: 12 },\n  { id: \"p4\", image: `${W}/watch-4.webp`, focus: \"50% 30%\", zoom: 1.2, author: \"Yusuf A.\", rating: 5, date: \"Oct 12\", text: \"Wore it to a wedding and got three compliments. Worth it at the sale price.\", verified: false, helpful: 9 },\n  {\n    id: \"p5\",\n    image: \"/demo/minimal-watch.webp\",\n    focus: \"55% 50%\",\n    zoom: 1.6,\n    tone: \"hue-rotate(-8deg) saturate(1.15)\",\n    author: \"Lena R.\",\n    rating: 4,\n    date: \"Oct 3\",\n    text: \"Crown is small but easy to set. Wish it came with a second strap.\",\n    verified: true,\n    helpful: 7,\n  },\n  { id: \"p6\", image: `${W}/watch-2.webp`, focus: \"50% 70%\", zoom: 1.5, tone: \"grayscale(0.2) contrast(1.08)\", author: \"Tom W.\", rating: 5, date: \"Sep 26\", text: \"Buckle detail. Solid, no rattle, the leather smells great.\", verified: true, helpful: 5 },\n];\n\nfunction Stars({ value, color, empty }: { value: number; color: string; empty: string }) {\n  return (\n    <span className=\"inline-flex gap-0.5\" aria-hidden=\"true\">\n      {[1, 2, 3, 4, 5].map((i) => (\n        <svg key={i} width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill={i <= value ? color : empty}>\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\" />\n        </svg>\n      ))}\n    </span>\n  );\n}\nfunction Photo({ ph, className }: { ph: PhotoReview; className?: string }) {\n  return (\n    // eslint-disable-next-line @next/next/no-img-element -- plain img keeps the block framework-agnostic\n    <img src={ph.image} alt={`Photo by ${ph.author}`} width={900} height={900} className={cn(\"h-full w-full object-cover\", className)} style={{ objectPosition: ph.focus ?? \"50% 50%\", transform: `scale(${ph.zoom ?? 1})`, filter: ph.tone }} />\n  );\n}\n\nexport function PhotoReviewGallery({ product = \"Minimal Watch\", photos = PHOTOS, total, onHelpful, onUpload, theme = \"dark\", className }: PhotoReviewGalleryProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [filter, setFilter] = React.useState<\"all\" | \"five\" | \"verified\">(\"all\");\n  const [open, setOpen] = React.useState<number | null>(null);\n  const [dir, setDir] = React.useState(1);\n  const [voted, setVoted] = React.useState<string[]>([]);\n  const [uploads, setUploads] = React.useState<{ id: string; url: string; name: string }[]>([]);\n  const fileRef = React.useRef<HTMLInputElement>(null);\n  const openerRef = React.useRef<HTMLElement | null>(null);\n  const dialogRef = React.useRef<HTMLDivElement>(null);\n\n  const list = photos.filter((x) => filter === \"all\" || (filter === \"five\" ? x.rating === 5 : x.verified));\n  const cur = open !== null ? list[open] : null;\n  const count = total ?? photos.length;\n\n  const go = React.useCallback(\n    (d: number) => {\n      if (open === null) return;\n      setDir(d);\n      setOpen((open + d + list.length) % list.length);\n    },\n    [open, list.length],\n  );\n  const close = React.useCallback(() => {\n    setOpen(null);\n    setTimeout(() => openerRef.current?.focus(), 0);\n  }, []);\n  React.useEffect(() => {\n    if (open === null) return;\n    const t = setTimeout(() => dialogRef.current?.querySelector<HTMLElement>(\"[data-autofocus]\")?.focus(), 40);\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") close();\n      if (e.key === \"ArrowRight\") go(1);\n      if (e.key === \"ArrowLeft\") go(-1);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => {\n      clearTimeout(t);\n      window.removeEventListener(\"keydown\", onKey);\n    };\n  }, [open, go, close]);\n  // Free the preview URLs when the block unmounts (single removals free their own).\n  const urlsRef = React.useRef<string[]>([]);\n  React.useEffect(() => () => urlsRef.current.forEach((u) => URL.revokeObjectURL(u)), []);\n\n  const show = (i: number, el: HTMLElement) => {\n    openerRef.current = el;\n    setDir(1);\n    setOpen(i);\n  };\n  const onDrag = (_: unknown, info: PanInfo) => {\n    if (info.offset.x < -60) go(1);\n    else if (info.offset.x > 60) go(-1);\n  };\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const shown = list.slice(0, 5);\n  const more = list.length - shown.length;\n\n  return (\n    <section\n      aria-labelledby={`${uid}-h`}\n      className={cn(\"relative min-h-[640px] w-full overflow-hidden px-4 py-12 sm:px-8\", className)}\n      style={{ background: p.bg, color: p.title, \"--tw-ring-color\": p.ring, \"--tw-ring-offset-color\": p.bg } as React.CSSProperties}\n    >\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              Customer photos <span style={{ color: p.muted }}>({count})</span>\n            </h2>\n          </div>\n          <div className=\"flex flex-wrap items-center gap-2\">\n            <div role=\"radiogroup\" aria-label=\"Show\" className=\"flex rounded-full border p-0.5\" style={{ borderColor: p.line }}>\n              {(\n                [\n                  [\"all\", \"All\"],\n                  [\"five\", \"5 stars\"],\n                  [\"verified\", \"Verified\"],\n                ] as const\n              ).map(([k, l]) => (\n                <button\n                  key={k}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={filter === k}\n                  onClick={() => setFilter(k)}\n                  className={cn(\"h-8 cursor-pointer rounded-full border-0 px-3.5 text-[12.5px] font-medium\", focus)}\n                  style={filter === k ? { background: p.buttonBg, color: p.buttonText } : { background: \"transparent\", color: p.body }}\n                >\n                  {l}\n                </button>\n              ))}\n            </div>\n            <button\n              type=\"button\"\n              onClick={() => fileRef.current?.click()}\n              className={cn(\"flex h-9 cursor-pointer items-center gap-1.5 rounded-full border px-4 text-[13px] font-semibold\", focus)}\n              style={{ borderColor: p.line, background: \"transparent\", color: p.title }}\n            >\n              <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M4 8h3l2-3h6l2 3h3v11H4z\" />\n                <circle cx=\"12\" cy=\"13\" r=\"3.5\" />\n              </svg>\n              Add your photos\n            </button>\n            <input\n              ref={fileRef}\n              type=\"file\"\n              accept=\"image/*\"\n              multiple\n              className=\"sr-only\"\n              tabIndex={-1}\n              aria-hidden=\"true\"\n              onChange={(e) => {\n                const files = [...(e.target.files ?? [])].slice(0, 4);\n                if (!files.length) return;\n                onUpload?.(files);\n                const added = files.map((f, i) => ({ id: `${f.name}-${i}-${Date.now()}`, url: URL.createObjectURL(f), name: f.name }));\n                urlsRef.current.push(...added.map((a) => a.url));\n                setUploads((u) => [...u, ...added].slice(-4));\n                e.target.value = \"\";\n              }}\n            />\n          </div>\n        </div>\n\n        {/* Mosaic */}\n        <ul className=\"m-0 mt-6 grid list-none grid-cols-2 gap-2 p-0 sm:grid-cols-4 sm:grid-rows-2\">\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            {shown.map((ph, i) => (\n              <motion.li\n                key={ph.id}\n                layout={!reduce}\n                initial={reduce ? false : { opacity: 0, scale: 0.96 }}\n                animate={{ opacity: 1, scale: 1 }}\n                exit={reduce ? undefined : { opacity: 0, scale: 0.96 }}\n                transition={{ duration: 0.25 }}\n                className={cn(\"relative\", i === 0 && \"col-span-2 row-span-2\")}\n              >\n                <button\n                  type=\"button\"\n                  onClick={(e) => show(i, e.currentTarget)}\n                  aria-label={`Open photo by ${ph.author}, ${ph.rating} stars`}\n                  className={cn(\"group block aspect-square w-full cursor-zoom-in overflow-hidden rounded-2xl border-0 p-0\", focus)}\n                  style={{ background: p.tile }}\n                >\n                  <span className=\"block h-full w-full transition-transform duration-500 group-hover:scale-[1.04]\">\n                    <Photo ph={ph} />\n                  </span>\n                  {i === 0 && (\n                    <span className=\"absolute inset-x-0 bottom-0 flex items-end justify-between gap-3 bg-gradient-to-t from-black/70 to-transparent p-4 pt-10 text-left text-white\">\n                      <span className=\"min-w-0\">\n                        <Stars value={ph.rating} color=\"#F5C451\" empty=\"rgba(255,255,255,0.3)\" />\n                        <span className=\"mt-1 line-clamp-2 block text-[13.5px] leading-[1.4]\">“{ph.text}”</span>\n                      </span>\n                    </span>\n                  )}\n                  {i === shown.length - 1 && more > 0 && <span className=\"absolute inset-0 flex items-center justify-center rounded-2xl bg-black/55 text-[20px] font-semibold text-white\">+{more}</span>}\n                </button>\n              </motion.li>\n            ))}\n          </AnimatePresence>\n        </ul>\n        {!list.length && (\n          <p className=\"m-0 mt-6 rounded-2xl border px-4 py-10 text-center text-[14px]\" style={{ borderColor: p.line, color: p.muted }}>\n            No photos match yet.\n          </p>\n        )}\n\n        <AnimatePresence initial={false}>\n          {uploads.length > 0 && (\n            <motion.div initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden\">\n              <div className=\"mt-5 rounded-2xl border p-4\" style={{ borderColor: p.line, background: p.card }}>\n                <p className=\"m-0 text-[13px] font-medium\">Your photos · ready to post with your review</p>\n                <ul className=\"m-0 mt-3 flex list-none flex-wrap gap-2 p-0\">\n                  {uploads.map((u) => (\n                    <li key={u.id} className=\"relative h-20 w-20 overflow-hidden rounded-xl\" style={{ background: p.tile }}>\n                      {/* eslint-disable-next-line @next/next/no-img-element -- local preview of a picked file */}\n                      <img src={u.url} alt={u.name} className=\"h-full w-full object-cover\" />\n                      <button\n                        type=\"button\"\n                        onClick={() => {\n                          URL.revokeObjectURL(u.url);\n                          setUploads((v) => v.filter((x) => x.id !== u.id));\n                        }}\n                        aria-label={`Remove ${u.name}`}\n                        className={cn(\"absolute top-1 right-1 flex h-6 w-6 cursor-pointer items-center justify-center rounded-full border-0 bg-black/70 text-[13px] text-white\", focus)}\n                      >\n                        ×\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      {/* Lightbox */}\n      <AnimatePresence>\n        {cur && open !== null && (\n          <motion.div\n            className=\"absolute inset-0 z-20 flex items-center justify-center p-3 sm:p-6\"\n            style={{ background: p.scrim }}\n            initial={reduce ? false : { opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={reduce ? undefined : { opacity: 0 }}\n            onMouseDown={(e) => e.target === e.currentTarget && close()}\n          >\n            <motion.div\n              ref={dialogRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-label={`Photo ${open + 1} of ${list.length}`}\n              initial={reduce ? false : { scale: 0.96, opacity: 0 }}\n              animate={{ scale: 1, opacity: 1 }}\n              exit={reduce ? undefined : { scale: 0.96, opacity: 0 }}\n              className=\"grid max-h-full w-full max-w-4xl grid-cols-1 overflow-hidden rounded-3xl md:grid-cols-[minmax(0,1.3fr)_minmax(0,1fr)]\"\n              style={{ background: p.card }}\n            >\n              <div className=\"relative aspect-square overflow-hidden md:aspect-auto md:min-h-[460px]\" style={{ background: p.tile }}>\n                <AnimatePresence initial={false} custom={dir} mode=\"popLayout\">\n                  <motion.div\n                    key={cur.id}\n                    custom={dir}\n                    className=\"absolute inset-0\"\n                    initial={reduce ? false : { x: dir * 60, opacity: 0 }}\n                    animate={{ x: 0, opacity: 1 }}\n                    exit={reduce ? undefined : { x: dir * -60, opacity: 0 }}\n                    transition={{ duration: 0.28, ease: [0.22, 1, 0.36, 1] }}\n                    drag={reduce ? false : \"x\"}\n                    dragConstraints={{ left: 0, right: 0 }}\n                    dragElastic={0.4}\n                    onDragEnd={onDrag}\n                  >\n                    <Photo ph={cur} className=\"pointer-events-none select-none\" />\n                  </motion.div>\n                </AnimatePresence>\n                {list.length > 1 && (\n                  <>\n                    <button\n                      type=\"button\"\n                      onClick={() => go(-1)}\n                      aria-label=\"Previous photo\"\n                      className={cn(\"absolute top-1/2 left-3 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border-0 bg-black/55 text-[18px] text-white\", focus)}\n                    >\n                      ‹\n                    </button>\n                    <button\n                      type=\"button\"\n                      onClick={() => go(1)}\n                      aria-label=\"Next photo\"\n                      className={cn(\"absolute top-1/2 right-3 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full border-0 bg-black/55 text-[18px] text-white\", focus)}\n                    >\n                      ›\n                    </button>\n                  </>\n                )}\n                <span className=\"absolute bottom-3 left-3 rounded-full bg-black/60 px-2.5 py-1 text-[12px] text-white tabular-nums\" aria-live=\"polite\">\n                  {open + 1} / {list.length}\n                </span>\n              </div>\n              <div className=\"flex flex-col p-5 sm:p-6\">\n                <div className=\"flex items-start justify-between gap-3\">\n                  <div>\n                    <p className=\"m-0 text-[15px] font-semibold\">{cur.author}</p>\n                    <p className=\"m-0 mt-0.5 text-[12.5px]\" style={{ color: p.muted }}>\n                      {cur.date}\n                      {cur.verified && <span style={{ color: p.accent }}> · ✓ Verified purchase</span>}\n                    </p>\n                  </div>\n                  <button\n                    type=\"button\"\n                    data-autofocus\n                    onClick={close}\n                    aria-label=\"Close\"\n                    className={cn(\"flex h-9 w-9 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 text-[20px]\", focus)}\n                    style={{ background: p.ghost, color: p.title }}\n                  >\n                    ×\n                  </button>\n                </div>\n                <div className=\"mt-4\">\n                  <Stars value={cur.rating} color={p.star} empty={p.line} />\n                  <p className=\"m-0 mt-2 text-[15px] leading-[1.6]\">{cur.text}</p>\n                </div>\n                <button\n                  type=\"button\"\n                  disabled={voted.includes(cur.id)}\n                  onClick={() => {\n                    setVoted((v) => [...v, cur.id]);\n                    onHelpful?.(cur);\n                  }}\n                  className={cn(\"mt-5 h-9 cursor-pointer self-start rounded-full border px-4 text-[13px] disabled:cursor-default\", focus)}\n                  style={voted.includes(cur.id) ? { borderColor: \"transparent\", background: p.ghost, color: p.accent } : { borderColor: p.line, background: \"transparent\", color: p.title }}\n                >\n                  {voted.includes(cur.id) ? `✓ Helpful (${cur.helpful + 1})` : `Helpful (${cur.helpful})`}\n                </button>\n                <ul className=\"m-0 mt-auto flex list-none gap-1.5 overflow-x-auto p-0 pt-6 [scrollbar-width:none]\" aria-label=\"All photos\">\n                  {list.map((ph, i) => (\n                    <li key={ph.id} className=\"shrink-0\">\n                      <button\n                        type=\"button\"\n                        onClick={() => {\n                          setDir(i > open ? 1 : -1);\n                          setOpen(i);\n                        }}\n                        aria-label={`Photo ${i + 1} by ${ph.author}`}\n                        aria-current={i === open ? \"true\" : undefined}\n                        className={cn(\"block h-14 w-14 cursor-pointer overflow-hidden rounded-lg border-2 p-0\", focus)}\n                        style={{ borderColor: i === open ? p.accent : \"transparent\", background: p.tile, opacity: i === open ? 1 : 0.6 }}\n                      >\n                        <Photo ph={ph} />\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}