{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "login",
  "title": "Login",
  "description": "Mac OS 9 Multiple Users welcome window with a keyboard-navigable user list, password field and default Log In button.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-button.json",
    "https://nostalgia-ui.com/r/retro-icons.json",
    "https://nostalgia-ui.com/r/retro-input.json",
    "https://nostalgia-ui.com/r/retro-label.json",
    "https://nostalgia-ui.com/r/retro-window.json"
  ],
  "files": [
    {
      "path": "registry/new-york/blocks/login.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { RetroButton } from \"@/registry/new-york/ui/retro-button\"\nimport { RetroIconFinder, RetroIconUser } from \"@/registry/new-york/ui/retro-icons\"\nimport { RetroInput } from \"@/registry/new-york/ui/retro-input\"\nimport { RetroLabel } from \"@/registry/new-york/ui/retro-label\"\nimport { RetroWindow } from \"@/registry/new-york/ui/retro-window\"\n\n/* ------------------------------------------------------------------ */\n/*  Types                                                              */\n/* ------------------------------------------------------------------ */\n\ninterface LoginUser {\n  id: string\n  name: string\n  /** Custom 32px icon. Defaults to the RetroIconUser portrait. */\n  icon?: React.ReactNode\n  /** Set to false for accounts without a password (e.g. Guest). Defaults to true. */\n  requiresPassword?: boolean\n}\n\n/**\n * Return `false` (or a Promise resolving to `false`) to reject the password;\n * the block then shows an error and clears the field.\n */\ntype LoginHandler = (\n  user: LoginUser,\n  password: string\n) => void | boolean | Promise<void | boolean>\n\ninterface LoginBlockProps\n  extends Omit<React.ComponentPropsWithoutRef<typeof RetroWindow>, \"children\" | \"title\" | \"onSubmit\"> {\n  users: LoginUser[]\n  onLogin?: LoginHandler\n  /** Shown in the welcome line. Defaults to \"Macintosh\". */\n  computerName?: string\n  /** Window title. Defaults to \"Welcome\". */\n  title?: string\n  /** Initially selected user id. */\n  defaultUserId?: string\n  /** Error message shown when onLogin returns false. */\n  errorMessage?: string\n}\n\n/* ------------------------------------------------------------------ */\n/*  LoginBlock                                                         */\n/* ------------------------------------------------------------------ */\n\nconst LoginBlock = React.forwardRef<HTMLDivElement, LoginBlockProps>(\n  function LoginBlock(\n    {\n      users,\n      onLogin,\n      computerName = \"Macintosh\",\n      title = \"Welcome\",\n      defaultUserId,\n      errorMessage = \"The password you entered is incorrect. Please try again.\",\n      className,\n      ...props\n    },\n    ref\n  ) {\n    const baseId = React.useId()\n    const listRef = React.useRef<HTMLUListElement>(null)\n    const passwordRef = React.useRef<HTMLInputElement>(null)\n\n    const [selectedId, setSelectedId] = React.useState<string | undefined>(\n      defaultUserId\n    )\n    const [password, setPassword] = React.useState(\"\")\n    const [error, setError] = React.useState(false)\n    const [pending, setPending] = React.useState(false)\n\n    const selectedIndex = users.findIndex((u) => u.id === selectedId)\n    const selected = selectedIndex >= 0 ? users[selectedIndex] : undefined\n    const needsPassword = selected ? selected.requiresPassword !== false : false\n    const optionId = (id: string) => `${baseId}-user-${id}`\n\n    const select = (user: LoginUser | undefined) => {\n      if (!user || user.id === selectedId) return\n      setSelectedId(user.id)\n      setPassword(\"\")\n      setError(false)\n    }\n\n    // Keep the active option scrolled into view (only the list, never the page)\n    React.useEffect(() => {\n      const list = listRef.current\n      if (!list || !selectedId) return\n      const el = list.querySelector<HTMLElement>(\n        `[data-user-id=\"${CSS.escape(selectedId)}\"]`\n      )\n      if (!el) return\n      if (el.offsetTop < list.scrollTop) list.scrollTop = el.offsetTop\n      else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight)\n        list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight\n    }, [selectedId])\n\n    const handleListKeyDown = (e: React.KeyboardEvent<HTMLUListElement>) => {\n      if (users.length === 0) return\n      let next: number | undefined\n      switch (e.key) {\n        case \"ArrowDown\":\n          next = selectedIndex < 0 ? 0 : Math.min(users.length - 1, selectedIndex + 1)\n          break\n        case \"ArrowUp\":\n          next = selectedIndex < 0 ? users.length - 1 : Math.max(0, selectedIndex - 1)\n          break\n        case \"Home\":\n          next = 0\n          break\n        case \"End\":\n          next = users.length - 1\n          break\n        case \"Enter\":\n          if (selected) {\n            e.preventDefault()\n            if (needsPassword) passwordRef.current?.focus()\n            else void submit()\n          }\n          return\n        default:\n          // Type-ahead: jump to the next user starting with the typed letter\n          if (e.key.length === 1 && /\\S/.test(e.key) && !e.metaKey && !e.ctrlKey) {\n            const letter = e.key.toLowerCase()\n            const start = selectedIndex + 1\n            for (let i = 0; i < users.length; i++) {\n              const idx = (start + i) % users.length\n              if (users[idx].name.toLowerCase().startsWith(letter)) {\n                next = idx\n                break\n              }\n            }\n          }\n      }\n      if (next !== undefined) {\n        e.preventDefault()\n        select(users[next])\n      }\n    }\n\n    async function submit() {\n      if (!selected || pending) return\n      setPending(true)\n      try {\n        const result = await onLogin?.(selected, needsPassword ? password : \"\")\n        if (result === false) {\n          setError(true)\n          setPassword(\"\")\n          passwordRef.current?.focus()\n        }\n      } finally {\n        setPending(false)\n      }\n    }\n\n    return (\n      <RetroWindow\n        ref={ref}\n        title={title}\n        className={cn(\"w-full max-w-[400px]\", className)}\n        {...props}\n      >\n        <form\n          className=\"flex flex-col gap-3 p-1\"\n          onSubmit={(e) => {\n            e.preventDefault()\n            void submit()\n          }}\n        >\n          {/* Header */}\n          <div className=\"flex items-center gap-3\">\n            <RetroIconFinder size=\"lg\" className=\"shrink-0\" />\n            <div className=\"min-w-0\">\n              <p className=\"os9-heading text-[12px] text-os9-black\">\n                Welcome to {computerName}\n              </p>\n              <p\n                id={`${baseId}-hint`}\n                className=\"mt-1 font-[family-name:var(--os9-font-sans)] text-[10px] leading-[1.4] text-os9-gray-800\"\n              >\n                Select your name from the list, then click Log In.\n              </p>\n            </div>\n          </div>\n\n          {/* User list */}\n          <ul\n            ref={listRef}\n            role=\"listbox\"\n            tabIndex={0}\n            aria-label=\"Users\"\n            aria-describedby={`${baseId}-hint`}\n            aria-activedescendant={selected ? optionId(selected.id) : undefined}\n            onKeyDown={handleListKeyDown}\n            className=\"os9-inset relative max-h-[204px] overflow-y-auto p-[2px] outline-none focus-visible:os9-focus-ring\"\n          >\n            {users.map((user) => {\n              const isSelected = user.id === selectedId\n              return (\n                <li\n                  key={user.id}\n                  id={optionId(user.id)}\n                  data-user-id={user.id}\n                  role=\"option\"\n                  aria-selected={isSelected}\n                  onClick={() => {\n                    select(user)\n                    listRef.current?.focus()\n                  }}\n                  onDoubleClick={() => {\n                    if (user.requiresPassword === false) void submit()\n                    else passwordRef.current?.focus()\n                  }}\n                  className={cn(\n                    \"flex h-[40px] cursor-default select-none items-center gap-2 px-2\",\n                    \"font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px]\",\n                    isSelected\n                      ? \"bg-os9-azul text-os9-white\"\n                      : \"text-os9-black hover:bg-os9-lavender\"\n                  )}\n                >\n                  <span className=\"flex size-8 shrink-0 items-center justify-center\">\n                    {user.icon ?? <RetroIconUser />}\n                  </span>\n                  <span className=\"truncate\">{user.name}</span>\n                </li>\n              )\n            })}\n          </ul>\n\n          {/* Password */}\n          {selected && needsPassword && (\n            <div className=\"flex flex-col gap-1\">\n              <RetroLabel htmlFor={`${baseId}-password`}>\n                Password for {selected.name}:\n              </RetroLabel>\n              <RetroInput\n                ref={passwordRef}\n                id={`${baseId}-password`}\n                type=\"password\"\n                autoComplete=\"current-password\"\n                value={password}\n                aria-invalid={error || undefined}\n                aria-describedby={error ? `${baseId}-error` : undefined}\n                onChange={(e) => {\n                  setPassword(e.target.value)\n                  if (error) setError(false)\n                }}\n              />\n              {error && (\n                <p\n                  id={`${baseId}-error`}\n                  role=\"alert\"\n                  className=\"font-[family-name:var(--os9-font-sans)] text-[10px] font-bold text-os9-black\"\n                >\n                  {errorMessage}\n                </p>\n              )}\n            </div>\n          )}\n\n          {/* Actions */}\n          <div className=\"flex justify-end\">\n            <RetroButton\n              type=\"submit\"\n              isDefault\n              disabled={!selected || pending}\n              className=\"min-w-[80px]\"\n            >\n              {pending ? \"Logging In…\" : \"Log In\"}\n            </RetroButton>\n          </div>\n        </form>\n      </RetroWindow>\n    )\n  }\n)\nLoginBlock.displayName = \"LoginBlock\"\n\nexport { LoginBlock }\nexport type { LoginBlockProps, LoginUser, LoginHandler }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}