{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "installer",
  "title": "Installer",
  "description": "Mac OS 9 multi-step installer wizard: Welcome, Read Me, license with Agree / Disagree alert, destination disk, install progress and finish.",
  "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-list-box.json",
    "https://nostalgia-ui.com/r/retro-progress.json",
    "https://nostalgia-ui.com/r/retro-window.json"
  ],
  "files": [
    {
      "path": "registry/new-york/blocks/installer.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 {\n  RetroIconAlert,\n  RetroIconHappyMac,\n  RetroIconHardDrive,\n} from \"@/registry/new-york/ui/retro-icons\"\nimport { RetroListBox, RetroListBoxItem } from \"@/registry/new-york/ui/retro-list-box\"\nimport { RetroProgress } from \"@/registry/new-york/ui/retro-progress\"\nimport { RetroWindow } from \"@/registry/new-york/ui/retro-window\"\n\n/* ------------------------------------------------------------------ */\n/*  Types                                                              */\n/* ------------------------------------------------------------------ */\n\ntype InstallerStep = \"welcome\" | \"readme\" | \"license\" | \"destination\" | \"install\" | \"done\"\n\ninterface InstallerDisk {\n  id: string\n  name: string\n  /** Free space in MB. */\n  availableMB: number\n  /** Capacity in MB (shown as info only). */\n  capacityMB?: number\n}\n\ntype InstallerFinishAction = \"quit\" | \"restart\"\n\ninterface InstallerBlockProps\n  extends Omit<React.ComponentPropsWithoutRef<typeof RetroWindow>, \"title\" | \"children\"> {\n  /** Product being installed. Defaults to \"Mac OS 9.2.2\". */\n  productName?: string\n  /** Quit or Restart on the final screen. */\n  onFinish?: (action: InstallerFinishAction) => void\n  /** Called with the chosen disk when installation starts. */\n  onInstall?: (disk: InstallerDisk) => void\n  /** Called when the license is declined. */\n  onDisagree?: () => void\n  /** Destination disks. Defaults to two sample volumes. */\n  disks?: InstallerDisk[]\n  /** Space the install needs, in MB. Defaults to 350. */\n  requiredMB?: number\n  /** Override the welcome text. */\n  welcome?: React.ReactNode\n  /** Override the Read Me text. */\n  readMe?: React.ReactNode\n  /** Override the license text. */\n  license?: React.ReactNode\n  /** Simulated install length in ms. Defaults to 6000. */\n  installDuration?: number\n  /** Initial step (handy for docs and tests). Defaults to \"welcome\". */\n  defaultStep?: InstallerStep\n  /** Window title. Defaults to \"Install <productName>\". */\n  title?: string\n}\n\n/* ------------------------------------------------------------------ */\n/*  Defaults                                                           */\n/* ------------------------------------------------------------------ */\n\nconst STEPS: { id: InstallerStep; label: string }[] = [\n  { id: \"welcome\", label: \"Welcome\" },\n  { id: \"readme\", label: \"Important Information\" },\n  { id: \"license\", label: \"Software License\" },\n  { id: \"destination\", label: \"Select Destination\" },\n  { id: \"install\", label: \"Install Software\" },\n  { id: \"done\", label: \"Finish Up\" },\n]\n\nconst DEFAULT_DISKS: InstallerDisk[] = [\n  { id: \"hd\", name: \"Macintosh HD\", availableMB: 1228, capacityMB: 6144 },\n  { id: \"scratch\", name: \"Scratch\", availableMB: 212, capacityMB: 2048 },\n]\n\nconst INSTALL_PHASES = [\n  \"Preparing to install…\",\n  \"System software\",\n  \"Extensions\",\n  \"Control Panels\",\n  \"Fonts\",\n  \"Apple Menu Items\",\n  \"Updating disk driver\",\n  \"Cleaning up…\",\n]\n\nconst TEXT = \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-[1.5] text-os9-black\"\n\nfunction formatMB(mb: number) {\n  return mb >= 1024 ? `${(mb / 1024).toFixed(1).replace(/\\.0$/, \"\")} GB` : `${mb} MB`\n}\n\nfunction defaultReadMe(product: string) {\n  return (\n    <>\n      <p className=\"font-bold\">Before You Install {product}</p>\n      <p className=\"mt-2\">\n        Back up any important files before you install. The Installer updates\n        your System Folder in place and keeps your documents, preferences and\n        third-party extensions.\n      </p>\n      <p className=\"mt-2 font-bold\">System Requirements</p>\n      <ul className=\"mt-1 list-disc pl-4\">\n        <li>A PowerPC processor</li>\n        <li>At least 64 MB of physical RAM, with virtual memory set to 40 MB</li>\n        <li>About 350 MB of free disk space</li>\n      </ul>\n      <p className=\"mt-2 font-bold\">Known Issues</p>\n      <p className=\"mt-1\">\n        Some older extensions may not load. If your computer freezes at\n        startup, hold down the Shift key to start up with extensions off,\n        then remove the extension in question from the Extensions folder.\n      </p>\n      <p className=\"mt-2\">\n        For late-breaking news, see the &ldquo;About {product}&rdquo; document\n        that is installed on your hard disk.\n      </p>\n    </>\n  )\n}\n\nfunction defaultLicense(product: string) {\n  return (\n    <>\n      <p className=\"font-bold\">SOFTWARE LICENSE AGREEMENT FOR {product.toUpperCase()}</p>\n      <p className=\"mt-2\">\n        PLEASE READ THIS SOFTWARE LICENSE AGREEMENT (&ldquo;LICENSE&rdquo;)\n        CAREFULLY BEFORE USING THE SOFTWARE. BY USING THE SOFTWARE, YOU ARE\n        AGREEING TO BE BOUND BY THE TERMS OF THIS LICENSE. IF YOU DO NOT AGREE\n        TO THE TERMS OF THIS LICENSE, CLICK &ldquo;DISAGREE&rdquo;.\n      </p>\n      <p className=\"mt-2\">\n        1. General. The software and documentation accompanying this License,\n        whether on disk, in read only memory, on any other media or in any\n        other form, are licensed, not sold, to you for use only under the\n        terms of this License.\n      </p>\n      <p className=\"mt-2\">\n        2. Permitted Uses and Restrictions. This License allows you to install\n        and use one copy of the software on a single computer at a time. You\n        may make one copy of the software in machine-readable form for backup\n        purposes only.\n      </p>\n      <p className=\"mt-2\">\n        3. Termination. This License is effective until terminated. Your\n        rights under this License will terminate automatically without notice\n        if you fail to comply with any term of this License.\n      </p>\n      <p className=\"mt-2\">\n        4. Limited Warranty on Media. The media on which the software is\n        recorded is warranted to be free from defects in materials and\n        workmanship under normal use for a period of ninety (90) days from\n        the date of original retail purchase.\n      </p>\n      <p className=\"mt-2\">\n        5. Disclaimer of Warranties. The software is provided &ldquo;AS\n        IS&rdquo; and without warranty of any kind, express or implied.\n      </p>\n    </>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  Step indicator                                                     */\n/* ------------------------------------------------------------------ */\n\nfunction StepList({ current }: { current: number }) {\n  return (\n    <ol\n      aria-label=\"Installation steps\"\n      className=\"flex w-[150px] shrink-0 flex-col gap-[6px] border-r border-os9-gray-600 py-[4px] pr-[10px] shadow-[1px_0_0_var(--os9-white)] @max-[520px]:hidden\"\n    >\n      {STEPS.map((s, i) => {\n        const state = i < current ? \"done\" : i === current ? \"current\" : \"todo\"\n        return (\n          <li\n            key={s.id}\n            aria-current={state === \"current\" ? \"step\" : undefined}\n            className={cn(\n              \"flex items-center gap-[6px] font-[family-name:var(--os9-font-sans)] text-[10px] leading-[1.3]\",\n              state === \"current\" && \"font-bold text-os9-black\",\n              state === \"done\" && \"text-os9-black\",\n              state === \"todo\" && \"text-os9-gray-700\"\n            )}\n          >\n            <span aria-hidden=\"true\" className=\"flex size-[10px] shrink-0 items-center justify-center\">\n              {state === \"current\" ? (\n                <svg width=\"6\" height=\"9\" viewBox=\"0 0 6 9\">\n                  <path d=\"M0 0L6 4.5L0 9Z\" fill=\"var(--os9-black)\" />\n                </svg>\n              ) : (\n                <span\n                  className={cn(\n                    \"block size-[6px] border\",\n                    state === \"done\" ? \"border-os9-black bg-os9-black\" : \"border-os9-gray-700\"\n                  )}\n                />\n              )}\n            </span>\n            {s.label}\n          </li>\n        )\n      })}\n    </ol>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  InstallerBlock                                                     */\n/* ------------------------------------------------------------------ */\n\nconst InstallerBlock = React.forwardRef<HTMLDivElement, InstallerBlockProps>(\n  function InstallerBlock(\n    {\n      productName = \"Mac OS 9.2.2\",\n      onFinish,\n      onInstall,\n      onDisagree,\n      disks = DEFAULT_DISKS,\n      requiredMB = 350,\n      welcome,\n      readMe,\n      license,\n      installDuration = 6000,\n      defaultStep = \"welcome\",\n      title,\n      className,\n      contentClassName,\n      onKeyDown,\n      ...props\n    },\n    ref\n  ) {\n    const id = React.useId()\n    const [step, setStep] = React.useState<InstallerStep>(defaultStep)\n    const [agreed, setAgreed] = React.useState(false)\n    const [alertOpen, setAlertOpen] = React.useState(false)\n    const [diskId, setDiskId] = React.useState<string | null>(\n      () => disks.find((d) => d.availableMB >= requiredMB)?.id ?? null\n    )\n    const [installing, setInstalling] = React.useState(false)\n    const [progress, setProgress] = React.useState(0)\n\n    const index = STEPS.findIndex((s) => s.id === step)\n    const disk = disks.find((d) => d.id === diskId) ?? null\n    const diskOk = !!disk && disk.availableMB >= requiredMB\n\n    /* Simulated install */\n    const progressRef = React.useRef(0)\n    React.useEffect(() => {\n      if (!installing) return\n      const tick = 100\n      const inc = 100 / Math.max(1, installDuration / tick)\n      const timer = setInterval(() => {\n        const next = Math.min(100, progressRef.current + inc)\n        progressRef.current = next\n        setProgress(next)\n        if (next >= 100) {\n          clearInterval(timer)\n          setInstalling(false)\n          setStep(\"done\")\n        }\n      }, tick)\n      return () => clearInterval(timer)\n    }, [installing, installDuration])\n\n    const goBack = () => {\n      if (index > 0 && !installing) setStep(STEPS[index - 1].id)\n    }\n\n    const startInstall = () => {\n      if (!disk) return\n      progressRef.current = 0\n      setProgress(0)\n      setInstalling(true)\n      onInstall?.(disk)\n    }\n\n    const primary = () => {\n      switch (step) {\n        case \"license\":\n          if (agreed) setStep(\"destination\")\n          else setAlertOpen(true)\n          return\n        case \"destination\":\n          if (diskOk) setStep(\"install\")\n          return\n        case \"install\":\n          if (!installing) startInstall()\n          return\n        case \"done\":\n          onFinish?.(\"restart\")\n          return\n        default:\n          setStep(STEPS[index + 1].id)\n      }\n    }\n\n    const agree = () => {\n      setAgreed(true)\n      setAlertOpen(false)\n      setStep(\"destination\")\n    }\n    const disagree = () => {\n      setAlertOpen(false)\n      onDisagree?.()\n    }\n\n    const primaryLabel =\n      step === \"install\" ? (installing ? \"Installing…\" : \"Start\") : step === \"done\" ? \"Restart\" : \"Continue\"\n    const primaryDisabled =\n      (step === \"destination\" && !diskOk) || (step === \"install\" && installing)\n\n    const phase =\n      INSTALL_PHASES[Math.min(INSTALL_PHASES.length - 1, Math.floor((progress / 100) * INSTALL_PHASES.length))]\n    const secondsLeft = Math.ceil(((100 - progress) / 100) * (installDuration / 1000))\n\n    let heading: string\n    let body: React.ReactNode\n    switch (step) {\n      case \"welcome\":\n        heading = `Welcome to the ${productName} Installer`\n        body = (\n          <div className=\"flex gap-4\">\n            <RetroIconHappyMac size=\"lg\" className=\"shrink-0\" />\n            <div className={TEXT}>\n              {welcome ?? (\n                <>\n                  <p>\n                    This program will guide you through the steps necessary\n                    to install {productName} on your computer.\n                  </p>\n                  <p className=\"mt-2\">\n                    Before you begin, quit all other applications and turn\n                    off any virus-protection software.\n                  </p>\n                  <p className=\"mt-2\">Click Continue to proceed.</p>\n                </>\n              )}\n            </div>\n          </div>\n        )\n        break\n      case \"readme\":\n        heading = \"Important Information\"\n        body = (\n          <div className={cn(\"os9-inset h-full overflow-y-auto p-[8px]\", TEXT)} tabIndex={0}>\n            {readMe ?? defaultReadMe(productName)}\n          </div>\n        )\n        break\n      case \"license\":\n        heading = \"Software License Agreement\"\n        body = (\n          <div className=\"flex h-full flex-col gap-2\">\n            <p className={TEXT}>Please read the license agreement below.</p>\n            <div\n              className={cn(\"os9-inset min-h-0 flex-1 overflow-y-auto p-[8px]\", TEXT)}\n              tabIndex={0}\n              aria-label=\"License agreement\"\n            >\n              {license ?? defaultLicense(productName)}\n            </div>\n          </div>\n        )\n        break\n      case \"destination\":\n        heading = \"Select Destination\"\n        body = (\n          <div className=\"flex h-full flex-col gap-2\">\n            <p className={TEXT} id={`${id}-dest`}>\n              Choose a disk on which to install {productName}.\n            </p>\n            <RetroListBox\n              aria-labelledby={`${id}-dest`}\n              value={diskId}\n              onValueChange={setDiskId}\n              className=\"min-h-[88px] flex-1\"\n            >\n              {disks.map((d) => (\n                <RetroListBoxItem\n                  key={d.id}\n                  value={d.id}\n                  textValue={d.name}\n                  disabled={d.availableMB < requiredMB}\n                  className=\"h-[22px] gap-[6px]\"\n                >\n                  <RetroIconHardDrive size=\"sm\" />\n                  <span className=\"min-w-0 flex-1 truncate\">{d.name}</span>\n                  <span className=\"shrink-0 tabular-nums\">{formatMB(d.availableMB)} available</span>\n                </RetroListBoxItem>\n              ))}\n            </RetroListBox>\n            <p className={TEXT} aria-live=\"polite\">\n              {disk ? (\n                diskOk ? (\n                  <>\n                    Installing requires about {formatMB(requiredMB)}.\n                    &ldquo;{disk.name}&rdquo; has {formatMB(disk.availableMB)} available.\n                  </>\n                ) : (\n                  <>&ldquo;{disk.name}&rdquo; does not have enough space. {formatMB(requiredMB)} is required.</>\n                )\n              ) : (\n                \"Select a destination disk.\"\n              )}\n            </p>\n          </div>\n        )\n        break\n      case \"install\":\n        heading = \"Install Software\"\n        body = (\n          <div className={cn(\"flex flex-col gap-3\", TEXT)}>\n            {installing || progress > 0 ? (\n              <>\n                <p>\n                  Installing {productName} on &ldquo;{disk?.name}&rdquo;.\n                </p>\n                <div className=\"flex flex-col gap-1\" aria-live=\"polite\">\n                  <p className=\"truncate\">Installing: {phase}</p>\n                  <RetroProgress value={progress} aria-label=\"Installation progress\" />\n                  <p className=\"text-os9-gray-800\">\n                    About {secondsLeft} {secondsLeft === 1 ? \"second\" : \"seconds\"} remaining\n                  </p>\n                </div>\n              </>\n            ) : (\n              <>\n                <p>\n                  Click Start to install {productName} on &ldquo;{disk?.name}&rdquo;.\n                </p>\n                <p>\n                  Installing will take a few minutes. You can stop at any\n                  time, but your system software may be left incomplete.\n                </p>\n              </>\n            )}\n          </div>\n        )\n        break\n      case \"done\":\n        heading = \"Installation Successful\"\n        body = (\n          <div className=\"flex gap-4\">\n            <RetroIconHappyMac size=\"lg\" className=\"shrink-0\" />\n            <div className={TEXT}>\n              <p>\n                {`${productName} was installed successfully on “${disk?.name ?? \"Macintosh HD\"}”.`}\n              </p>\n              <p className=\"mt-2\">\n                You must restart your computer to use the newly installed\n                software. Click Restart to restart now, or Quit to restart\n                later.\n              </p>\n            </div>\n          </div>\n        )\n        break\n    }\n\n    return (\n      <RetroWindow\n        ref={ref}\n        title={title ?? `Install ${productName}`}\n        role=\"dialog\"\n        aria-label={title ?? `Install ${productName}`}\n        className={cn(\"@container w-full max-w-[620px]\", className)}\n        contentClassName={cn(\"relative flex h-[340px] flex-none gap-[12px] p-[12px] @max-[520px]:h-[400px]\", contentClassName)}\n        onKeyDown={(e) => {\n          onKeyDown?.(e)\n          if (e.defaultPrevented) return\n          if (alertOpen) {\n            if (e.key === \"Escape\") {\n              e.preventDefault()\n              disagree()\n            }\n            return\n          }\n          if (e.key !== \"Enter\") return\n          const t = e.target as HTMLElement\n          if (t.closest(\"button, [role=listbox]\")) return\n          if (primaryDisabled) return\n          e.preventDefault()\n          primary()\n        }}\n        {...props}\n      >\n        <StepList current={index} />\n\n        <div className=\"flex min-w-0 flex-1 flex-col gap-3\" inert={alertOpen || undefined}>\n          <div>\n            <p className=\"hidden font-[family-name:var(--os9-font-sans)] text-[9px] text-os9-gray-800 @max-[520px]:block\">\n              Step {index + 1} of {STEPS.length}\n            </p>\n            <h2 className=\"os9-heading text-[14px] text-os9-black\">{heading}</h2>\n          </div>\n\n          <div className=\"min-h-0 flex-1\">{body}</div>\n\n          <div className=\"flex flex-wrap items-center justify-end gap-3 border-t border-os9-gray-600 pt-[6px] shadow-[inset_0_1px_0_var(--os9-white)]\">\n            {step === \"done\" ? (\n              <RetroButton type=\"button\" className=\"min-w-[80px]\" onClick={() => onFinish?.(\"quit\")}>\n                Quit\n              </RetroButton>\n            ) : step === \"install\" && installing ? (\n              <RetroButton\n                type=\"button\"\n                className=\"min-w-[80px]\"\n                onClick={() => {\n                  setInstalling(false)\n                  progressRef.current = 0\n                  setProgress(0)\n                }}\n              >\n                Stop\n              </RetroButton>\n            ) : (\n              <RetroButton type=\"button\" className=\"min-w-[80px]\" disabled={index === 0} onClick={goBack}>\n                Go Back\n              </RetroButton>\n            )}\n            <RetroButton\n              type=\"button\"\n              isDefault\n              className=\"min-w-[80px]\"\n              disabled={primaryDisabled}\n              onClick={primary}\n            >\n              {primaryLabel}\n            </RetroButton>\n          </div>\n        </div>\n\n        {/* License alert */}\n        {alertOpen && (\n          <div className=\"absolute inset-0 z-10 flex items-center justify-center bg-os9-gray-200/70 p-3\">\n            <div\n              role=\"alertdialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${id}-alert`}\n              className=\"w-full max-w-[380px] border border-os9-black bg-os9-gray-200 p-[3px] shadow-[var(--os9-shadow-window)]\"\n            >\n              <div className=\"border border-os9-gray-600 shadow-[inset_1px_1px_0_var(--os9-white)]\">\n                <div className=\"flex gap-3 p-[12px]\">\n                  <RetroIconAlert className=\"shrink-0\" />\n                  <p id={`${id}-alert`} className=\"os9-heading text-[12px] leading-[1.35] text-os9-black\">\n                    To continue installing the software, you must agree to the\n                    terms of the software license agreement.\n                  </p>\n                </div>\n                <p className={cn(TEXT, \"px-[12px] pb-2 pl-[56px]\")}>\n                  Click Agree to continue, or click Disagree to cancel the\n                  installation.\n                </p>\n                <div className=\"flex justify-end gap-3 px-[12px] pb-[12px]\">\n                  <RetroButton type=\"button\" className=\"min-w-[80px]\" onClick={disagree}>\n                    Disagree\n                  </RetroButton>\n                  <RetroButton type=\"button\" isDefault autoFocus className=\"min-w-[80px]\" onClick={agree}>\n                    Agree\n                  </RetroButton>\n                </div>\n              </div>\n            </div>\n          </div>\n        )}\n      </RetroWindow>\n    )\n  }\n)\nInstallerBlock.displayName = \"InstallerBlock\"\n\nexport { InstallerBlock }\nexport type { InstallerBlockProps, InstallerDisk, InstallerFinishAction, InstallerStep }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}