{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "developer-settings",
  "type": "registry:block",
  "title": "API Keys & Webhooks",
  "description": "Scoped API keys with a show-once secret, roll and revoke, plus webhook endpoints with event picking, a signing secret and a deliveries log where failed sends retry and flip to 200.",
  "categories": [
    "screen",
    "Settings"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/alert-dialog.json",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/checkbox.json",
    "https://coss.com/ui/r/dialog.json",
    "https://coss.com/ui/r/input.json",
    "https://coss.com/ui/r/label.json",
    "https://coss.com/ui/r/menu.json",
    "https://coss.com/ui/r/select.json",
    "https://coss.com/ui/r/spinner.json",
    "https://coss.com/ui/r/switch.json"
  ],
  "files": [
    {
      "path": "registry/devl/developer-settings.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowLeftIcon,\n  BellIcon,\n  CheckIcon,\n  ClockIcon,\n  CopyIcon,\n  CreditCardIcon,\n  EllipsisIcon,\n  EyeIcon,\n  EyeOffIcon,\n  KeyRoundIcon,\n  PaletteIcon,\n  PlusIcon,\n  RefreshCwIcon,\n  RotateCwIcon,\n  SendIcon,\n  SettingsIcon,\n  ShieldIcon,\n  Trash2Icon,\n  TriangleAlertIcon,\n  UserIcon,\n  UsersIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type FormEvent, type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport {\n  AlertDialog,\n  AlertDialogClose,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogPopup,\n  AlertDialogTitle,\n} from \"@/components/ui/alert-dialog\";\nimport { Button } from \"@/components/ui/button\";\nimport { Checkbox } from \"@/components/ui/checkbox\";\nimport { Dialog, DialogClose, DialogDescription, DialogFooter, DialogHeader, DialogPanel, DialogPopup, DialogTitle } from \"@/components/ui/dialog\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from \"@/components/ui/menu\";\nimport { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { Spinner } from \"@/components/ui/spinner\";\nimport { Switch } from \"@/components/ui/switch\";\n\nexport type SettingsSectionId =\n  | \"profile\"\n  | \"appearance\"\n  | \"notifications\"\n  | \"security\"\n  | \"general\"\n  | \"members\"\n  | \"billing\"\n  | \"developer\";\n\nexport interface DevScopeResource {\n  id: string;\n  name: string;\n  readOnly?: boolean;\n}\n\nexport interface DevApiKey {\n  id: string;\n  name: string;\n  last4: string;\n  scopes: string[];\n  expires?: string;\n  daysLeft?: number;\n  lastUsed?: string;\n}\n\nexport interface DevEventGroup {\n  id: string;\n  name: string;\n  events: { id: string; hint: string }[];\n}\n\nexport interface DevDelivery {\n  id: string;\n  event: string;\n  status: number | \"timeout\";\n  latency: number;\n  time: string;\n}\n\nexport interface DevEndpoint {\n  id: string;\n  url: string;\n  paused?: boolean;\n  events: string[];\n  secret: string;\n  deliveries: DevDelivery[];\n}\n\nexport interface DeveloperSettingsProps {\n  className?: string;\n  today?: string;\n  keyPrefix?: string;\n  resources?: DevScopeResource[];\n  apiKeys?: DevApiKey[];\n  eventGroups?: DevEventGroup[];\n  endpoints?: DevEndpoint[];\n  onNavigate?: (section: SettingsSectionId) => void;\n}\n\nconst easeOut = [0.23, 1, 0.32, 1] as const;\nconst press = \"transition-[color,background-color,box-shadow,scale] duration-150 ease-out active:scale-[0.97]\";\nconst alphabet = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\nconst navGroups: { label: string; items: { id: SettingsSectionId; label: string; icon: ReactNode }[] }[] = [\n  {\n    label: \"Account\",\n    items: [\n      { id: \"profile\", label: \"Profile\", icon: <UserIcon /> },\n      { id: \"appearance\", label: \"Appearance\", icon: <PaletteIcon /> },\n      { id: \"notifications\", label: \"Notifications\", icon: <BellIcon /> },\n      { id: \"security\", label: \"Security\", icon: <ShieldIcon /> },\n    ],\n  },\n  {\n    label: \"Workspace\",\n    items: [\n      { id: \"general\", label: \"General\", icon: <SettingsIcon /> },\n      { id: \"members\", label: \"Members & roles\", icon: <UsersIcon /> },\n      { id: \"billing\", label: \"Billing\", icon: <CreditCardIcon /> },\n    ],\n  },\n  {\n    label: \"Developer\",\n    items: [{ id: \"developer\", label: \"API keys & webhooks\", icon: <KeyRoundIcon /> }],\n  },\n];\n\nconst expiryOptions = [\n  { value: \"7\", label: \"7 days\" },\n  { value: \"30\", label: \"30 days\" },\n  { value: \"90\", label: \"90 days\" },\n  { value: \"365\", label: \"1 year\" },\n  { value: \"0\", label: \"No expiry\" },\n];\n\nconst defaultResources: DevScopeResource[] = [\n  { id: \"projects\", name: \"Projects\" },\n  { id: \"deployments\", name: \"Deployments\" },\n  { id: \"domains\", name: \"Domains\" },\n  { id: \"env\", name: \"Environment variables\" },\n  { id: \"webhooks\", name: \"Webhooks\" },\n  { id: \"logs\", name: \"Logs\", readOnly: true },\n];\n\nconst defaultKeys: DevApiKey[] = [\n  {\n    id: \"k1\",\n    name: \"GitHub Actions deploy\",\n    last4: \"8f2a\",\n    scopes: [\"write:deployments\", \"read:deployments\", \"read:projects\", \"read:logs\"],\n    expires: \"Feb 4, 2027\",\n    daysLeft: 100,\n    lastUsed: \"2 min ago\",\n  },\n  {\n    id: \"k2\",\n    name: \"Status page sync\",\n    last4: \"41ad\",\n    scopes: [\"read:deployments\", \"read:logs\"],\n    expires: \"Nov 3, 2026\",\n    daysLeft: 7,\n    lastUsed: \"3 hours ago\",\n  },\n  {\n    id: \"k3\",\n    name: \"Terraform\",\n    last4: \"c07e\",\n    scopes: [\n      \"write:projects\",\n      \"read:projects\",\n      \"write:deployments\",\n      \"read:deployments\",\n      \"write:domains\",\n      \"read:domains\",\n      \"write:env\",\n      \"read:env\",\n      \"read:logs\",\n    ],\n    lastUsed: \"41 days ago\",\n  },\n  {\n    id: \"k4\",\n    name: \"Jonah’s local scripts\",\n    last4: \"9b13\",\n    scopes: [\"read:projects\", \"read:env\"],\n    expires: \"Nov 19, 2026\",\n    daysLeft: 23,\n  },\n];\n\nconst defaultEventGroups: DevEventGroup[] = [\n  {\n    id: \"deployment\",\n    name: \"Deployments\",\n    events: [\n      { id: \"deployment.created\", hint: \"A build starts\" },\n      { id: \"deployment.succeeded\", hint: \"A build is ready\" },\n      { id: \"deployment.failed\", hint: \"A build or check fails\" },\n      { id: \"deployment.promoted\", hint: \"A preview goes to production\" },\n    ],\n  },\n  {\n    id: \"project\",\n    name: \"Projects\",\n    events: [\n      { id: \"project.created\", hint: \"A project is created\" },\n      { id: \"project.deleted\", hint: \"A project is deleted\" },\n    ],\n  },\n  {\n    id: \"domain\",\n    name: \"Domains\",\n    events: [\n      { id: \"domain.verified\", hint: \"DNS checks pass\" },\n      { id: \"domain.expiring\", hint: \"A certificate is close to expiry\" },\n    ],\n  },\n  {\n    id: \"member\",\n    name: \"Members\",\n    events: [\n      { id: \"member.added\", hint: \"Someone joins\" },\n      { id: \"member.removed\", hint: \"Someone leaves\" },\n    ],\n  },\n];\n\nconst defaultEndpoints: DevEndpoint[] = [\n  {\n    id: \"e1\",\n    url: \"https://api.paperkite.app/webhooks/ridgeline\",\n    events: [\"deployment.created\", \"deployment.succeeded\", \"deployment.failed\", \"deployment.promoted\", \"project.created\"],\n    secret: \"rlsig_test_Q2m8vLx4TfR9kZp1Wd7nYc3h\",\n    deliveries: [\n      { id: \"d1\", event: \"deployment.failed\", status: 503, latency: 2140, time: \"2 min ago\" },\n      { id: \"d2\", event: \"deployment.succeeded\", status: \"timeout\", latency: 10000, time: \"9 min ago\" },\n      { id: \"d3\", event: \"deployment.promoted\", status: 200, latency: 182, time: \"1 hour ago\" },\n      { id: \"d4\", event: \"deployment.created\", status: 200, latency: 164, time: \"1 hour ago\" },\n      { id: \"d5\", event: \"project.created\", status: 201, latency: 240, time: \"3 hours ago\" },\n    ],\n  },\n  {\n    id: \"e2\",\n    url: \"https://ops.ridgeline.app/hooks/deploy-bot\",\n    events: [\"deployment.failed\", \"domain.verified\", \"domain.expiring\", \"member.added\", \"member.removed\"],\n    secret: \"rlsig_test_Hn5bWq0Ys8Lr2Mc6Xe4Tj9Ka\",\n    deliveries: [\n      { id: \"d6\", event: \"member.added\", status: 204, latency: 96, time: \"26 min ago\" },\n      { id: \"d7\", event: \"domain.verified\", status: 204, latency: 88, time: \"2 hours ago\" },\n      { id: \"d8\", event: \"deployment.failed\", status: 204, latency: 131, time: \"Yesterday\" },\n    ],\n  },\n  {\n    id: \"e3\",\n    url: \"https://ci.grovehouse.io/preview-comments\",\n    paused: true,\n    events: [\"deployment.succeeded\"],\n    secret: \"rlsig_test_Pz3cVn7Rk1Gd5Sy9Bf2Lm6Qw\",\n    deliveries: [{ id: \"d9\", event: \"deployment.succeeded\", status: 200, latency: 301, time: \"Oct 12\" }],\n  },\n];\n\nfunction useReducedMotionAfterMount() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && Boolean(prefers);\n}\n\nfunction randomToken(length: number) {\n  const bytes = new Uint8Array(length);\n  crypto.getRandomValues(bytes);\n  return Array.from(bytes, (b) => alphabet[b % alphabet.length]).join(\"\");\n}\n\nfunction addDays(iso: string, days: number) {\n  const d = new Date(`${iso}T00:00:00Z`);\n  d.setUTCDate(d.getUTCDate() + days);\n  return d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\", year: \"numeric\", timeZone: \"UTC\" });\n}\n\nfunction isOk(status: DevDelivery[\"status\"]) {\n  return typeof status === \"number\" && status < 300;\n}\n\nfunction hostOf(url: string) {\n  return url.replace(/^https?:\\/\\//, \"\").split(\"/\")[0];\n}\n\nfunction formatLatency(ms: number) {\n  return ms >= 1000 ? `${(ms / 1000).toFixed(1)} s` : `${ms} ms`;\n}\n\nfunction useCopy() {\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout> | null>(null);\n  useEffect(() => () => {\n    if (timer.current) clearTimeout(timer.current);\n  }, []);\n  const copy = (text: string) => {\n    navigator.clipboard?.writeText(text).catch(() => {});\n    setCopied(true);\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(false), 1800);\n  };\n  return { copied, copy };\n}\n\nfunction RidgelineShell({\n  active,\n  onNavigate,\n  children,\n  className,\n}: {\n  active: SettingsSectionId;\n  onNavigate?: (section: SettingsSectionId) => void;\n  children: ReactNode;\n  className?: string;\n}) {\n  const pillsRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const scroller = pillsRef.current;\n    const el = scroller?.querySelector<HTMLElement>(`[data-section=\"${active}\"]`);\n    if (!scroller || !el || scroller.scrollWidth <= scroller.clientWidth) return;\n    scroller.scrollLeft = el.offsetLeft - 16;\n  }, [active]);\n\n  return (\n    <div className={cn(\"flex h-[760px] w-full bg-background text-foreground\", className)}>\n      <aside className=\"hidden w-60 shrink-0 flex-col border-r bg-muted/30 px-3 py-4 md:flex\">\n        <button\n          className=\"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-muted-foreground text-sm outline-none transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n          type=\"button\"\n        >\n          <ArrowLeftIcon className=\"size-4\" />\n          Back to Ridgeline\n        </button>\n        <nav aria-label=\"Settings\" className=\"flex flex-col\">\n          {navGroups.map((group) => (\n            <div className=\"flex flex-col\" key={group.label}>\n              <span className=\"px-2 pt-5 pb-1.5 font-medium text-muted-foreground text-xs\">{group.label}</span>\n              <div className=\"flex flex-col gap-0.5\">\n                {group.items.map((item) => {\n                  const current = item.id === active;\n                  return (\n                    <button\n                      aria-current={current ? \"page\" : undefined}\n                      className={cn(\n                        \"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-left text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground\",\n                        current ? \"bg-accent font-medium text-foreground\" : \"text-foreground/80 hover:bg-accent/60\",\n                      )}\n                      key={item.id}\n                      onClick={() => onNavigate?.(item.id)}\n                      type=\"button\"\n                    >\n                      {item.icon}\n                      <span className=\"truncate\">{item.label}</span>\n                    </button>\n                  );\n                })}\n              </div>\n            </div>\n          ))}\n        </nav>\n        <div className=\"mt-auto flex items-center gap-2.5 px-2 pt-4\">\n          <span className=\"flex size-7 shrink-0 items-center justify-center rounded-full bg-foreground font-medium text-[11px] text-background\">\n            AL\n          </span>\n          <span className=\"flex min-w-0 flex-col\">\n            <span className=\"truncate font-medium text-sm\">Ada Lindqvist</span>\n            <span className=\"truncate text-muted-foreground text-xs\">ada@ridgeline.app</span>\n          </span>\n        </div>\n      </aside>\n      <div className=\"flex min-w-0 flex-1 flex-col\">\n        <div className=\"md:hidden\">\n          <div className=\"flex h-12 items-center gap-2 border-b px-4\">\n            <button\n              aria-label=\"Back to Ridgeline\"\n              className=\"-ms-1.5 flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent/60 focus-visible:ring-2 focus-visible:ring-ring\"\n              type=\"button\"\n            >\n              <ArrowLeftIcon className=\"size-4\" />\n            </button>\n            <span className=\"font-medium text-sm\">Settings</span>\n          </div>\n          <nav\n            aria-label=\"Settings\"\n            className=\"overflow-x-auto border-b px-4 py-2.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n            ref={pillsRef}\n          >\n            <div className=\"flex w-max gap-1.5\">\n              {navGroups.flatMap((g) => g.items).map((item) => {\n                const current = item.id === active;\n                return (\n                  <button\n                    aria-current={current ? \"page\" : undefined}\n                    className={cn(\n                      \"flex h-7 cursor-pointer items-center rounded-full px-3 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                      current\n                        ? \"bg-foreground font-medium text-background\"\n                        : \"bg-muted text-muted-foreground hover:text-foreground\",\n                    )}\n                    data-section={item.id}\n                    key={item.id}\n                    onClick={() => onNavigate?.(item.id)}\n                    type=\"button\"\n                  >\n                    {item.label}\n                  </button>\n                );\n              })}\n            </div>\n          </nav>\n        </div>\n        <div className=\"min-h-0 flex-1 overflow-y-auto\">{children}</div>\n      </div>\n    </div>\n  );\n}\n\nfunction SwapIcon({ on, onIcon, offIcon }: { on: boolean; onIcon: ReactNode; offIcon: ReactNode }) {\n  return (\n    <AnimatePresence initial={false} mode=\"popLayout\">\n      <motion.span\n        animate={{ opacity: 1, scale: 1 }}\n        className=\"flex\"\n        exit={{ opacity: 0, scale: 0.8 }}\n        initial={{ opacity: 0, scale: 0.8 }}\n        key={on ? \"on\" : \"off\"}\n        transition={{ duration: 0.15, ease: easeOut }}\n      >\n        {on ? onIcon : offIcon}\n      </motion.span>\n    </AnimatePresence>\n  );\n}\n\nfunction SectionHeader({ title, description, action }: { title: string; description: string; action?: ReactNode }) {\n  return (\n    <div className=\"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between sm:gap-4\">\n      <div className=\"min-w-0\">\n        <h2 className=\"font-medium text-sm\">{title}</h2>\n        <p className=\"text-pretty text-muted-foreground text-sm\">{description}</p>\n      </div>\n      {action}\n    </div>\n  );\n}\n\nfunction ScopeChips({ scopes }: { scopes: string[] }) {\n  const chip = \"inline-flex h-5 items-center rounded-md bg-muted px-1.5 font-mono text-[11px] text-foreground\";\n  if (scopes.length === 0) return <span className=\"text-muted-foreground text-sm\">None</span>;\n  return (\n    <span className=\"flex min-w-0 items-center gap-1\">\n      <span className={cn(chip, \"truncate\")}>{scopes[0]}</span>\n      {scopes.length > 1 && <span className={cn(chip, \"shrink-0 text-muted-foreground\")}>+{scopes.length - 1}</span>}\n    </span>\n  );\n}\n\nfunction Expiry({ apiKey }: { apiKey: DevApiKey }) {\n  if (!apiKey.expires) return <span className=\"text-muted-foreground\">Never</span>;\n  const soon = (apiKey.daysLeft ?? 99) < 14;\n  return (\n    <span className={cn(\"inline-flex items-center gap-1 tabular-nums\", soon ? \"text-destructive-foreground\" : \"text-muted-foreground\")}>\n      {apiKey.expires}\n      {soon && <ClockIcon aria-label={`Expires in ${apiKey.daysLeft} days`} className=\"size-3.5\" />}\n    </span>\n  );\n}\n\nfunction StatusCode({ status, busy, reduce }: { status: DevDelivery[\"status\"]; busy: boolean; reduce: boolean }) {\n  const ok = isOk(status);\n  return (\n    <span\n      className={cn(\n        \"relative inline-flex h-5 w-[3.75rem] items-center justify-center overflow-hidden rounded-md px-1.5 font-medium font-mono text-[11px] tabular-nums transition-colors duration-200\",\n        busy\n          ? \"bg-muted text-muted-foreground\"\n          : ok\n            ? \"bg-success/10 text-success-foreground dark:bg-success/16\"\n            : \"bg-destructive/8 text-destructive-foreground dark:bg-destructive/16\",\n      )}\n    >\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ opacity: 1, y: 0 }}\n          className=\"flex items-center\"\n          exit={reduce ? { opacity: 0 } : { opacity: 0, y: -8 }}\n          initial={reduce ? { opacity: 0 } : { opacity: 0, y: 8 }}\n          key={busy ? \"busy\" : String(status)}\n          transition={{ duration: 0.2, ease: easeOut }}\n        >\n          {busy ? <Spinner className=\"size-3\" /> : status === \"timeout\" ? \"timeout\" : status}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction SecretReveal({ name, secret, onDone, reduce }: { name: string; secret: string; onDone: () => void; reduce: boolean }) {\n  const { copied, copy } = useCopy();\n  const [everCopied, setEverCopied] = useState(false);\n  return (\n    <>\n      <DialogHeader>\n        <DialogTitle>Save your key</DialogTitle>\n        <DialogDescription>\n          <span className=\"font-medium text-foreground\">{name}</span> is ready. This is the only time the full key is shown.\n        </DialogDescription>\n      </DialogHeader>\n      <DialogPanel className=\"flex flex-col gap-3\">\n        <div\n          className={cn(\n            \"relative flex items-center gap-2 overflow-hidden rounded-lg border bg-muted/50 py-1.5 ps-3 pe-1.5 transition-colors duration-300\",\n            copied && \"border-success/40 bg-success/6\",\n          )}\n        >\n          <AnimatePresence>\n            {copied && !reduce && (\n              <motion.span\n                animate={{ x: \"100%\" }}\n                aria-hidden\n                className=\"pointer-events-none absolute inset-y-0 left-0 w-full bg-gradient-to-r from-transparent via-success/15 to-transparent\"\n                exit={{ opacity: 0 }}\n                initial={{ x: \"-100%\" }}\n                transition={{ duration: 0.6, ease: easeOut }}\n              />\n            )}\n          </AnimatePresence>\n          <code className=\"relative min-w-0 flex-1 break-all font-mono text-xs leading-5\">{secret}</code>\n          <Button\n            className={cn(\"relative shrink-0\", press)}\n            onClick={() => {\n              copy(secret);\n              setEverCopied(true);\n            }}\n            size=\"sm\"\n            variant=\"outline\"\n          >\n            <SwapIcon offIcon={<CopyIcon />} on={copied} onIcon={<CheckIcon className=\"text-success-foreground\" />} />\n            {copied ? \"Copied\" : \"Copy\"}\n          </Button>\n        </div>\n        <p className=\"flex items-start gap-2 text-pretty text-muted-foreground text-xs\">\n          <TriangleAlertIcon className=\"mt-px size-3.5 shrink-0 text-warning-foreground\" />\n          Store it in your secret manager now. If it’s lost, roll the key to get a new one.\n        </p>\n      </DialogPanel>\n      <DialogFooter>\n        <Button className={press} onClick={onDone} variant={everCopied ? \"default\" : \"outline\"}>\n          {everCopied ? \"Done\" : \"I’ve saved it\"}\n        </Button>\n      </DialogFooter>\n    </>\n  );\n}\n\nfunction CreateKeyForm({\n  resources,\n  today,\n  onCreate,\n}: {\n  resources: DevScopeResource[];\n  today: string;\n  onCreate: (name: string, scopes: string[], days: number) => void;\n}) {\n  const id = useId();\n  const [name, setName] = useState(\"\");\n  const [scopes, setScopes] = useState<string[]>([\"read:projects\", \"read:deployments\"]);\n  const [expiry, setExpiry] = useState(\"90\");\n  const days = Number(expiry);\n\n  const setAccess = (resource: string, kind: \"read\" | \"write\", on: boolean) =>\n    setScopes((all) => {\n      const read = `read:${resource}`;\n      const write = `write:${resource}`;\n      const rest = all.filter((s) => s !== read && s !== write);\n      const hasWrite = all.includes(write);\n      if (kind === \"write\") return on ? [...rest, write, read] : [...rest, read];\n      if (!on) return rest;\n      return hasWrite ? [...rest, write, read] : [...rest, read];\n    });\n\n  const submit = (e: FormEvent) => {\n    e.preventDefault();\n    if (!name.trim() || scopes.length === 0) return;\n    onCreate(name.trim(), [...scopes.filter((s) => s.startsWith(\"write\")), ...scopes.filter((s) => s.startsWith(\"read\"))], days);\n  };\n\n  return (\n    <form className=\"contents\" onSubmit={submit}>\n      <DialogHeader>\n        <DialogTitle>Create API key</DialogTitle>\n        <DialogDescription>Keys act as the workspace, not as you. Give each one only what it needs.</DialogDescription>\n      </DialogHeader>\n      <DialogPanel className=\"flex flex-col gap-5\">\n        <div className=\"flex flex-col gap-2\">\n          <Label htmlFor={`${id}-name`}>Name</Label>\n          <Input autoFocus id={`${id}-name`} onChange={(e) => setName(e.target.value)} placeholder=\"Release pipeline\" value={name} />\n        </div>\n        <fieldset className=\"flex flex-col gap-2\">\n          <legend className=\"mb-2 font-medium text-sm\">Scopes</legend>\n          <div className=\"divide-y rounded-lg border\">\n            {resources.map((r) => {\n              const read = scopes.includes(`read:${r.id}`);\n              const write = scopes.includes(`write:${r.id}`);\n              return (\n                <div className=\"flex items-center gap-3 px-3 py-2\" key={r.id}>\n                  <span className=\"min-w-0 flex-1 truncate text-sm\">{r.name}</span>\n                  <label className=\"flex cursor-pointer items-center gap-1.5 font-mono text-muted-foreground text-xs\">\n                    <Checkbox checked={read} onCheckedChange={(on) => setAccess(r.id, \"read\", Boolean(on))} />\n                    read\n                  </label>\n                  <label\n                    className={cn(\n                      \"flex w-14 items-center gap-1.5 font-mono text-muted-foreground text-xs\",\n                      r.readOnly ? \"cursor-not-allowed opacity-40\" : \"cursor-pointer\",\n                    )}\n                  >\n                    <Checkbox checked={write} disabled={r.readOnly} onCheckedChange={(on) => setAccess(r.id, \"write\", Boolean(on))} />\n                    write\n                  </label>\n                </div>\n              );\n            })}\n          </div>\n          <p className=\"text-muted-foreground text-xs\">Write includes read.</p>\n        </fieldset>\n        <div className=\"flex flex-col gap-2\">\n          <Label>Expires</Label>\n          <Select items={expiryOptions} onValueChange={(v) => v && setExpiry(v as string)} value={expiry}>\n            <SelectTrigger aria-label=\"Expiry\">\n              <SelectValue />\n            </SelectTrigger>\n            <SelectPopup>\n              {expiryOptions.map((o) => (\n                <SelectItem key={o.value} value={o.value}>\n                  {o.label}\n                </SelectItem>\n              ))}\n            </SelectPopup>\n          </Select>\n          <p className={cn(\"text-xs tabular-nums\", days === 0 ? \"text-warning-foreground\" : \"text-muted-foreground\")}>\n            {days === 0 ? \"Keys that never expire are easy to forget about.\" : `Stops working on ${addDays(today, days)}.`}\n          </p>\n        </div>\n      </DialogPanel>\n      <DialogFooter>\n        <DialogClose render={<Button variant=\"ghost\" />}>Cancel</DialogClose>\n        <Button className={press} disabled={!name.trim() || scopes.length === 0} type=\"submit\">\n          Create key\n        </Button>\n      </DialogFooter>\n    </form>\n  );\n}\n\nfunction EventsForm({\n  groups,\n  initial,\n  url,\n  onSave,\n}: {\n  groups: DevEventGroup[];\n  initial: string[];\n  url?: string;\n  onSave: (events: string[], url: string) => void;\n}) {\n  const id = useId();\n  const [selected, setSelected] = useState(initial);\n  const [value, setValue] = useState(\"\");\n  const [error, setError] = useState<string | null>(null);\n  const adding = url === undefined;\n\n  const submit = (e: FormEvent) => {\n    e.preventDefault();\n    if (adding && !/^https:\\/\\/[^\\s/]+\\.[^\\s/]+/.test(value.trim())) {\n      setError(\"Use a full https:// address.\");\n      return;\n    }\n    onSave(selected, adding ? value.trim() : url);\n  };\n\n  return (\n    <form className=\"contents\" onSubmit={submit}>\n      <DialogHeader>\n        <DialogTitle>{adding ? \"Add endpoint\" : \"Events\"}</DialogTitle>\n        <DialogDescription>\n          {adding ? \"Ridgeline sends a signed POST to this URL for each event you pick.\" : <span className=\"break-all font-mono text-xs\">{url}</span>}\n        </DialogDescription>\n      </DialogHeader>\n      <DialogPanel className=\"flex flex-col gap-5\">\n        {adding && (\n          <div className=\"flex flex-col gap-2\">\n            <Label htmlFor={`${id}-url`}>Endpoint URL</Label>\n            <Input\n              aria-describedby={error ? `${id}-error` : undefined}\n              aria-invalid={error ? true : undefined}\n              autoFocus\n              id={`${id}-url`}\n              onChange={(e) => {\n                setValue(e.target.value);\n                setError(null);\n              }}\n              placeholder=\"https://example.com/webhooks\"\n              type=\"url\"\n              value={value}\n            />\n            {error && (\n              <p className=\"text-destructive-foreground text-xs\" id={`${id}-error`}>\n                {error}\n              </p>\n            )}\n          </div>\n        )}\n        <div className=\"flex flex-col gap-4\">\n          {groups.map((g) => {\n            const ids = g.events.map((e) => e.id);\n            const count = ids.filter((e) => selected.includes(e)).length;\n            return (\n              <div className=\"flex flex-col gap-2\" key={g.id}>\n                <label className=\"flex w-fit cursor-pointer items-center gap-2 font-medium text-sm\">\n                  <Checkbox\n                    checked={count === ids.length}\n                    indeterminate={count > 0 && count < ids.length}\n                    onCheckedChange={(on) => setSelected((s) => (on ? Array.from(new Set([...s, ...ids])) : s.filter((e) => !ids.includes(e))))}\n                  />\n                  {g.name}\n                </label>\n                <div className=\"grid gap-x-4 gap-y-1.5 ps-6 sm:grid-cols-2\">\n                  {g.events.map((ev) => (\n                    <label className=\"flex cursor-pointer items-start gap-2\" key={ev.id}>\n                      <Checkbox\n                        checked={selected.includes(ev.id)}\n                        className=\"mt-0.5\"\n                        onCheckedChange={(on) => setSelected((s) => (on ? [...s, ev.id] : s.filter((e) => e !== ev.id)))}\n                      />\n                      <span className=\"flex min-w-0 flex-col\">\n                        <span className=\"truncate font-mono text-xs\">{ev.id}</span>\n                        <span className=\"text-muted-foreground text-xs\">{ev.hint}</span>\n                      </span>\n                    </label>\n                  ))}\n                </div>\n              </div>\n            );\n          })}\n        </div>\n      </DialogPanel>\n      <DialogFooter>\n        <DialogClose render={<Button variant=\"ghost\" />}>Cancel</DialogClose>\n        <Button className={press} disabled={selected.length === 0} type=\"submit\">\n          {adding ? \"Add endpoint\" : \"Save events\"}\n        </Button>\n      </DialogFooter>\n    </form>\n  );\n}\n\nexport function DeveloperSettings({\n  className,\n  today = \"2026-10-27\",\n  keyPrefix = \"dvl_test_\",\n  resources = defaultResources,\n  apiKeys = defaultKeys,\n  eventGroups = defaultEventGroups,\n  endpoints: initialEndpoints = defaultEndpoints,\n  onNavigate,\n}: DeveloperSettingsProps) {\n  const reduce = useReducedMotionAfterMount();\n  const [keys, setKeys] = useState(apiKeys);\n  const [endpoints, setEndpoints] = useState(initialEndpoints);\n  const [selectedId, setSelectedId] = useState(initialEndpoints[0]?.id ?? \"\");\n  const [keyDialog, setKeyDialog] = useState<{ mode: \"create\" } | { mode: \"reveal\"; name: string; secret: string } | null>(null);\n  const [keyDialogOpen, setKeyDialogOpen] = useState(false);\n  const [eventsDialog, setEventsDialog] = useState<{ endpointId?: string; key: number } | null>(null);\n  const [eventsOpen, setEventsOpen] = useState(false);\n  const [revoking, setRevoking] = useState<DevApiKey | null>(null);\n  const [revokeOpen, setRevokeOpen] = useState(false);\n  const [deleting, setDeleting] = useState<DevEndpoint | null>(null);\n  const [deleteOpen, setDeleteOpen] = useState(false);\n  const [fresh, setFresh] = useState<string | null>(null);\n  const [revealed, setRevealed] = useState(false);\n  const [rolled, setRolled] = useState<string | null>(null);\n  const [busy, setBusy] = useState<string[]>([]);\n  const counter = useRef(0);\n  const timers = useRef<ReturnType<typeof setTimeout>[]>([]);\n  const secretCopy = useCopy();\n\n  useEffect(() => () => timers.current.forEach(clearTimeout), []);\n\n  const later = (fn: () => void, ms: number) => {\n    timers.current.push(setTimeout(fn, ms));\n  };\n\n  const endpoint = endpoints.find((e) => e.id === selectedId) ?? endpoints[0];\n  const statusOf = (e: DevEndpoint) => (e.paused ? \"paused\" : e.deliveries.some((d) => !isOk(d.status)) ? \"failing\" : \"active\");\n  const updateEndpoint = (eid: string, fn: (e: DevEndpoint) => DevEndpoint) => setEndpoints((all) => all.map((e) => (e.id === eid ? fn(e) : e)));\n  const totalEvents = eventGroups.reduce((n, g) => n + g.events.length, 0);\n\n  const flash = (kid: string) => {\n    setFresh(kid);\n    later(() => setFresh((f) => (f === kid ? null : f)), 2400);\n  };\n\n  const createKey = (name: string, scopes: string[], days: number) => {\n    const token = randomToken(32);\n    counter.current += 1;\n    const kid = `new-${counter.current}`;\n    setKeys((all) => [\n      { id: kid, name, last4: token.slice(-4), scopes, expires: days ? addDays(today, days) : undefined, daysLeft: days || undefined },\n      ...all,\n    ]);\n    setKeyDialog({ mode: \"reveal\", name, secret: `${keyPrefix}${token}` });\n    flash(kid);\n  };\n\n  const rollKey = (k: DevApiKey) => {\n    const token = randomToken(32);\n    setKeys((all) => all.map((x) => (x.id === k.id ? { ...x, last4: token.slice(-4), lastUsed: undefined } : x)));\n    setKeyDialog({ mode: \"reveal\", name: k.name, secret: `${keyPrefix}${token}` });\n    setKeyDialogOpen(true);\n    flash(k.id);\n  };\n\n  const retry = (eid: string, ids: string[]) => {\n    setBusy((b) => [...b, ...ids]);\n    ids.forEach((did, i) =>\n      later(\n        () => {\n          updateEndpoint(eid, (e) => ({\n            ...e,\n            deliveries: e.deliveries.map((d) =>\n              d.id === did ? { ...d, status: 200, latency: 140 + ((did.charCodeAt(did.length - 1) * 37) % 160), time: \"just now\" } : d,\n            ),\n          }));\n          setBusy((b) => b.filter((x) => x !== did));\n        },\n        900 + i * 240,\n      ),\n    );\n  };\n\n  const sendTest = (eid: string) => {\n    counter.current += 1;\n    const did = `test-${counter.current}`;\n    updateEndpoint(eid, (e) => ({ ...e, deliveries: [{ id: did, event: \"ping\", status: 200, latency: 0, time: \"just now\" }, ...e.deliveries] }));\n    retry(eid, [did]);\n  };\n\n  const fade = reduce ? { duration: 0 } : { duration: 0.22, ease: easeOut };\n  const failed = endpoint ? endpoint.deliveries.filter((d) => !isOk(d.status)) : [];\n  const eventsTarget = eventsDialog?.endpointId ? endpoints.find((e) => e.id === eventsDialog.endpointId) : undefined;\n\n  return (\n    <RidgelineShell active=\"developer\" className={className} onNavigate={onNavigate}>\n      <div className=\"mx-auto w-full max-w-2xl px-6 py-10 md:px-10\">\n        <h1 className=\"font-semibold text-2xl tracking-tight\">API keys & webhooks</h1>\n        <p className=\"mt-1 text-muted-foreground text-sm\">Authenticate scripts against the Ridgeline API, and hear about changes as they happen.</p>\n\n        <section className=\"mt-10\">\n          <SectionHeader\n            action={\n              <Button\n                className={cn(\"shrink-0 self-start sm:self-auto\", press)}\n                onClick={() => {\n                  setKeyDialog({ mode: \"create\" });\n                  setKeyDialogOpen(true);\n                }}\n                size=\"sm\"\n              >\n                <PlusIcon />\n                Create key\n              </Button>\n            }\n            description=\"Send a key as a bearer token, from servers only.\"\n            title=\"API keys\"\n          />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <div className=\"hidden grid-cols-[minmax(0,1fr)_10rem_7.5rem_2rem] items-center gap-3 border-b px-4 py-2.5 font-medium text-muted-foreground text-xs sm:grid\">\n              <span>Name</span>\n              <span>Scopes</span>\n              <span>Expires</span>\n              <span className=\"sr-only\">Actions</span>\n            </div>\n            <ul>\n              <AnimatePresence initial={false}>\n                {keys.map((k) => (\n                  <motion.li\n                    animate={{ opacity: 1, height: \"auto\" }}\n                    className={cn(\"overflow-hidden border-b transition-colors duration-700 last:border-b-0\", fresh === k.id && \"bg-success/6\")}\n                    exit={{ opacity: 0, height: 0 }}\n                    initial={{ opacity: 0, height: 0 }}\n                    key={k.id}\n                    transition={fade}\n                  >\n                    <div className=\"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 px-4 py-3 sm:grid-cols-[minmax(0,1fr)_10rem_7.5rem_2rem]\">\n                      <div className=\"min-w-0\">\n                        <p className=\"truncate font-medium text-sm\">{k.name}</p>\n                        <p className=\"truncate text-muted-foreground text-xs\">\n                          <span className=\"font-mono\">\n                            {keyPrefix}…{k.last4}\n                          </span>\n                          <span aria-hidden> · </span>\n                          {k.lastUsed ? `used ${k.lastUsed}` : \"never used\"}\n                        </p>\n                      </div>\n                      <div className=\"col-span-2 row-start-2 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1.5 text-xs sm:contents sm:text-sm\">\n                        <ScopeChips scopes={k.scopes} />\n                        <span className=\"sm:hidden\">\n                          <span className=\"text-muted-foreground\">Expires </span>\n                          <Expiry apiKey={k} />\n                        </span>\n                        <span className=\"hidden sm:inline\">\n                          <Expiry apiKey={k} />\n                        </span>\n                      </div>\n                      <Menu>\n                        <MenuTrigger\n                          render={\n                            <Button\n                              aria-label={`Actions for ${k.name}`}\n                              className={cn(\"col-start-2 row-start-1 justify-self-end sm:col-start-auto sm:row-start-auto\", press)}\n                              size=\"icon-sm\"\n                              variant=\"ghost\"\n                            />\n                          }\n                        >\n                          <EllipsisIcon />\n                        </MenuTrigger>\n                        <MenuPopup align=\"end\" className=\"w-48\">\n                          <MenuItem onClick={() => rollKey(k)}>\n                            <RefreshCwIcon />\n                            Roll key\n                          </MenuItem>\n                          <MenuSeparator />\n                          <MenuItem\n                            onClick={() => {\n                              setRevoking(k);\n                              setRevokeOpen(true);\n                            }}\n                            variant=\"destructive\"\n                          >\n                            <Trash2Icon />\n                            Revoke key\n                          </MenuItem>\n                        </MenuPopup>\n                      </Menu>\n                    </div>\n                  </motion.li>\n                ))}\n              </AnimatePresence>\n            </ul>\n            {keys.length === 0 && (\n              <div className=\"flex flex-col items-center gap-1 px-4 py-10 text-center\">\n                <p className=\"font-medium text-sm\">No API keys</p>\n                <p className=\"text-muted-foreground text-xs\">Create one for CI, scripts or anything server-side.</p>\n              </div>\n            )}\n          </div>\n        </section>\n\n        <section className=\"mt-10\">\n          <SectionHeader\n            action={\n              <Button\n                className={cn(\"shrink-0 self-start sm:self-auto\", press)}\n                onClick={() => {\n                  counter.current += 1;\n                  setEventsDialog({ key: counter.current });\n                  setEventsOpen(true);\n                }}\n                size=\"sm\"\n                variant=\"outline\"\n              >\n                <PlusIcon />\n                Add endpoint\n              </Button>\n            }\n            description=\"Ridgeline posts signed events to these URLs.\"\n            title=\"Webhooks\"\n          />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <ul>\n              <AnimatePresence initial={false}>\n                {endpoints.map((e) => {\n                  const s = statusOf(e);\n                  const active = e.id === endpoint?.id;\n                  return (\n                    <motion.li\n                      animate={{ opacity: 1, height: \"auto\" }}\n                      className=\"relative overflow-hidden border-b last:border-b-0\"\n                      exit={{ opacity: 0, height: 0 }}\n                      initial={{ opacity: 0, height: 0 }}\n                      key={e.id}\n                      transition={fade}\n                    >\n                      <div className={cn(\"flex items-center gap-3 py-3 ps-4 pe-3 transition-colors duration-150\", active ? \"bg-accent/50\" : \"hover:bg-accent/30\")}>\n                        <button\n                          aria-current={active ? \"true\" : undefined}\n                          className=\"flex min-w-0 flex-1 items-center gap-3 text-left outline-none after:absolute after:inset-0 focus-visible:after:ring-2 focus-visible:after:ring-ring focus-visible:after:ring-inset\"\n                          onClick={() => {\n                            setSelectedId(e.id);\n                            setRevealed(false);\n                          }}\n                          type=\"button\"\n                        >\n                          <span\n                            aria-hidden\n                            className={cn(\n                              \"size-2 shrink-0 rounded-full\",\n                              s === \"active\" && \"bg-success\",\n                              s === \"failing\" && \"bg-destructive\",\n                              s === \"paused\" && \"bg-muted-foreground/40\",\n                            )}\n                          />\n                          <span className=\"flex min-w-0 flex-col\">\n                            <span className=\"truncate font-mono text-[13px]\">{e.url.replace(/^https:\\/\\//, \"\")}</span>\n                            <span className={cn(\"text-xs\", s === \"failing\" ? \"text-destructive-foreground\" : \"text-muted-foreground\")}>\n                              {e.events.length === 1 ? \"1 event\" : `${e.events.length} events`} ·{\" \"}\n                              {s === \"failing\"\n                                ? `${e.deliveries.filter((d) => !isOk(d.status)).length} failing`\n                                : s === \"paused\"\n                                  ? \"Paused\"\n                                  : \"Healthy\"}\n                            </span>\n                          </span>\n                        </button>\n                        <Switch\n                          aria-label={`Send events to ${hostOf(e.url)}`}\n                          checked={!e.paused}\n                          className=\"relative\"\n                          onCheckedChange={(on) => updateEndpoint(e.id, (x) => ({ ...x, paused: !on }))}\n                        />\n                        <Menu>\n                          <MenuTrigger render={<Button aria-label={`Actions for ${hostOf(e.url)}`} className={cn(\"relative\", press)} size=\"icon-sm\" variant=\"ghost\" />}>\n                            <EllipsisIcon />\n                          </MenuTrigger>\n                          <MenuPopup align=\"end\" className=\"w-48\">\n                            <MenuItem\n                              onClick={() => {\n                                counter.current += 1;\n                                setEventsDialog({ endpointId: e.id, key: counter.current });\n                                setEventsOpen(true);\n                              }}\n                            >\n                              <CheckIcon />\n                              Edit events\n                            </MenuItem>\n                            <MenuItem\n                              onClick={() => {\n                                setSelectedId(e.id);\n                                sendTest(e.id);\n                              }}\n                            >\n                              <SendIcon />\n                              Send test event\n                            </MenuItem>\n                            <MenuSeparator />\n                            <MenuItem\n                              onClick={() => {\n                                setDeleting(e);\n                                setDeleteOpen(true);\n                              }}\n                              variant=\"destructive\"\n                            >\n                              <Trash2Icon />\n                              Delete endpoint\n                            </MenuItem>\n                          </MenuPopup>\n                        </Menu>\n                      </div>\n                    </motion.li>\n                  );\n                })}\n              </AnimatePresence>\n            </ul>\n            {endpoints.length === 0 && (\n              <div className=\"flex flex-col items-center gap-1 px-4 py-10 text-center\">\n                <p className=\"font-medium text-sm\">No endpoints</p>\n                <p className=\"text-muted-foreground text-xs\">Add one to hear about deploys, domains and members.</p>\n              </div>\n            )}\n          </div>\n\n          {endpoint && (\n            <>\n              <h3 className=\"mt-6 truncate font-medium text-muted-foreground text-xs\">\n                Settings for <span className=\"font-mono\">{hostOf(endpoint.url)}</span>\n              </h3>\n              <div className=\"mt-2 divide-y rounded-xl border bg-card\">\n                <div className=\"flex flex-col gap-3 px-4 py-3.5 sm:flex-row sm:items-center sm:gap-4\">\n                  <div className=\"min-w-0 flex-1\">\n                    <p className=\"font-medium text-sm\">Signing secret</p>\n                    <p className=\"text-muted-foreground text-xs\">\n                      {rolled === endpoint.id ? \"Rolled just now. The old one works for 24 more hours.\" : \"Verify the ridgeline-signature header with it.\"}\n                    </p>\n                  </div>\n                  <div className=\"flex items-center gap-1.5\">\n                    <div className=\"flex min-w-0 flex-1 items-center rounded-lg border bg-muted/50 py-0.5 ps-2.5 pe-0.5 sm:w-56 sm:flex-none\">\n                      <code className=\"min-w-0 flex-1 truncate font-mono text-xs\">{revealed ? endpoint.secret : `rlsig_test_${\"•\".repeat(10)}`}</code>\n                      <Button\n                        aria-label={revealed ? \"Hide secret\" : \"Reveal secret\"}\n                        aria-pressed={revealed}\n                        className={press}\n                        onClick={() => setRevealed((r) => !r)}\n                        size=\"icon-xs\"\n                        variant=\"ghost\"\n                      >\n                        <SwapIcon offIcon={<EyeIcon />} on={revealed} onIcon={<EyeOffIcon />} />\n                      </Button>\n                      <Button aria-label=\"Copy secret\" className={press} onClick={() => secretCopy.copy(endpoint.secret)} size=\"icon-xs\" variant=\"ghost\">\n                        <SwapIcon offIcon={<CopyIcon />} on={secretCopy.copied} onIcon={<CheckIcon className=\"text-success-foreground\" />} />\n                      </Button>\n                    </div>\n                    <Button\n                      className={press}\n                      onClick={() => {\n                        updateEndpoint(endpoint.id, (x) => ({ ...x, secret: `rlsig_test_${randomToken(24)}` }));\n                        setRolled(endpoint.id);\n                        setRevealed(true);\n                      }}\n                      size=\"sm\"\n                      variant=\"outline\"\n                    >\n                      Roll\n                    </Button>\n                  </div>\n                </div>\n                <div className=\"flex items-center gap-4 px-4 py-3.5\">\n                  <div className=\"min-w-0 flex-1\">\n                    <p className=\"font-medium text-sm\">Events</p>\n                    <p className=\"truncate text-muted-foreground text-xs tabular-nums\">\n                      {endpoint.events.length} of {totalEvents} · {endpoint.events.slice(0, 2).join(\", \")}\n                      {endpoint.events.length > 2 && ` and ${endpoint.events.length - 2} more`}\n                    </p>\n                  </div>\n                  <Button\n                    className={press}\n                    onClick={() => {\n                      counter.current += 1;\n                      setEventsDialog({ endpointId: endpoint.id, key: counter.current });\n                      setEventsOpen(true);\n                    }}\n                    size=\"sm\"\n                    variant=\"outline\"\n                  >\n                    Edit\n                  </Button>\n                </div>\n              </div>\n\n              <div className=\"mt-6 flex items-center justify-between gap-3\">\n                <h3 className=\"font-medium text-muted-foreground text-xs\">Recent deliveries</h3>\n                <div className=\"-me-2 flex items-center gap-1\">\n                  {failed.length > 1 && (\n                    <Button\n                      className={press}\n                      disabled={failed.every((d) => busy.includes(d.id))}\n                      onClick={() => retry(endpoint.id, failed.filter((d) => !busy.includes(d.id)).map((d) => d.id))}\n                      size=\"xs\"\n                      variant=\"ghost\"\n                    >\n                      <RotateCwIcon />\n                      Retry failed\n                    </Button>\n                  )}\n                  <Button className={press} onClick={() => sendTest(endpoint.id)} size=\"xs\" variant=\"ghost\">\n                    <SendIcon />\n                    Send test\n                  </Button>\n                </div>\n              </div>\n              <div className=\"mt-2 overflow-hidden rounded-xl border bg-card\">\n                <div className=\"hidden grid-cols-[minmax(0,1fr)_4.5rem_4.5rem_6rem_4.5rem] items-center gap-3 border-b px-4 py-2.5 font-medium text-muted-foreground text-xs sm:grid\">\n                  <span>Event</span>\n                  <span>Status</span>\n                  <span className=\"text-right\">Latency</span>\n                  <span className=\"text-right\">Time</span>\n                  <span className=\"sr-only\">Actions</span>\n                </div>\n                <ul>\n                  <AnimatePresence initial={false}>\n                    {endpoint.deliveries.map((d) => {\n                      const ok = isOk(d.status);\n                      const isBusy = busy.includes(d.id);\n                      return (\n                        <motion.li\n                          animate={{ opacity: 1, height: \"auto\" }}\n                          className=\"overflow-hidden border-b last:border-b-0\"\n                          exit={{ opacity: 0, height: 0 }}\n                          initial={{ opacity: 0, height: 0 }}\n                          key={d.id}\n                          transition={fade}\n                        >\n                          <div className=\"grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 gap-y-0.5 px-4 py-2.5 sm:grid-cols-[minmax(0,1fr)_4.5rem_4.5rem_6rem_4.5rem]\">\n                            <span className=\"col-start-2 row-start-1 truncate font-mono text-[13px] sm:col-start-auto\">{d.event}</span>\n                            <span className=\"col-start-1 row-span-2 row-start-1 sm:col-start-auto sm:row-span-1 sm:row-start-auto\">\n                              <StatusCode busy={isBusy} reduce={reduce} status={d.status} />\n                            </span>\n                            <span\n                              className={cn(\n                                \"col-start-2 row-start-2 font-mono text-muted-foreground text-xs tabular-nums sm:col-start-auto sm:row-start-auto sm:text-right\",\n                                !isBusy && d.latency >= 1000 && \"text-warning-foreground\",\n                              )}\n                            >\n                              {isBusy ? \"…\" : formatLatency(d.latency)}\n                              <span className=\"font-sans text-muted-foreground sm:hidden\"> · {d.time}</span>\n                            </span>\n                            <span className=\"hidden text-right text-muted-foreground text-sm sm:block\">{d.time}</span>\n                            <span className=\"col-start-3 row-span-2 row-start-1 flex justify-end sm:col-start-auto sm:row-span-1 sm:row-start-auto\">\n                              {!ok && (\n                                <Button className={press} disabled={isBusy} onClick={() => retry(endpoint.id, [d.id])} size=\"xs\" variant=\"outline\">\n                                  <RotateCwIcon />\n                                  Retry\n                                </Button>\n                              )}\n                            </span>\n                          </div>\n                        </motion.li>\n                      );\n                    })}\n                  </AnimatePresence>\n                </ul>\n                {endpoint.deliveries.length === 0 && (\n                  <p className=\"px-4 py-8 text-center text-muted-foreground text-sm\">Nothing sent yet. Send a test event to check it answers.</p>\n                )}\n              </div>\n            </>\n          )}\n        </section>\n      </div>\n\n      <Dialog onOpenChange={setKeyDialogOpen} open={keyDialogOpen}>\n        <DialogPopup className=\"sm:max-w-md\" showCloseButton={keyDialog?.mode === \"create\"}>\n          {keyDialog?.mode === \"reveal\" ? (\n            <SecretReveal key={keyDialog.secret} name={keyDialog.name} onDone={() => setKeyDialogOpen(false)} reduce={reduce} secret={keyDialog.secret} />\n          ) : (\n            <CreateKeyForm onCreate={createKey} resources={resources} today={today} />\n          )}\n        </DialogPopup>\n      </Dialog>\n\n      <Dialog onOpenChange={setEventsOpen} open={eventsOpen}>\n        <DialogPopup className=\"sm:max-w-lg\">\n          {eventsDialog && (\n            <EventsForm\n              groups={eventGroups}\n              initial={eventsTarget?.events ?? [\"deployment.failed\"]}\n              key={eventsDialog.key}\n              onSave={(events, url) => {\n                if (eventsTarget) {\n                  updateEndpoint(eventsTarget.id, (x) => ({ ...x, events }));\n                } else {\n                  counter.current += 1;\n                  const eid = `ep-${counter.current}`;\n                  setEndpoints((all) => [...all, { id: eid, url, events, secret: `rlsig_test_${randomToken(24)}`, deliveries: [] }]);\n                  setSelectedId(eid);\n                  setRevealed(false);\n                }\n                setEventsOpen(false);\n              }}\n              url={eventsTarget?.url}\n            />\n          )}\n        </DialogPopup>\n      </Dialog>\n\n      <AlertDialog onOpenChange={setRevokeOpen} open={revokeOpen}>\n        <AlertDialogPopup>\n          <AlertDialogHeader>\n            <AlertDialogTitle>Revoke {revoking?.name}?</AlertDialogTitle>\n            <AlertDialogDescription>\n              Anything using <span className=\"font-mono text-foreground\">…{revoking?.last4}</span> stops working straight away. This can’t be undone.\n            </AlertDialogDescription>\n          </AlertDialogHeader>\n          <AlertDialogFooter>\n            <AlertDialogClose render={<Button variant=\"ghost\" />}>Cancel</AlertDialogClose>\n            <AlertDialogClose\n              render={<Button onClick={() => revoking && setKeys((all) => all.filter((x) => x.id !== revoking.id))} variant=\"destructive\" />}\n            >\n              Revoke key\n            </AlertDialogClose>\n          </AlertDialogFooter>\n        </AlertDialogPopup>\n      </AlertDialog>\n\n      <AlertDialog onOpenChange={setDeleteOpen} open={deleteOpen}>\n        <AlertDialogPopup>\n          <AlertDialogHeader>\n            <AlertDialogTitle>Delete this endpoint?</AlertDialogTitle>\n            <AlertDialogDescription>\n              <span className=\"break-all font-mono text-foreground\">{deleting?.url}</span> stops receiving events, and its delivery history goes with it.\n            </AlertDialogDescription>\n          </AlertDialogHeader>\n          <AlertDialogFooter>\n            <AlertDialogClose render={<Button variant=\"ghost\" />}>Cancel</AlertDialogClose>\n            <AlertDialogClose\n              render={\n                <Button\n                  onClick={() => {\n                    if (!deleting) return;\n                    const next = endpoints.find((x) => x.id !== deleting.id);\n                    setEndpoints((all) => all.filter((x) => x.id !== deleting.id));\n                    if (selectedId === deleting.id && next) setSelectedId(next.id);\n                  }}\n                  variant=\"destructive\"\n                />\n              }\n            >\n              Delete endpoint\n            </AlertDialogClose>\n          </AlertDialogFooter>\n        </AlertDialogPopup>\n      </AlertDialog>\n    </RidgelineShell>\n  );\n}\n"
    }
  ]
}