{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "status-page",
  "type": "registry:block",
  "title": "Status Page",
  "description": "A public status page: a banner that names what's wrong, 90 days of uptime bars you can scrub with mouse or arrow keys, an incident timeline, and an inline subscribe form.",
  "categories": [
    "block",
    "Apps"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/input.json"
  ],
  "files": [
    {
      "path": "registry/devl/status-page.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { BellIcon, CheckIcon, CircleCheckIcon, OctagonAlertIcon, TriangleAlertIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type FormEvent, type KeyboardEvent, useId, useMemo, useRef, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ServiceStatus = \"operational\" | \"degraded\" | \"outage\" | \"maintenance\";\nexport type DayStatus = \"operational\" | \"degraded\" | \"outage\" | \"none\";\n\nexport interface StatusComponent {\n  id: string;\n  name: string;\n  description?: string;\n  status: ServiceStatus;\n  history: DayStatus[];\n  notes?: Record<number, string>;\n}\n\nexport type IncidentStage = \"investigating\" | \"identified\" | \"monitoring\" | \"resolved\";\n\nexport interface StatusIncident {\n  id: string;\n  title: string;\n  impact: \"minor\" | \"major\";\n  date: string;\n  updates: { stage: IncidentStage; time: string; body: string }[];\n}\n\nexport interface StatusPageProps {\n  company?: string;\n  today?: string;\n  updatedAgo?: string;\n  components: StatusComponent[];\n  incidents?: StatusIncident[];\n  onSubscribe?: (email: string) => Promise<void>;\n  className?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[box-shadow,scale,background-color] duration-150 active:scale-[0.97]\";\n\nconst SERVICE: Record<ServiceStatus, { label: string; text: string; dot: string }> = {\n  operational: { label: \"Operational\", text: \"text-success-foreground\", dot: \"bg-success\" },\n  degraded: { label: \"Degraded\", text: \"text-warning-foreground\", dot: \"bg-warning\" },\n  outage: { label: \"Outage\", text: \"text-destructive-foreground\", dot: \"bg-destructive\" },\n  maintenance: { label: \"Maintenance\", text: \"text-info-foreground\", dot: \"bg-info\" },\n};\n\nconst DAY: Record<DayStatus, { bar: string; label: string }> = {\n  operational: { bar: \"bg-success/75\", label: \"No incidents\" },\n  degraded: { bar: \"bg-warning\", label: \"Degraded performance\" },\n  outage: { bar: \"bg-destructive\", label: \"Outage\" },\n  none: { bar: \"bg-muted\", label: \"No data\" },\n};\n\nconst STAGE: Record<IncidentStage, { label: string; dot: string }> = {\n  investigating: { label: \"Investigating\", dot: \"bg-destructive\" },\n  identified: { label: \"Identified\", dot: \"bg-warning\" },\n  monitoring: { label: \"Monitoring\", dot: \"bg-info\" },\n  resolved: { label: \"Resolved\", dot: \"bg-success\" },\n};\n\nfunction dayLabel(today: string, offset: number) {\n  const d = new Date(`${today}T12:00:00Z`);\n  d.setUTCDate(d.getUTCDate() - offset);\n  return d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\", year: \"numeric\", timeZone: \"UTC\" });\n}\n\nfunction uptime(history: DayStatus[]) {\n  const known = history.filter((d) => d !== \"none\");\n  if (!known.length) return 100;\n  const score = known.reduce((s, d) => s + (d === \"operational\" ? 1 : d === \"degraded\" ? 0.995 : 0.97), 0);\n  return (score / known.length) * 100;\n}\n\nfunction UptimeBars({ component, today }: { component: StatusComponent; today: string }) {\n  const reduce = useReducedMotion();\n  const ref = useRef<HTMLDivElement>(null);\n  const [tip, setTip] = useState<{ i: number; left: number } | null>(null);\n  const n = component.history.length;\n  const mobileFrom = Math.max(0, n - 30);\n\n  const show = (i: number) => {\n    const box = ref.current;\n    const bar = box?.children[i] as HTMLElement | undefined;\n    if (!box || !bar) return;\n    const center = bar.offsetLeft + bar.offsetWidth / 2;\n    const w = 224;\n    setTip({ i, left: Math.min(Math.max(0, center - w / 2), box.offsetWidth - w) });\n  };\n\n  const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {\n    const first = (ref.current?.children[0] as HTMLElement | undefined)?.offsetParent ? 0 : mobileFrom;\n    const cur = tip?.i ?? n - 1;\n    if (e.key === \"ArrowLeft\" || e.key === \"ArrowRight\") {\n      e.preventDefault();\n      show(Math.min(n - 1, Math.max(first, cur + (e.key === \"ArrowRight\" ? 1 : -1))));\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      show(first);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      show(n - 1);\n    } else if (e.key === \"Escape\") {\n      setTip(null);\n    }\n  };\n\n  const day = tip ? component.history[tip.i] : null;\n\n  return (\n    <div className=\"relative\">\n      <div\n        aria-label={`${component.name}, daily uptime. Use arrow keys to inspect a day.`}\n        className=\"flex h-8 cursor-default items-stretch gap-[2px] rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card\"\n        onBlur={() => setTip(null)}\n        onFocus={() => show(n - 1)}\n        onKeyDown={onKeyDown}\n        onPointerLeave={() => setTip(null)}\n        ref={ref}\n        role=\"group\"\n        tabIndex={0}\n      >\n        {component.history.map((d, i) => (\n          <span\n            className={cn(\n              \"min-w-0 flex-1 rounded-[calc(var(--radius)*0.2)] transition-[opacity,scale] duration-150\",\n              DAY[d].bar,\n              i < mobileFrom && \"max-sm:hidden\",\n              tip && tip.i !== i && \"opacity-50\",\n              tip?.i === i && \"scale-y-110\",\n            )}\n            key={i}\n            onPointerEnter={() => show(i)}\n          />\n        ))}\n      </div>\n      <AnimatePresence>\n        {day && tip && (\n          <motion.div\n            animate={{ opacity: 1, y: 0, left: tip.left }}\n            className=\"pointer-events-none absolute bottom-full z-20 mb-2 w-56 rounded-xl border bg-popover p-3 text-popover-foreground shadow-lg/5\"\n            exit={{ opacity: 0, transition: { duration: 0.1 } }}\n            initial={{ opacity: 0, y: reduce ? 0 : 4, left: tip.left }}\n            role=\"tooltip\"\n            transition={{ duration: 0.14, ease, left: { duration: 0 } }}\n          >\n            <p className=\"font-medium text-xs\">{dayLabel(today, n - 1 - tip.i)}</p>\n            <p className=\"mt-1.5 flex items-center gap-2 text-xs\">\n              <span className={cn(\"size-2 shrink-0 rounded-full\", DAY[day].bar)} />\n              {DAY[day].label}\n            </p>\n            {component.notes?.[tip.i] && <p className=\"mt-1.5 text-pretty text-muted-foreground text-xs\">{component.notes[tip.i]}</p>}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport function StatusPage({\n  company = \"Fernway\",\n  today = \"2026-10-24\",\n  updatedAgo = \"1 min ago\",\n  components,\n  incidents = [],\n  onSubscribe = async () => {},\n  className,\n}: StatusPageProps) {\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const [subscribing, setSubscribing] = useState(false);\n  const [email, setEmail] = useState(\"\");\n  const [subState, setSubState] = useState<\"idle\" | \"busy\" | \"done\">(\"idle\");\n  const [error, setError] = useState(false);\n\n  const overall = useMemo(() => {\n    if (components.some((c) => c.status === \"outage\")) return \"outage\" as const;\n    if (components.some((c) => c.status === \"degraded\")) return \"degraded\" as const;\n    if (components.some((c) => c.status === \"maintenance\")) return \"maintenance\" as const;\n    return \"operational\" as const;\n  }, [components]);\n  const affected = components.filter((c) => c.status !== \"operational\");\n  const live = incidents.find((i) => i.updates[0]?.stage !== \"resolved\");\n\n  const banner = {\n    operational: {\n      icon: CircleCheckIcon,\n      title: \"All systems operational\",\n      box: \"border-success/25 bg-success/8 dark:bg-success/10\",\n      icon_: \"text-success-foreground\",\n    },\n    degraded: {\n      icon: TriangleAlertIcon,\n      title: `${affected.map((c) => c.name).join(\", \")} ${affected.length > 1 ? \"are\" : \"is\"} running slow`,\n      box: \"border-warning/30 bg-warning/8 dark:bg-warning/10\",\n      icon_: \"text-warning-foreground\",\n    },\n    outage: {\n      icon: OctagonAlertIcon,\n      title: `Outage affecting ${affected.map((c) => c.name).join(\", \")}`,\n      box: \"border-destructive/25 bg-destructive/8 dark:bg-destructive/12\",\n      icon_: \"text-destructive-foreground\",\n    },\n    maintenance: {\n      icon: TriangleAlertIcon,\n      title: \"Scheduled maintenance in progress\",\n      box: \"border-info/25 bg-info/8 dark:bg-info/10\",\n      icon_: \"text-info-foreground\",\n    },\n  }[overall];\n\n  const subscribe = async (e: FormEvent) => {\n    e.preventDefault();\n    if (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/.test(email.trim())) {\n      setError(true);\n      return;\n    }\n    setSubState(\"busy\");\n    await onSubscribe(email.trim());\n    setSubState(\"done\");\n  };\n\n  return (\n    <section className={cn(\"mx-auto w-full max-w-[880px] space-y-5\", className)}>\n      <header className=\"flex flex-wrap items-center justify-between gap-3\">\n        <div className=\"flex items-center gap-2.5\">\n          <span className=\"flex size-8 items-center justify-center rounded-lg bg-primary text-primary-foreground\">\n            <svg aria-hidden className=\"size-4.5\" fill=\"currentColor\" viewBox=\"0 0 18 18\">\n              <path d=\"M9 1.5c.6 3.6 2.4 5.4 6 6-3.6.6-5.4 2.4-6 6-.6-3.6-2.4-5.4-6-6 3.6-.6 5.4-2.4 6-6Z\" />\n            </svg>\n          </span>\n          <div>\n            <p className=\"font-semibold text-sm tracking-tight\">{company}</p>\n            <p className=\"text-muted-foreground text-xs\">System status</p>\n          </div>\n        </div>\n        <Button\n          aria-expanded={subscribing}\n          className={press}\n          onClick={() => setSubscribing((s) => !s)}\n          variant={subscribing ? \"secondary\" : \"outline\"}\n        >\n          <BellIcon />\n          Subscribe to updates\n        </Button>\n      </header>\n\n      <AnimatePresence initial={false}>\n        {subscribing && (\n          <motion.div\n            animate={{ height: \"auto\", opacity: 1 }}\n            className=\"-mx-1 overflow-hidden px-1\"\n            exit={{ height: 0, opacity: 0 }}\n            initial={{ height: 0, opacity: 0 }}\n            transition={{ duration: reduce ? 0 : 0.24, ease }}\n          >\n            <div className=\"pb-1\">\n              {subState === \"done\" ? (\n                <p className=\"flex items-center gap-2 rounded-2xl border bg-card px-4 py-3.5 text-sm shadow-xs/5\">\n                  <CheckIcon className=\"size-4 shrink-0 text-success-foreground\" strokeWidth={2.5} />\n                  <span className=\"min-w-0 text-pretty\">\n                    You’ll get an email at <span className=\"font-medium\">{email.trim()}</span> when anything changes.\n                  </span>\n                </p>\n              ) : (\n                <form\n                  className=\"flex flex-col gap-2 rounded-2xl border bg-card p-3 shadow-xs/5 sm:flex-row sm:items-center sm:ps-4\"\n                  noValidate\n                  onSubmit={subscribe}\n                >\n                  <label\n                    className={cn(\n                      \"shrink-0 text-sm transition-colors duration-150\",\n                      error ? \"text-destructive-foreground\" : \"text-muted-foreground\",\n                    )}\n                    htmlFor={`${uid}-sub`}\n                  >\n                    {error ? \"Enter a valid email address\" : \"Email me about incidents and maintenance\"}\n                  </label>\n                  <Input\n                    aria-invalid={error ? true : undefined}\n                    className=\"sm:ms-auto sm:max-w-60\"\n                    id={`${uid}-sub`}\n                    onChange={(e) => {\n                      setEmail(e.target.value);\n                      setError(false);\n                    }}\n                    placeholder=\"you@company.com\"\n                    type=\"email\"\n                    value={email}\n                  />\n                  <Button className={press} loading={subState === \"busy\"} type=\"submit\">\n                    Subscribe\n                  </Button>\n                </form>\n              )}\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n\n      <div className={cn(\"flex items-start gap-3 rounded-2xl border p-4 sm:items-center sm:p-5\", banner.box)} role=\"status\">\n        <banner.icon className={cn(\"mt-0.5 size-5 shrink-0 sm:mt-0\", banner.icon_)} />\n        <div className=\"min-w-0 flex-1\">\n          <p className=\"text-balance font-medium\">{banner.title}</p>\n          {live && <p className=\"mt-0.5 text-pretty text-muted-foreground text-sm\">{live.updates[0].body}</p>}\n        </div>\n        <span className=\"hidden shrink-0 items-center gap-1.5 text-muted-foreground text-xs sm:flex\">\n          <span className=\"relative flex size-1.5\">\n            <span className=\"absolute inset-0 animate-ping rounded-full bg-success/60 motion-reduce:hidden\" />\n            <span className=\"relative size-1.5 rounded-full bg-success\" />\n          </span>\n          Updated {updatedAgo}\n        </span>\n      </div>\n\n      <div className=\"rounded-2xl border bg-card shadow-xs/5\">\n        <ul className=\"divide-y\">\n          {components.map((c) => {\n            const s = SERVICE[c.status];\n            return (\n              <li className=\"px-4 py-4 sm:px-5\" key={c.id}>\n                <div className=\"flex items-baseline justify-between gap-3\">\n                  <div className=\"min-w-0\">\n                    <p className=\"truncate font-medium text-sm\">{c.name}</p>\n                    {c.description && <p className=\"truncate text-muted-foreground text-xs\">{c.description}</p>}\n                  </div>\n                  <span className={cn(\"flex shrink-0 items-center gap-1.5 font-medium text-xs\", s.text)}>\n                    <span className={cn(\"size-1.5 rounded-full\", s.dot)} />\n                    {s.label}\n                  </span>\n                </div>\n                <div className=\"mt-3\">\n                  <UptimeBars component={c} today={today} />\n                </div>\n                <div className=\"mt-2 flex items-center justify-between gap-2 text-muted-foreground text-xs\">\n                  <span className=\"sm:hidden\">30 days ago</span>\n                  <span className=\"max-sm:hidden\">{c.history.length} days ago</span>\n                  <span className=\"h-px flex-1 bg-border\" />\n                  <span className=\"tabular-nums sm:hidden\">{uptime(c.history.slice(-30)).toFixed(2)}% uptime</span>\n                  <span className=\"tabular-nums max-sm:hidden\">{uptime(c.history).toFixed(2)}% uptime</span>\n                  <span className=\"h-px flex-1 bg-border\" />\n                  <span>Today</span>\n                </div>\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n\n      {incidents.length > 0 && (\n        <div>\n          <h3 className=\"font-medium text-sm\">Recent incidents</h3>\n          <ol className=\"mt-3 space-y-3\">\n            {incidents.map((inc) => {\n              const resolved = inc.updates[0]?.stage === \"resolved\";\n              return (\n                <li className=\"rounded-2xl border bg-card p-4 shadow-xs/5 sm:p-5\" key={inc.id}>\n                  <div className=\"flex flex-wrap items-center justify-between gap-x-3 gap-y-1\">\n                    <p className=\"flex items-center gap-2 font-medium text-sm\">\n                      <span\n                        className={cn(\n                          \"size-2 shrink-0 rounded-full\",\n                          resolved ? \"bg-muted-foreground/40\" : inc.impact === \"major\" ? \"bg-destructive\" : \"bg-warning\",\n                        )}\n                      />\n                      {inc.title}\n                    </p>\n                    <span className=\"text-muted-foreground text-xs\">{inc.date}</span>\n                  </div>\n                  <ol className=\"relative mt-3 space-y-3 ps-5 before:absolute before:top-1.5 before:bottom-1.5 before:left-[3px] before:w-px before:bg-border\">\n                    {inc.updates.map((u, i) => (\n                      <li className=\"relative\" key={`${u.stage}-${u.time}`}>\n                        <span\n                          className={cn(\n                            \"absolute top-1.5 -left-5 size-[7px] rounded-full ring-2 ring-card\",\n                            i === 0 ? STAGE[u.stage].dot : \"bg-muted-foreground/35\",\n                          )}\n                        />\n                        <p className=\"text-xs\">\n                          <span className=\"font-medium\">{STAGE[u.stage].label}</span>\n                          <span className=\"text-muted-foreground\"> · {u.time}</span>\n                        </p>\n                        <p className=\"mt-0.5 text-pretty text-muted-foreground text-sm\">{u.body}</p>\n                      </li>\n                    ))}\n                  </ol>\n                </li>\n              );\n            })}\n          </ol>\n        </div>\n      )}\n    </section>\n  );\n}\n"
    }
  ]
}