{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "request-access",
  "type": "registry:block",
  "title": "Request Access",
  "description": "The page you hit when a doc is private: who you are signed in as, a switch-account menu, an optional note and a Request access button. It then shows who the request went to, when, and a resend that unlocks after a countdown.",
  "categories": [
    "block",
    "Empty & Error"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/button.json",
    "https://coss.com/ui/r/label.json",
    "https://coss.com/ui/r/menu.json",
    "https://coss.com/ui/r/textarea.json"
  ],
  "files": [
    {
      "path": "registry/devl/request-access.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport { CheckIcon, ChevronDownIcon, ChevronRightIcon, ClockIcon, FileTextIcon, LockIcon, LogInIcon } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type ReactNode, useEffect, useId, useState } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport { Label } from \"@/components/ui/label\";\nimport { Menu, MenuGroup, MenuGroupLabel, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from \"@/components/ui/menu\";\nimport { Textarea } from \"@/components/ui/textarea\";\nimport { cn } from \"@/lib/utils\";\n\nexport type AccessStatus = \"denied\" | \"pending\" | \"granted\";\n\nexport interface AccessPerson {\n  name: string;\n  email: string;\n  initials: string;\n}\n\nexport interface RequestAccessProps {\n  workspace?: string;\n  space?: string;\n  doc?: string;\n  owner?: AccessPerson;\n  user?: AccessPerson;\n  otherAccounts?: string[];\n  resendAfter?: number;\n  status?: AccessStatus;\n  defaultStatus?: AccessStatus;\n  onStatusChange?: (status: AccessStatus) => void;\n  onRequest?: (note: string) => void;\n  onResend?: () => void;\n  onCancel?: () => void;\n  onSwitchAccount?: (email: string | null) => void;\n  children?: ReactNode;\n  className?: string;\n}\n\nconst ease = [0.23, 1, 0.32, 1] as const;\n\nfunction Mark() {\n  return (\n    <span className=\"flex size-6 shrink-0 items-center justify-center rounded-md bg-primary text-primary-foreground\">\n      <svg aria-hidden className=\"size-4\" fill=\"none\" viewBox=\"0 0 28 28\">\n        <path d=\"M7 18.5 12 12l3.5 4.5 2-2.5 3.5 4.5\" stroke=\"currentColor\" strokeLinecap=\"round\" strokeLinejoin=\"round\" strokeWidth=\"2.6\" />\n      </svg>\n    </span>\n  );\n}\n\nfunction Initials({ person, className }: { person: AccessPerson; className?: string }) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"flex size-8 shrink-0 items-center justify-center rounded-full bg-violet-500/15 font-medium text-violet-700 text-xs dark:text-violet-300\",\n        className,\n      )}\n    >\n      {person.initials}\n    </span>\n  );\n}\n\nfunction RollingDigit({ digit }: { digit: string }) {\n  const reduce = useReducedMotion();\n  return (\n    <span className=\"relative inline-flex h-[1lh] w-[1ch] justify-center overflow-hidden\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ y: 0, opacity: 1 }}\n          exit={reduce ? { opacity: 0 } : { y: \"70%\", opacity: 0 }}\n          initial={reduce ? { opacity: 0 } : { y: \"-70%\", opacity: 0 }}\n          key={digit}\n          transition={{ duration: 0.28, ease }}\n        >\n          {digit}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction Countdown({ seconds }: { seconds: number }) {\n  const text = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, \"0\")}`;\n  return (\n    <span aria-hidden className=\"inline-flex tabular-nums\">\n      {text.split(\"\").map((c, i) => (c === \":\" ? <span key=\"colon\">:</span> : <RollingDigit digit={c} key={`d${i}`} />))}\n    </span>\n  );\n}\n\nfunction DrawnCheck() {\n  const reduce = useReducedMotion();\n  return (\n    <svg aria-hidden className=\"size-5\" fill=\"none\" viewBox=\"0 0 24 24\">\n      <motion.circle\n        animate={{ pathLength: 1 }}\n        className=\"stroke-success\"\n        cx=\"12\"\n        cy=\"12\"\n        initial={{ pathLength: reduce ? 1 : 0 }}\n        r=\"9\"\n        strokeLinecap=\"round\"\n        strokeWidth=\"2\"\n        transform=\"rotate(-90 12 12)\"\n        transition={{ duration: 0.4, ease }}\n      />\n      <motion.path\n        animate={{ pathLength: 1 }}\n        className=\"stroke-success\"\n        d=\"m8 12.4 2.7 2.6L16 9.6\"\n        initial={{ pathLength: reduce ? 1 : 0 }}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth=\"2\"\n        transition={{ duration: 0.3, delay: reduce ? 0 : 0.32, ease }}\n      />\n    </svg>\n  );\n}\n\nfunction ago(ms: number) {\n  const s = Math.floor(ms / 1000);\n  if (s < 45) return \"just now\";\n  const m = Math.round(s / 60);\n  return m === 1 ? \"1 min ago\" : `${m} min ago`;\n}\n\nexport function RequestAccess({\n  workspace = \"Ridgeline\",\n  space = \"Strategy\",\n  doc = \"Q3 roadmap\",\n  owner = { name: \"Mara Okafor\", email: \"mara@ridgeline.app\", initials: \"MO\" },\n  user = { name: \"Ada Lindqvist\", email: \"ada@ridgeline.app\", initials: \"AL\" },\n  otherAccounts = [],\n  resendAfter = 60,\n  status: statusProp,\n  defaultStatus = \"denied\",\n  onStatusChange,\n  onRequest,\n  onResend,\n  onCancel,\n  onSwitchAccount,\n  children,\n  className,\n}: RequestAccessProps) {\n  const reduce = useReducedMotion();\n  const uid = useId();\n  const [inner, setInner] = useState<AccessStatus>(defaultStatus);\n  const status = statusProp ?? inner;\n  const [email, setEmail] = useState(user.email);\n  const [note, setNote] = useState(\"\");\n  const [sending, setSending] = useState(false);\n  const [sentAt, setSentAt] = useState<number | null>(null);\n  const [now, setNow] = useState(0);\n  const ownerFirst = owner.name.split(\" \")[0];\n\n  const setStatus = (next: AccessStatus) => {\n    setInner(next);\n    onStatusChange?.(next);\n  };\n\n  useEffect(() => {\n    if (status !== \"pending\") return;\n    setNow(Date.now());\n    const t = setInterval(() => setNow(Date.now()), 1000);\n    return () => clearInterval(t);\n  }, [status]);\n\n  useEffect(() => {\n    if (!sending) return;\n    const t = setTimeout(() => {\n      setSending(false);\n      setSentAt(Date.now());\n      setStatus(\"pending\");\n    }, 700);\n    return () => clearTimeout(t);\n  }, [sending]);\n\n  const request = () => {\n    setSending(true);\n    onRequest?.(note.trim());\n  };\n\n  const resend = () => {\n    setSentAt(Date.now());\n    setNow(Date.now());\n    onResend?.();\n  };\n\n  const cancel = () => {\n    setSentAt(null);\n    setStatus(\"denied\");\n    onCancel?.();\n  };\n\n  const switchTo = (next: string | null) => {\n    if (next) setEmail(next);\n    onSwitchAccount?.(next);\n  };\n\n  const elapsed = sentAt && now ? Math.max(0, now - sentAt) : 0;\n  const wait = sentAt ? Math.max(0, resendAfter - Math.floor(elapsed / 1000)) : resendAfter;\n  const sentTime = sentAt ? new Intl.DateTimeFormat(undefined, { hour: \"numeric\", minute: \"2-digit\" }).format(sentAt) : \"\";\n  const swap = reduce ? { opacity: 0 } : { opacity: 0, y: 8, filter: \"blur(4px)\" };\n\n  return (\n    <div className={cn(\"flex h-160 w-full max-w-275 flex-col overflow-hidden rounded-2xl border bg-card text-foreground shadow-xs/5\", className)}>\n      <header className=\"flex h-12 shrink-0 items-center gap-2 border-b px-3 sm:px-4\">\n        <Mark />\n        <nav aria-label=\"Breadcrumb\" className=\"flex min-w-0 items-center gap-1 text-sm\">\n          <span className=\"hidden font-medium sm:inline\">{workspace}</span>\n          <ChevronRightIcon aria-hidden className=\"hidden size-3.5 text-muted-foreground sm:block\" />\n          <span className=\"truncate text-muted-foreground\">{space}</span>\n          <ChevronRightIcon aria-hidden className=\"size-3.5 shrink-0 text-muted-foreground\" />\n          <span className=\"flex min-w-0 items-center gap-1.5 font-medium\" aria-current=\"page\">\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.span\n                animate={{ opacity: 1, scale: 1 }}\n                className=\"flex\"\n                exit={{ opacity: 0, scale: reduce ? 1 : 0.8 }}\n                initial={{ opacity: 0, scale: reduce ? 1 : 0.8 }}\n                key={status === \"granted\" ? \"open\" : \"locked\"}\n                transition={{ duration: 0.2, ease }}\n              >\n                {status === \"granted\" ? (\n                  <FileTextIcon aria-hidden className=\"size-3.5 text-muted-foreground\" />\n                ) : (\n                  <LockIcon aria-hidden className=\"size-3.5 text-muted-foreground\" />\n                )}\n              </motion.span>\n            </AnimatePresence>\n            <span className=\"truncate\">{doc}</span>\n          </span>\n        </nav>\n        <div className=\"ms-auto flex items-center gap-2\">\n          <Initials className=\"size-7 text-[0.625rem]\" person={user} />\n        </div>\n      </header>\n\n      <div className=\"relative grid min-h-0 flex-1 overflow-y-auto bg-background\">\n        <AnimatePresence initial={false} mode=\"wait\">\n          {status === \"granted\" ? (\n            <motion.div\n              animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n              className=\"col-start-1 row-start-1 mx-auto w-full max-w-170 px-5 py-8 sm:px-8\"\n              exit={{ opacity: 0 }}\n              initial={swap}\n              key=\"granted\"\n              transition={{ duration: 0.3, ease }}\n            >\n              <motion.div\n                animate={{ opacity: 1, y: 0 }}\n                className=\"mb-8 flex items-center gap-2.5 rounded-xl border bg-card px-3 py-2.5 text-sm shadow-xs/5\"\n                initial={{ opacity: 0, y: reduce ? 0 : -6 }}\n                role=\"status\"\n                transition={{ duration: 0.3, delay: 0.15, ease }}\n              >\n                <span className=\"flex size-6 shrink-0 items-center justify-center rounded-full bg-success/12 text-success-foreground\">\n                  <CheckIcon aria-hidden className=\"size-3.5\" />\n                </span>\n                <span className=\"min-w-0 flex-1 text-pretty\">\n                  <span className=\"font-medium\">{ownerFirst} gave you access.</span>{\" \"}\n                  <span className=\"text-muted-foreground\">You can view and comment on this doc.</span>\n                </span>\n              </motion.div>\n              {children}\n            </motion.div>\n          ) : (\n            <motion.div\n              animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n              className=\"col-start-1 row-start-1 flex flex-col items-center justify-center px-4 py-10 text-center sm:px-6\"\n              exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.98, filter: \"blur(4px)\" }}\n              initial={swap}\n              key=\"gate\"\n              transition={{ duration: 0.25, ease }}\n            >\n              <AnimatePresence initial={false} mode=\"wait\">\n                {status === \"denied\" ? (\n                  <motion.div\n                    animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                    className=\"flex w-full max-w-96 flex-col items-center\"\n                    exit={swap}\n                    initial={swap}\n                    key=\"denied\"\n                    transition={{ duration: 0.2, ease }}\n                  >\n                    <div className=\"flex size-10 items-center justify-center rounded-xl border bg-card shadow-xs/5\">\n                      <LockIcon aria-hidden className=\"size-5\" />\n                    </div>\n                    <h2 className=\"mt-4 text-balance font-semibold text-xl\">You don&rsquo;t have access to {doc}</h2>\n                    <p className=\"mt-1.5 max-w-88 text-pretty text-muted-foreground text-sm\">\n                      This doc is private to the {space} team. Ask {ownerFirst} for access and you&rsquo;ll get an email when they reply.\n                    </p>\n\n                    <div className=\"mt-6 flex w-full items-center gap-3 rounded-xl border bg-card p-2 ps-3 text-left shadow-xs/5\">\n                      <Initials person={{ ...user, email }} />\n                      <span className=\"flex min-w-0 flex-1 flex-col\">\n                        <span className=\"text-muted-foreground text-xs\">You&rsquo;re signed in as</span>\n                        <span className=\"truncate font-medium text-sm\">{email}</span>\n                      </span>\n                      <Menu>\n                        <MenuTrigger render={<Button className=\"shrink-0\" size=\"sm\" variant=\"ghost\" />}>\n                          <span className=\"max-sm:hidden\">Switch account</span>\n                          <span className=\"sm:hidden\">Switch</span>\n                          <ChevronDownIcon aria-hidden className=\"opacity-60\" />\n                        </MenuTrigger>\n                        <MenuPopup align=\"end\" className=\"min-w-60\">\n                          <MenuGroup>\n                            <MenuGroupLabel>Accounts</MenuGroupLabel>\n                            {[user.email, ...otherAccounts].map((a) => (\n                              <MenuItem key={a} onClick={() => switchTo(a)}>\n                                <span className=\"min-w-0 flex-1 truncate\">{a}</span>\n                                {a === email && <CheckIcon aria-label=\"Current account\" />}\n                              </MenuItem>\n                            ))}\n                          </MenuGroup>\n                          <MenuSeparator />\n                          <MenuItem onClick={() => switchTo(null)}>\n                            <LogInIcon />\n                            Sign in with another account\n                          </MenuItem>\n                        </MenuPopup>\n                      </Menu>\n                    </div>\n\n                    <div className=\"mt-4 flex w-full flex-col gap-2 text-left\">\n                      <Label className=\"gap-1\" htmlFor={`${uid}-note`}>\n                        Add a note <span className=\"font-normal text-muted-foreground\">(optional)</span>\n                      </Label>\n                      <Textarea\n                        className=\"text-sm\"\n                        disabled={sending}\n                        id={`${uid}-note`}\n                        maxLength={280}\n                        onChange={(e) => setNote(e.currentTarget.value)}\n                        placeholder={`Tell ${ownerFirst} why you need it`}\n                        size=\"sm\"\n                        value={note}\n                      />\n                    </div>\n                    <Button className=\"mt-4 w-full active:scale-[0.98]\" loading={sending} onClick={request}>\n                      Request access\n                    </Button>\n                    <p className=\"mt-3 flex items-center gap-1.5 text-muted-foreground text-xs\">\n                      <Initials className=\"size-4 bg-amber-500/15 text-[0.4375rem] text-amber-800 dark:text-amber-300\" person={owner} />\n                      {owner.name} owns this doc\n                    </p>\n                  </motion.div>\n                ) : (\n                  <motion.div\n                    animate={{ opacity: 1, y: 0, filter: \"blur(0px)\" }}\n                    className=\"flex w-full max-w-96 flex-col items-center\"\n                    exit={swap}\n                    initial={swap}\n                    key=\"pending\"\n                    transition={{ duration: 0.2, ease }}\n                  >\n                    <div className=\"flex size-10 items-center justify-center rounded-xl border bg-card shadow-xs/5\">\n                      <DrawnCheck />\n                    </div>\n                    <h2 className=\"mt-4 text-balance font-semibold text-xl\" role=\"status\">\n                      Request sent to {ownerFirst} <span className=\"font-normal text-muted-foreground\">(owner)</span>\n                    </h2>\n                    <p className=\"mt-1.5 max-w-88 text-pretty text-muted-foreground text-sm\">\n                      We&rsquo;ll email {email} when {ownerFirst} responds. Most requests are answered within a day.\n                    </p>\n                    <p className=\"mt-3 flex items-center gap-1.5 text-muted-foreground text-xs tabular-nums\">\n                      <ClockIcon aria-hidden className=\"size-3.5\" />\n                      Sent {sentTime ? `at ${sentTime} · ${ago(elapsed)}` : \"just now\"}\n                    </p>\n\n                    {note.trim() && (\n                      <figure className=\"mt-6 w-full rounded-xl border bg-card p-3 text-left shadow-xs/5\">\n                        <figcaption className=\"flex items-center gap-2 text-muted-foreground text-xs\">\n                          <Initials className=\"size-5 text-[0.5625rem]\" person={user} />\n                          Your note\n                        </figcaption>\n                        <blockquote className=\"mt-2 whitespace-pre-line text-pretty text-sm\">{note.trim()}</blockquote>\n                      </figure>\n                    )}\n\n                    <div className=\"mt-6 flex flex-wrap items-center justify-center gap-2\">\n                      <Button className=\"min-w-40 active:scale-[0.97]\" disabled={wait > 0} onClick={resend} variant=\"outline\">\n                        {wait > 0 ? (\n                          <>\n                            <span className=\"inline-flex gap-1\">\n                              Resend in\n                              <Countdown seconds={wait} />\n                            </span>\n                            <span className=\"sr-only\">{wait} seconds</span>\n                          </>\n                        ) : (\n                          \"Resend request\"\n                        )}\n                      </Button>\n                      <Button className=\"active:scale-[0.97]\" onClick={cancel} variant=\"ghost\">\n                        Cancel request\n                      </Button>\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}