{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "finder-window",
  "title": "Finder Window",
  "description": "Mac OS 9 Finder window with a sortable Name / Date Modified / Size / Kind list view, disclosure triangles, an icon view toggle, a status placard and a size box.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-bevel-button.json",
    "https://nostalgia-ui.com/r/retro-icon-view.json",
    "https://nostalgia-ui.com/r/retro-icons.json",
    "https://nostalgia-ui.com/r/retro-placard.json",
    "https://nostalgia-ui.com/r/retro-tree-view.json",
    "https://nostalgia-ui.com/r/retro-window.json"
  ],
  "files": [
    {
      "path": "registry/new-york/blocks/finder-window.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { RetroBevelButton } from \"@/registry/new-york/ui/retro-bevel-button\"\nimport {\n  RetroIconApplication,\n  RetroIconDocument,\n  RetroIconFolder,\n} from \"@/registry/new-york/ui/retro-icons\"\nimport {\n  RetroIconView,\n  type IconViewItem,\n} from \"@/registry/new-york/ui/retro-icon-view\"\nimport { RetroPlacard } from \"@/registry/new-york/ui/retro-placard\"\nimport {\n  RetroTreeView,\n  type RetroTreeViewColumn,\n  type TreeNode,\n} from \"@/registry/new-york/ui/retro-tree-view\"\nimport { RetroWindow } from \"@/registry/new-york/ui/retro-window\"\n\n/* ------------------------------------------------------------------ */\n/*  Types                                                              */\n/* ------------------------------------------------------------------ */\n\ntype FinderItemType = \"folder\" | \"document\" | \"application\"\n\ninterface FinderItem {\n  id: string\n  /** File or folder name. */\n  label: string\n  /** Picks the default icons. Inferred from `children` when omitted. */\n  type?: FinderItemType\n  /** Kind column text, e.g. \"SimpleText text document\". Defaults per type. */\n  kind?: string\n  /** Size in bytes. Folders show \"—\". */\n  size?: number\n  /**\n   * Last modified. Pass a Date or an ISO string without a time zone\n   * (e.g. \"1999-10-23T14:32\") so server and client format it identically.\n   */\n  modified?: Date | string\n  /** 32px icon for icon view. */\n  icon?: React.ReactNode\n  /** 16px icon for list view. */\n  smallIcon?: React.ReactNode\n  /** Folder contents. An empty array still makes the item a folder. */\n  children?: FinderItem[]\n}\n\ntype FinderView = \"list\" | \"icon\"\n\ninterface FinderWindowBlockProps\n  extends Omit<\n    React.ComponentPropsWithoutRef<typeof RetroWindow>,\n    \"title\" | \"children\" | \"resizable\"\n  > {\n  /** Folder name shown in the title bar. Defaults to \"Macintosh HD\". */\n  title?: string\n  /** Top-level contents of the folder. */\n  items: FinderItem[]\n  /** Controlled view. */\n  view?: FinderView\n  /** Uncontrolled initial view. Defaults to \"list\". */\n  defaultView?: FinderView\n  onViewChange?: (view: FinderView) => void\n  /** Double-click / Enter on an item. */\n  onOpen?: (item: FinderItem) => void\n  /** Free space shown in the header, e.g. \"1.2 GB\". Defaults to \"1.2 GB\". */\n  available?: string\n  /** Initially expanded folder ids (list view). */\n  defaultExpanded?: string[]\n  /** Show the size box. Defaults to true. */\n  resizable?: boolean\n}\n\n/* ------------------------------------------------------------------ */\n/*  Helpers                                                            */\n/* ------------------------------------------------------------------ */\n\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\nconst DAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"]\n\nfunction toDate(value: Date | string | undefined) {\n  if (!value) return null\n  const d = typeof value === \"string\" ? new Date(value) : value\n  return Number.isNaN(d.getTime()) ? null : d\n}\n\n/** \"Sat, Oct 23, 1999, 2:32 PM\" — Finder's long date format. */\nfunction formatFinderDate(value: Date | string | undefined) {\n  const d = toDate(value)\n  if (!d) return null\n  const h = d.getHours()\n  const m = String(d.getMinutes()).padStart(2, \"0\")\n  return `${DAYS[d.getDay()]}, ${MONTHS[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}, ${h % 12 || 12}:${m} ${h >= 12 ? \"PM\" : \"AM\"}`\n}\n\n/** Finder-style sizes: \"4K\", \"312K\", \"1.2 MB\". */\nfunction formatFinderSize(bytes: number | undefined) {\n  if (bytes == null) return null\n  const k = bytes / 1024\n  if (k < 1000) return `${Math.max(1, Math.round(k))}K`\n  const mb = k / 1024\n  if (mb < 1000) return `${mb.toFixed(1).replace(/\\.0$/, \"\")} MB`\n  return `${(mb / 1024).toFixed(1).replace(/\\.0$/, \"\")} GB`\n}\n\nfunction itemType(item: FinderItem): FinderItemType {\n  return item.type ?? (item.children ? \"folder\" : \"document\")\n}\n\nconst DEFAULT_KIND: Record<FinderItemType, string> = {\n  folder: \"folder\",\n  document: \"document\",\n  application: \"application program\",\n}\n\nfunction defaultIcon(type: FinderItemType, size: \"sm\" | \"default\") {\n  if (type === \"folder\") return <RetroIconFolder size={size} />\n  if (type === \"application\") return <RetroIconApplication size={size} />\n  return <RetroIconDocument size={size} />\n}\n\nfunction toTreeNode(item: FinderItem): TreeNode {\n  const type = itemType(item)\n  return {\n    id: item.id,\n    label: item.label,\n    icon: item.smallIcon ?? defaultIcon(type, \"sm\"),\n    children: item.children?.map(toTreeNode),\n    modified: toDate(item.modified)?.getTime(),\n    modifiedText: formatFinderDate(item.modified),\n    size: type === \"folder\" ? undefined : item.size,\n    kind: item.kind ?? DEFAULT_KIND[type],\n  }\n}\n\nfunction indexItems(items: FinderItem[], map = new Map<string, FinderItem>()) {\n  for (const item of items) {\n    map.set(item.id, item)\n    if (item.children) indexItems(item.children, map)\n  }\n  return map\n}\n\n/* ------------------------------------------------------------------ */\n/*  Small pieces                                                       */\n/* ------------------------------------------------------------------ */\n\nfunction ListViewGlyph() {\n  return (\n    <svg width=\"12\" height=\"10\" viewBox=\"0 0 12 10\" aria-hidden=\"true\">\n      <path d=\"M0 0.5H2M0 4.5H2M0 8.5H2M4 0.5H12M4 4.5H12M4 8.5H12\" stroke=\"currentColor\" />\n    </svg>\n  )\n}\n\nfunction IconViewGlyph() {\n  return (\n    <svg width=\"12\" height=\"10\" viewBox=\"0 0 12 10\" aria-hidden=\"true\">\n      <path d=\"M0.5 0.5H4.5V4.5H0.5ZM7.5 0.5H11.5V4.5H7.5ZM0.5 5.5H4.5V9.5H0.5ZM7.5 5.5H11.5V9.5H7.5Z\" fill=\"none\" stroke=\"currentColor\" />\n    </svg>\n  )\n}\n\n/** Decorative Platinum horizontal scroll bar (inactive: no thumb). */\nfunction HorizontalScrollBar() {\n  const arrow = (dir: \"left\" | \"right\") => (\n    <span\n      className={cn(\n        \"flex w-[15px] shrink-0 items-center justify-center bg-os9-gray-300 shadow-[var(--os9-shadow-raised)]\",\n        dir === \"left\" ? \"border-r border-os9-black\" : \"border-l border-os9-black\"\n      )}\n    >\n      <svg width=\"4\" height=\"7\" viewBox=\"0 0 4 7\" className={dir === \"left\" ? \"rotate-180\" : undefined}>\n        <path d=\"M0 0L4 3.5L0 7Z\" fill=\"var(--os9-gray-600)\" />\n      </svg>\n    </span>\n  )\n  return (\n    <div aria-hidden=\"true\" className=\"flex h-full min-w-[40px] flex-1\">\n      {arrow(\"left\")}\n      <span className=\"flex-1 bg-os9-gray-300 shadow-[inset_1px_1px_0_var(--os9-gray-500)]\" />\n      {arrow(\"right\")}\n    </div>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  FinderWindowBlock                                                  */\n/* ------------------------------------------------------------------ */\n\nconst FinderWindowBlock = React.forwardRef<HTMLDivElement, FinderWindowBlockProps>(\n  function FinderWindowBlock(\n    {\n      title = \"Macintosh HD\",\n      items,\n      view: viewProp,\n      defaultView = \"list\",\n      onViewChange,\n      onOpen,\n      available = \"1.2 GB\",\n      defaultExpanded,\n      resizable = true,\n      className,\n      contentClassName,\n      ...props\n    },\n    ref\n  ) {\n    const [internalView, setInternalView] = React.useState<FinderView>(defaultView)\n    const view = viewProp ?? internalView\n    const setView = (next: FinderView) => {\n      if (viewProp === undefined) setInternalView(next)\n      onViewChange?.(next)\n    }\n\n    const [selected, setSelected] = React.useState<string[]>([])\n\n    const byId = React.useMemo(() => indexItems(items), [items])\n    const treeItems = React.useMemo(() => items.map(toTreeNode), [items])\n    const iconItems = React.useMemo<IconViewItem[]>(\n      () =>\n        items.map((item) => ({\n          id: item.id,\n          label: item.label,\n          icon: item.icon ?? defaultIcon(itemType(item), \"default\"),\n        })),\n      [items]\n    )\n\n    /* Drop the widest columns when the window gets narrow. */\n    const bodyRef = React.useRef<HTMLDivElement>(null)\n    const [bodyWidth, setBodyWidth] = React.useState<number | null>(null)\n    React.useEffect(() => {\n      const el = bodyRef.current\n      if (!el) return\n      const ro = new ResizeObserver(([entry]) => setBodyWidth(entry.contentRect.width))\n      ro.observe(el)\n      return () => ro.disconnect()\n    }, [])\n    const showDate = bodyWidth === null || bodyWidth >= 380\n    const showKind = bodyWidth === null || bodyWidth >= 520\n\n    const columns = React.useMemo<RetroTreeViewColumn[]>(() => {\n      const cols: RetroTreeViewColumn[] = [\n        { key: \"label\", header: \"Name\", width: \"minmax(120px,1fr)\" },\n      ]\n      if (showDate)\n        cols.push({\n          key: \"modified\",\n          header: \"Date Modified\",\n          width: 176,\n          render: (n) => (n.modifiedText as string | null) ?? \"—\",\n        })\n      cols.push({\n        key: \"size\",\n        header: \"Size\",\n        width: 64,\n        align: \"right\",\n        render: (n) => formatFinderSize(n.size as number | undefined) ?? \"—\",\n      })\n      if (showKind) cols.push({ key: \"kind\", header: \"Kind\", width: 150 })\n      return cols\n    }, [showDate, showKind])\n\n    const count = items.length\n    const selectedCount = selected.filter((id) => byId.has(id)).length\n\n    return (\n      <RetroWindow\n        ref={ref}\n        title={title}\n        resizable={resizable}\n        minWidth={240}\n        minHeight={180}\n        className={cn(\"h-[380px] w-full max-w-[640px]\", className)}\n        contentClassName={cn(\"flex flex-col p-0\", contentClassName)}\n        footer={\n          <div className=\"flex h-[15px] items-stretch\">\n            <RetroPlacard className=\"h-[15px] border-y-0 border-l-0\">\n              {selectedCount > 0\n                ? `${selectedCount} of ${count} selected`\n                : `${count} ${count === 1 ? \"item\" : \"items\"}`}\n            </RetroPlacard>\n            <HorizontalScrollBar />\n          </div>\n        }\n        {...props}\n      >\n        {/* Header strip: view buttons + item count / free space */}\n        <div className=\"flex h-[22px] shrink-0 items-center gap-2 border-b border-os9-black px-[4px] shadow-[inset_0_-1px_0_var(--os9-gray-500)]\">\n          <div role=\"group\" aria-label=\"View\" className=\"flex shrink-0\">\n            <RetroBevelButton\n              bevel=\"small\"\n              size=\"sm\"\n              aria-label=\"as List\"\n              title=\"as List\"\n              pressed={view === \"list\"}\n              onPressedChange={() => setView(\"list\")}\n              icon={<ListViewGlyph />}\n              className=\"h-[16px] min-h-0 w-[20px] min-w-0 px-0 py-0\"\n            />\n            <RetroBevelButton\n              bevel=\"small\"\n              size=\"sm\"\n              aria-label=\"as Icons\"\n              title=\"as Icons\"\n              pressed={view === \"icon\"}\n              onPressedChange={() => setView(\"icon\")}\n              icon={<IconViewGlyph />}\n              className=\"-ml-px h-[16px] min-h-0 w-[20px] min-w-0 px-0 py-0\"\n            />\n          </div>\n          <p className=\"min-w-0 flex-1 truncate pr-[44px] text-center font-[family-name:var(--os9-font-sans)] text-[10px] text-os9-black max-[420px]:pr-0\">\n            {count} {count === 1 ? \"item\" : \"items\"}, {available} available\n          </p>\n        </div>\n\n        {/* Body */}\n        <div ref={bodyRef} className=\"min-h-0 flex-1\">\n          {view === \"list\" ? (\n            <RetroTreeView\n              aria-label={title}\n              items={treeItems}\n              columns={columns}\n              defaultSort={{ column: \"label\", direction: \"asc\" }}\n              defaultExpanded={defaultExpanded}\n              selectionMode=\"multiple\"\n              selected={selected}\n              onSelectedChange={setSelected}\n              onActivate={(node) => {\n                const item = byId.get(node.id)\n                if (item) onOpen?.(item)\n              }}\n              className=\"h-full border-0 shadow-none\"\n            />\n          ) : (\n            <RetroIconView\n              aria-label={title}\n              items={iconItems}\n              selected={selected}\n              onSelectedChange={setSelected}\n              onOpen={(icon) => {\n                const item = byId.get(icon.id)\n                if (item) onOpen?.(item)\n              }}\n              className=\"h-full overflow-auto border-0 bg-os9-white shadow-none\"\n            />\n          )}\n        </div>\n      </RetroWindow>\n    )\n  }\n)\nFinderWindowBlock.displayName = \"FinderWindowBlock\"\n\nexport { FinderWindowBlock, formatFinderDate, formatFinderSize }\nexport type { FinderWindowBlockProps, FinderItem, FinderItemType, FinderView }\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}