{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "something-went-wrong",
  "type": "registry:block",
  "title": "Something Went Wrong",
  "description": "An app error page with a small 1-bit dithered ?! glyph, Try again that fails once with a shake and then recovers into a check, a copyable error details panel and a quiet Report this link.",
  "categories": [
    "block",
    "Empty & Error"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/collapsible.json"
  ],
  "files": [
    {
      "path": "registry/devl/something-went-wrong.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { ChevronDownIcon, CopyIcon, FlagIcon, LayoutDashboardIcon, MountainIcon, RotateCwIcon } from \"lucide-react\";\nimport { AnimatePresence, MotionConfig, motion, useAnimationControls, useReducedMotion } from \"motion/react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Collapsible, CollapsiblePanel, CollapsibleTrigger } from \"@/components/ui/collapsible\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ErrorDetails {\n  id: string;\n  status?: string;\n  request?: string;\n  time?: string;\n  stack?: string[];\n}\n\nexport interface RecoveredCopy {\n  title: string;\n  description: string;\n  actionLabel: string;\n}\n\nexport interface SomethingWentWrongProps {\n  title?: string;\n  description?: string;\n  stillFailingDescription?: string;\n  details?: ErrorDetails;\n  recovered?: RecoveredCopy;\n  breadcrumb?: string[];\n  product?: string;\n  userInitials?: string;\n  onRetry?: () => Promise<void> | void;\n  onGoToDashboard?: () => void;\n  onReport?: (errorId: string) => void;\n  onContinue?: () => void;\n  className?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst W = 34;\nconst H = 17;\nconst CELL = 3;\nconst BAYER = [\n  [0, 8, 2, 10],\n  [12, 4, 14, 6],\n  [3, 11, 1, 9],\n  [15, 7, 13, 5],\n];\nconst QUESTION = [\".###.\", \"#...#\", \"....#\", \"...#.\", \"..#..\", \".....\", \"..#..\"];\nconst BANG = [\"#\", \"#\", \"#\", \"#\", \"#\", \".\", \"#\"];\nconst CHECK = [\"......##\", \".....##.\", \"##..##..\", \".####...\", \"..##....\"];\n\nfunction stamp(cells: Set<number>, rows: string[], ox: number, oy: number, scale = 2) {\n  rows.forEach((row, y) => {\n    [...row].forEach((ch, x) => {\n      if (ch !== \"#\") return;\n      for (let dy = 0; dy < scale; dy++) {\n        for (let dx = 0; dx < scale; dx++) cells.add((oy + y * scale + dy) * W + ox + x * scale + dx);\n      }\n    });\n  });\n  return cells;\n}\n\nconst ERROR_INK = stamp(stamp(new Set(), QUESTION, 10, 1), BANG, 22, 1);\nconst CHECK_INK = stamp(new Set(), CHECK, 9, 3);\n\nfunction hash(x: number, y: number, seed: number) {\n  let h = (Math.imul(x, 374761393) + Math.imul(y, 668265263) + Math.imul(seed, 1442695041)) | 0;\n  h = Math.imul(h ^ (h >>> 13), 1274126177);\n  h ^= h >>> 16;\n  return (h >>> 0) / 4294967296;\n}\n\nfunction nearInk(ink: Set<number>, x: number, y: number) {\n  for (let dy = -1; dy <= 1; dy++) {\n    for (let dx = -1; dx <= 1; dx++) {\n      const nx = x + dx;\n      const ny = y + dy;\n      if (nx >= 0 && nx < W && ny >= 0 && ny < H && ink.has(ny * W + nx)) return true;\n    }\n  }\n  return false;\n}\n\nfunction DitherGlyph({ recovered, busy }: { recovered: boolean; busy: boolean }) {\n  const reduce = useReducedMotion();\n  const [tick, setTick] = useState(0);\n\n  useEffect(() => {\n    if (reduce || recovered) return;\n    const t = setInterval(() => setTick((n) => n + 1), busy ? 180 : 1400);\n    return () => clearInterval(t);\n  }, [busy, recovered, reduce]);\n\n  const cells = useMemo(() => {\n    const ink = recovered ? CHECK_INK : ERROR_INK;\n    const out: { x: number; y: number; kind: \"ink\" | \"dot\" | \"off\"; delay: number }[] = [];\n    for (let y = 0; y < H; y++) {\n      for (let x = 0; x < W; x++) {\n        const dx = (x - (W - 1) / 2) / (W / 2);\n        const dy = (y - (H - 1) / 2) / (H / 2);\n        const glow = Math.max(0, 1 - Math.hypot(dx, dy)) * (recovered ? 0.85 : 1.15);\n        const noise = (hash(x, y, tick) - 0.5) * 0.14;\n        let kind: \"ink\" | \"dot\" | \"off\" = \"off\";\n        if (ink.has(y * W + x)) kind = \"ink\";\n        else if (!nearInk(ink, x, y) && (BAYER[y % 4][x % 4] + 0.5) / 16 < glow + noise) kind = \"dot\";\n        out.push({ x, y, kind, delay: Math.round(hash(x, y, 7) * 260) });\n      }\n    }\n    return out;\n  }, [recovered, tick]);\n\n  return (\n    <svg aria-hidden className=\"h-auto w-36 overflow-visible\" viewBox={`0 0 ${W * CELL} ${H * CELL}`}>\n      {cells.map((c) => (\n        <rect\n          className={cn(\n            \"transition-opacity duration-300 ease-out motion-reduce:transition-none\",\n            c.kind === \"ink\" ? \"fill-foreground\" : \"fill-foreground/35\",\n          )}\n          height={c.kind === \"ink\" ? CELL + 0.02 : CELL - 1}\n          key={`${c.x}-${c.y}`}\n          style={{ opacity: c.kind === \"off\" ? 0 : 1, transitionDelay: `${c.delay}ms` }}\n          shapeRendering=\"crispEdges\"\n          width={c.kind === \"ink\" ? CELL + 0.02 : CELL - 1}\n          x={c.x * CELL + (c.kind === \"ink\" ? 0 : 0.5)}\n          y={c.y * CELL + (c.kind === \"ink\" ? 0 : 0.5)}\n        />\n      ))}\n    </svg>\n  );\n}\n\nfunction DrawnCheck({ className }: { className?: string }) {\n  const reduce = useReducedMotion();\n  return (\n    <svg aria-hidden className={className} fill=\"none\" viewBox=\"0 0 24 24\">\n      <motion.path\n        animate={{ pathLength: 1 }}\n        d=\"M4.5 12.5l5 5L19.5 7\"\n        initial={{ pathLength: reduce ? 1 : 0 }}\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth={2.25}\n        transition={{ duration: 0.32, ease }}\n      />\n    </svg>\n  );\n}\n\nfunction CopyButton({ text }: { text: string }) {\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  useEffect(() => () => clearTimeout(timer.current), []);\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(text);\n    } catch {}\n    setCopied(true);\n    clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(false), 1800);\n  };\n\n  return (\n    <Button\n      aria-label={copied ? \"Copied\" : \"Copy error details\"}\n      className=\"text-muted-foreground\"\n      onClick={copy}\n      size=\"icon-xs\"\n      variant=\"ghost\"\n    >\n      {copied ? <DrawnCheck className=\"size-3.5 text-success-foreground\" /> : <CopyIcon className=\"size-3.5\" />}\n    </Button>\n  );\n}\n\nconst swap = {\n  initial: { opacity: 0, y: 6, filter: \"blur(2px)\" },\n  animate: { opacity: 1, y: 0, filter: \"blur(0px)\" },\n  exit: { opacity: 0, y: -6, filter: \"blur(2px)\" },\n  transition: { duration: 0.22, ease },\n};\n\nexport function SomethingWentWrong({\n  title = \"Something went wrong\",\n  description = \"We couldn’t load this report. Your data is safe, and we’ve logged the error.\",\n  stillFailingDescription = \"Still not loading. This usually clears up in a few minutes.\",\n  details = { id: \"err_7Hq2kV9x\", stack: [] },\n  recovered = { title: \"You’re back\", description: \"The report loaded. Nothing was lost.\", actionLabel: \"Continue\" },\n  breadcrumb = [\"Reports\"],\n  product = \"Ridgeline\",\n  userInitials = \"AL\",\n  onRetry,\n  onGoToDashboard,\n  onReport,\n  onContinue,\n  className,\n}: SomethingWentWrongProps) {\n  const reduce = useReducedMotion();\n  const [phase, setPhase] = useState<\"error\" | \"retrying\" | \"recovered\">(\"error\");\n  const [attempts, setAttempts] = useState(1);\n  const [reported, setReported] = useState(false);\n  const shake = useAnimationControls();\n  const alive = useRef(true);\n\n  useEffect(() => {\n    alive.current = true;\n    return () => {\n      alive.current = false;\n    };\n  }, []);\n\n  const retry = async () => {\n    setPhase(\"retrying\");\n    try {\n      await onRetry?.();\n      if (alive.current) setPhase(\"recovered\");\n    } catch {\n      if (!alive.current) return;\n      setPhase(\"error\");\n      setAttempts((a) => a + 1);\n      if (!reduce) shake.start({ x: [0, -7, 6, -4, 2, 0], transition: { duration: 0.42, ease: \"easeOut\" } });\n    }\n  };\n\n  const isRecovered = phase === \"recovered\";\n  const copyText = [\n    `Error ID: ${details.id}`,\n    details.status && `Status: ${details.status}`,\n    details.request && `Request: ${details.request}`,\n    details.time && `Time: ${details.time}`,\n    `Attempts: ${attempts}`,\n    ...(details.stack ?? []),\n  ]\n    .filter(Boolean)\n    .join(\"\\n\");\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <section\n        className={cn(\n          \"mx-auto w-full max-w-[1040px] overflow-hidden rounded-2xl border bg-card text-card-foreground shadow-xs/5\",\n          className,\n        )}\n      >\n        <header className=\"flex h-12 items-center gap-3 border-b px-4\">\n          <span className=\"flex size-6 shrink-0 items-center justify-center rounded-md bg-primary text-primary-foreground\">\n            <MountainIcon className=\"size-3.5\" />\n          </span>\n          <nav aria-label=\"Breadcrumb\" className=\"flex min-w-0 items-center gap-1.5 text-sm\">\n            <span className=\"font-medium\">{product}</span>\n            {breadcrumb.map((crumb, i) => (\n              <span className=\"flex min-w-0 items-center gap-1.5 text-muted-foreground\" key={crumb}>\n                <span aria-hidden className=\"text-foreground/20\">\n                  /\n                </span>\n                <span className={cn(\"truncate\", i === breadcrumb.length - 1 && \"text-foreground\")}>{crumb}</span>\n              </span>\n            ))}\n          </nav>\n          <span className=\"ms-auto flex size-7 shrink-0 items-center justify-center rounded-full bg-muted font-medium text-muted-foreground text-xs\">\n            {userInitials}\n          </span>\n        </header>\n\n        <div className=\"flex min-h-[500px] flex-col items-center px-5 pt-14 pb-12 text-center sm:min-h-[620px] sm:pt-24 sm:pb-14\">\n          <motion.div animate={shake} className=\"flex w-full flex-col items-center\">\n            <DitherGlyph busy={phase === \"retrying\"} recovered={isRecovered} />\n\n            <div aria-live=\"polite\" className=\"mt-7 grid w-full max-w-md place-items-center\">\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                <motion.div className=\"flex flex-col items-center\" key={isRecovered ? \"ok\" : \"err\"} {...swap}>\n                  <h2 className=\"text-balance font-semibold text-xl tracking-tight\">{isRecovered ? recovered.title : title}</h2>\n                  <p className=\"mt-2 max-w-[26rem] text-pretty text-muted-foreground text-sm\">\n                    {isRecovered ? recovered.description : attempts > 1 ? stillFailingDescription : description}\n                  </p>\n                </motion.div>\n              </AnimatePresence>\n            </div>\n\n            <div className=\"mt-6 flex flex-wrap items-center justify-center gap-2\">\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                {isRecovered ? (\n                  <motion.div key=\"continue\" {...swap}>\n                    <Button className=\"active:scale-[0.97]\" onClick={onContinue}>\n                      {recovered.actionLabel}\n                    </Button>\n                  </motion.div>\n                ) : (\n                  <motion.div className=\"flex flex-wrap items-center justify-center gap-2\" key=\"actions\" {...swap}>\n                    <Button className=\"min-w-28 active:scale-[0.97]\" loading={phase === \"retrying\"} onClick={retry}>\n                      <RotateCwIcon />\n                      Try again\n                    </Button>\n                    <Button className=\"active:scale-[0.97]\" onClick={onGoToDashboard} variant=\"outline\">\n                      <LayoutDashboardIcon />\n                      Go to dashboard\n                    </Button>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </div>\n          </motion.div>\n\n          <AnimatePresence initial={false}>\n            {!isRecovered && (\n              <motion.div\n                animate={{ opacity: 1, height: \"auto\" }}\n                className=\"w-full max-w-md overflow-hidden\"\n                exit={{ opacity: 0, height: 0 }}\n                initial={{ opacity: 0, height: 0 }}\n                transition={{ duration: 0.24, ease }}\n              >\n                <Collapsible className=\"mt-8 rounded-xl border bg-background text-left shadow-xs/5 dark:bg-input/16\">\n                  <div className=\"flex items-center gap-2 pe-2\">\n                    <CollapsibleTrigger className=\"group flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-xl py-2.5 ps-3.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\">\n                      <ChevronDownIcon className=\"size-4 shrink-0 -rotate-90 text-muted-foreground transition-transform duration-200 group-data-panel-open:rotate-0\" />\n                      <span className=\"font-medium\">Error details</span>\n                      <span className=\"ms-auto truncate font-mono text-muted-foreground text-xs\">{details.id}</span>\n                    </CollapsibleTrigger>\n                    <CopyButton text={copyText} />\n                  </div>\n                  <CollapsiblePanel>\n                    <dl className=\"grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 border-t px-3.5 pt-3 font-mono text-xs\">\n                      {details.status && (\n                        <>\n                          <dt className=\"text-muted-foreground\">Status</dt>\n                          <dd className=\"min-w-0 truncate\">{details.status}</dd>\n                        </>\n                      )}\n                      {details.request && (\n                        <>\n                          <dt className=\"text-muted-foreground\">Request</dt>\n                          <dd className=\"min-w-0 truncate\">{details.request}</dd>\n                        </>\n                      )}\n                      {details.time && (\n                        <>\n                          <dt className=\"text-muted-foreground\">Time</dt>\n                          <dd className=\"min-w-0 truncate tabular-nums\">{details.time}</dd>\n                        </>\n                      )}\n                      <dt className=\"text-muted-foreground\">Attempts</dt>\n                      <dd className=\"tabular-nums\">{attempts}</dd>\n                    </dl>\n                    {details.stack && details.stack.length > 0 && (\n                      <pre className=\"mx-3.5 mt-3 mb-3.5 overflow-x-auto rounded-lg bg-muted/60 px-3 py-2.5 font-mono text-[0.6875rem] text-muted-foreground leading-5\">\n                        {details.stack.map((line, i) => (\n                          <span className={cn(\"block\", i === 0 && \"text-foreground\")} key={line}>\n                            {line}\n                          </span>\n                        ))}\n                      </pre>\n                    )}\n                  </CollapsiblePanel>\n                </Collapsible>\n\n                <div className=\"mt-3 flex h-7 justify-center\">\n                  <AnimatePresence initial={false} mode=\"popLayout\">\n                    {reported ? (\n                      <motion.p\n                        className=\"flex items-center gap-1.5 text-muted-foreground text-xs\"\n                        key=\"done\"\n                        role=\"status\"\n                        {...swap}\n                      >\n                        <DrawnCheck className=\"size-3.5 text-success-foreground\" />\n                        Reported. We’ll look into {details.id}.\n                      </motion.p>\n                    ) : (\n                      <motion.div key=\"report\" {...swap}>\n                        <Button\n                          className=\"text-muted-foreground hover:text-foreground\"\n                          onClick={() => {\n                            setReported(true);\n                            onReport?.(details.id);\n                          }}\n                          size=\"xs\"\n                          variant=\"ghost\"\n                        >\n                          <FlagIcon />\n                          Report this\n                        </Button>\n                      </motion.div>\n                    )}\n                  </AnimatePresence>\n                </div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </section>\n    </MotionConfig>\n  );\n}\n"
    }
  ]
}