{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-file-manager",
  "type": "registry:component",
  "title": "App File Manager",
  "description": "A file browser with breadcrumbs, grid and list views, checkbox selection with a bulk action bar, a storage meter and a drag-over upload overlay.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "app-ui",
    "files",
    "file manager",
    "upload",
    "drag and drop",
    "selection",
    "storage"
  ],
  "docs": "https://hyperblur.dev/effects/app-file-manager",
  "files": [
    {
      "path": "registry/hyperblur/app-file-manager.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/app-file-manager.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type AppFileKind = \"folder\" | \"image\" | \"doc\" | \"sheet\" | \"video\" | \"pdf\" | \"zip\" | \"audio\";\n\nexport interface AppFile {\n  id: string;\n  name: string;\n  kind: AppFileKind;\n  size?: number;\n  items?: number;\n  modified: string;\n  owner: string;\n}\n\nexport interface AppFileManagerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  files?: AppFile[];\n  path?: string[];\n  defaultView?: \"grid\" | \"list\";\n  defaultSelected?: string[];\n  usedBytes?: number;\n  totalBytes?: number;\n  accent?: string;\n  onUpload?: (files: File[]) => void;\n  onDelete?: (ids: string[]) => void;\n  onOpenFile?: (file: AppFile) => void;\n  onPathSelect?: (index: number) => void;\n}\n\nconst GB = 1024 * 1024 * 1024;\nconst MB = 1024 * 1024;\n\nconst defaultFiles: AppFile[] = [\n  { id: \"f1\", name: \"Campaign assets\", kind: \"folder\", items: 48, modified: \"Nov 3\", owner: \"Maya Okafor\" },\n  { id: \"f2\", name: \"Press kit\", kind: \"folder\", items: 12, modified: \"Oct 29\", owner: \"Sofia Lind\" },\n  { id: \"f3\", name: \"hero-launch-v4.png\", kind: \"image\", size: 4.8 * MB, modified: \"Nov 4\", owner: \"Amara Chen\" },\n  { id: \"f4\", name: \"Launch brief.docx\", kind: \"doc\", size: 312 * 1024, modified: \"Nov 2\", owner: \"Maya Okafor\" },\n  { id: \"f5\", name: \"Budget Q4.xlsx\", kind: \"sheet\", size: 128 * 1024, modified: \"Nov 1\", owner: \"Tom Whitaker\" },\n  { id: \"f6\", name: \"teaser-cut-03.mp4\", kind: \"video\", size: 286 * MB, modified: \"Oct 31\", owner: \"Diego Ramos\" },\n  { id: \"f7\", name: \"Brand guidelines.pdf\", kind: \"pdf\", size: 18.2 * MB, modified: \"Oct 27\", owner: \"Sofia Lind\" },\n  { id: \"f8\", name: \"product-shots.zip\", kind: \"zip\", size: 642 * MB, modified: \"Oct 24\", owner: \"Amara Chen\" },\n  { id: \"f9\", name: \"billboard-night.jpg\", kind: \"image\", size: 9.1 * MB, modified: \"Oct 22\", owner: \"Amara Chen\" },\n  { id: \"f10\", name: \"voiceover-final.wav\", kind: \"audio\", size: 54 * MB, modified: \"Oct 20\", owner: \"Kenji Mori\" },\n];\n\nconst kindMeta: Record<AppFileKind, { color: string; label: string; icon: string }> = {\n  folder: { color: \"#7fb3ff\", label: \"Folder\", icon: \"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z\" },\n  image: { color: \"#c084fc\", label: \"Image\", icon: \"M4 5h16v14H4V5Zm0 11 5-5 4 4 2-2 5 5M15 9.5a1.5 1.5 0 1 0 0-.01\" },\n  doc: { color: \"#60a5fa\", label: \"Document\", icon: \"M7 3h7l5 5v13H7V3Zm7 0v5h5M10 13h6M10 17h6\" },\n  sheet: { color: \"#34d399\", label: \"Spreadsheet\", icon: \"M5 4h14v16H5V4Zm0 5h14M5 14h14M10 4v16\" },\n  video: { color: \"#fb923c\", label: \"Video\", icon: \"M4 6h12v12H4V6Zm12 4 4-2v8l-4-2\" },\n  pdf: { color: \"#f87171\", label: \"PDF\", icon: \"M7 3h7l5 5v13H7V3Zm7 0v5h5M9.5 16h5\" },\n  zip: { color: \"#facc15\", label: \"Archive\", icon: \"M6 3h12v18H6V3Zm6 0v2m0 2v2m0 2v2m-1 2h2v3h-2v-3Z\" },\n  audio: { color: \"#2dd4bf\", label: \"Audio\", icon: \"M9 18V6l10-2v12M9 18a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Zm10-2a2.5 2.5 0 1 1-5 0 2.5 2.5 0 0 1 5 0Z\" },\n};\n\nconst places = [\n  { label: \"My files\", icon: \"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z\" },\n  { label: \"Shared with me\", icon: \"M16 19a5 5 0 0 0-10 0M11 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm6-1a3 3 0 1 0-1-5.8M21 19a4.5 4.5 0 0 0-3-4.2\" },\n  { label: \"Recent\", icon: \"M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-13v4l3 2\" },\n  { label: \"Starred\", icon: \"M12 4l2.5 5 5.5.8-4 3.9.9 5.5L12 16.6 7.1 19.2l.9-5.5-4-3.9 5.5-.8L12 4Z\" },\n  { label: \"Trash\", icon: \"M5 7h14M10 11v6m4-6v6M6 7l1 13h10l1-13M9 7V4h6v3\" },\n];\n\nfunction fmtSize(b?: number) {\n  if (b === undefined) return \"\";\n  if (b >= GB) return `${(b / GB).toFixed(1)} GB`;\n  if (b >= MB) return `${(b / MB).toFixed(1)} MB`;\n  return `${Math.max(1, Math.round(b / 1024))} KB`;\n}\n\nfunction kindFromName(name: string, type: string): AppFileKind {\n  const ext = name.split(\".\").pop()?.toLowerCase() ?? \"\";\n  if (type.startsWith(\"image/\") || [\"png\", \"jpg\", \"jpeg\", \"gif\", \"webp\", \"svg\"].includes(ext)) return \"image\";\n  if (type.startsWith(\"video/\") || [\"mp4\", \"mov\", \"webm\"].includes(ext)) return \"video\";\n  if (type.startsWith(\"audio/\") || [\"mp3\", \"wav\", \"m4a\"].includes(ext)) return \"audio\";\n  if (ext === \"pdf\") return \"pdf\";\n  if ([\"xls\", \"xlsx\", \"csv\", \"numbers\"].includes(ext)) return \"sheet\";\n  if ([\"zip\", \"rar\", \"7z\", \"gz\"].includes(ext)) return \"zip\";\n  return \"doc\";\n}\n\nfunction hash(s: string) {\n  let h = 0;\n  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;\n  return h >>> 0;\n}\n\nconst css = `\n.hb-ye4 {\n  --hb-ye4-accent: #2f7bff;\n  container-type: inline-size;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  min-height: 600px;\n  overflow: hidden;\n  border: 1px solid rgba(255,255,255,.08);\n  border-radius: 16px;\n  background: #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 14px;\n  line-height: 1.4;\n}\n.hb-ye4 *, .hb-ye4 *::before, .hb-ye4 *::after { box-sizing: border-box; }\n.hb-ye4-shell { display: grid; grid-template-columns: 1fr; min-height: 600px; }\n.hb-ye4-side { display: none; flex-direction: column; gap: 4px; padding: 18px 12px; border-right: 1px solid rgba(255,255,255,.08); background: #0d0d0d; }\n.hb-ye4-new { display: flex; align-items: center; justify-content: center; gap: 8px; height: 36px; margin: 0 4px 12px; border: 0; border-radius: 10px; background: #ededed; color: #0a0a0a; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); }\n.hb-ye4-new:hover { background: #fff; }\n.hb-ye4-new svg { width: 15px; height: 15px; }\n.hb-ye4-place { display: flex; align-items: center; gap: 10px; width: 100%; margin: 0; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; color: #a1a1a1; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }\n.hb-ye4-place:hover { background: #151515; color: #ededed; }\n.hb-ye4-place[aria-current=\"page\"] { background: #171717; color: #ededed; }\n.hb-ye4-place svg { width: 16px; height: 16px; flex: none; }\n.hb-ye4-place[aria-current=\"page\"] svg { color: var(--hb-ye4-accent); }\n.hb-ye4-storage { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid rgba(255,255,255,.06); }\n.hb-ye4-storage-h { display: flex; justify-content: space-between; font-size: 12.5px; }\n.hb-ye4-storage-h span { color: #8f8f8f; }\n.hb-ye4-meter { display: flex; gap: 2px; height: 7px; margin: 9px 0 10px; border-radius: 999px; background: #1f1f1f; overflow: hidden; }\n.hb-ye4-meter i { height: 100%; transform-origin: left; animation: hb-ye4-grow .9s cubic-bezier(.2,.8,.2,1) both; }\n.hb-ye4-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 8px; color: #8f8f8f; font-size: 11.5px; }\n.hb-ye4-legend span { display: flex; align-items: center; gap: 6px; }\n.hb-ye4-legend i { width: 7px; height: 7px; border-radius: 2px; }\n.hb-ye4-upgrade { margin-top: 12px; color: var(--hb-ye4-accent); font-size: 12.5px; font-weight: 500; text-decoration: none; }\n.hb-ye4-main { position: relative; display: flex; flex-direction: column; min-width: 0; padding: 16px 18px 18px; }\n.hb-ye4-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }\n.hb-ye4-crumbs { display: flex; align-items: center; gap: 2px; margin: 0 auto 0 0; padding: 0; list-style: none; min-width: 0; font-size: 15px; }\n.hb-ye4-crumbs li { display: flex; align-items: center; gap: 2px; min-width: 0; }\n.hb-ye4-crumbs li + li::before { content: \"/\"; margin: 0 4px; color: #4a4a4a; }\n.hb-ye4-crumb { margin: 0; padding: 3px 6px; border: 0; border-radius: 6px; background: transparent; color: #8f8f8f; font: inherit; cursor: pointer; white-space: nowrap; }\n.hb-ye4-crumb:hover { background: #151515; color: #ededed; }\n.hb-ye4-crumb[aria-current=\"page\"] { color: #ededed; font-weight: 600; cursor: default; }\n.hb-ye4-search { display: flex; align-items: center; gap: 8px; width: 220px; max-width: 100%; height: 34px; padding: 0 10px; border: 1px solid #262626; border-radius: 9px; background: #111; color: #737373; }\n.hb-ye4-search:focus-within { outline: 2px solid var(--hb-ye4-accent); outline-offset: 1px; }\n.hb-ye4-search svg { width: 15px; height: 15px; flex: none; }\n.hb-ye4-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: #ededed; font: inherit; font-size: 13px; outline: none; }\n.hb-ye4-seg { display: flex; gap: 2px; padding: 3px; border: 1px solid rgba(255,255,255,.08); border-radius: 9px; background: #101010; }\n.hb-ye4-seg button { display: grid; place-items: center; width: 30px; height: 26px; margin: 0; padding: 0; border: 0; border-radius: 6px; background: transparent; color: #8f8f8f; cursor: pointer; }\n.hb-ye4-seg button[aria-checked=\"true\"] { background: #1f1f1f; color: #ededed; }\n.hb-ye4-seg svg { width: 15px; height: 15px; }\n.hb-ye4 button:focus-visible, .hb-ye4 a:focus-visible, .hb-ye4-check:focus-visible { outline: 2px solid var(--hb-ye4-accent); outline-offset: 1px; }\n.hb-ye4-sum { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: #737373; font-size: 12px; }\n.hb-ye4-area { position: relative; flex: 1; min-height: 0; }\n.hb-ye4-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }\n.hb-ye4-card { position: relative; display: flex; flex-direction: column; border: 1px solid rgba(255,255,255,.07); border-radius: 12px; background: #101010; cursor: pointer; overflow: hidden; transition: border-color .15s ease, transform .2s ease, box-shadow .2s ease; animation: hb-ye4-in .35s cubic-bezier(.2,.8,.2,1) both; }\n.hb-ye4-card:hover { border-color: rgba(255,255,255,.14); transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,.35); }\n.hb-ye4-card[data-selected=\"true\"], .hb-ye4-tr[data-selected=\"true\"] { border-color: color-mix(in srgb, var(--hb-ye4-accent) 70%, transparent); background: color-mix(in srgb, var(--hb-ye4-accent) 8%, #101010); }\n.hb-ye4-card[data-new=\"true\"], .hb-ye4-tr[data-new=\"true\"] { animation: hb-ye4-flash 1.6s ease both; }\n.hb-ye4-thumb { position: relative; display: grid; place-items: center; height: 96px; background: #151515; }\n.hb-ye4-thumb svg { width: 34px; height: 34px; }\n.hb-ye4-art { position: absolute; inset: 0; }\n.hb-ye4-check { position: absolute; top: 8px; left: 8px; z-index: 1; width: 17px; height: 17px; margin: 0; accent-color: var(--hb-ye4-accent); cursor: pointer; opacity: 0; transition: opacity .15s ease; }\n.hb-ye4-card:hover .hb-ye4-check, .hb-ye4-check:checked, .hb-ye4-check:focus-visible, .hb-ye4[data-selecting=\"true\"] .hb-ye4-check { opacity: 1; }\n.hb-ye4-info { display: flex; flex-direction: column; gap: 2px; padding: 9px 11px 10px; min-width: 0; }\n.hb-ye4-name { overflow: hidden; font-size: 13px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; }\n.hb-ye4-meta { color: #737373; font-size: 11.5px; }\n.hb-ye4-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }\n.hb-ye4-table th { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.08); color: #737373; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-align: left; text-transform: uppercase; }\n.hb-ye4-table td { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.05); color: #a1a1a1; white-space: nowrap; }\n.hb-ye4-table td:nth-child(2) { width: 100%; max-width: 0; color: #ededed; }\n.hb-ye4-tr { cursor: pointer; animation: hb-ye4-in .3s ease both; }\n.hb-ye4-tr:hover td { background: #111; }\n.hb-ye4-tr[data-selected=\"true\"] td { background: color-mix(in srgb, var(--hb-ye4-accent) 9%, transparent); }\n.hb-ye4-tr .hb-ye4-check, .hb-ye4-table th .hb-ye4-check { position: static; opacity: 1; }\n.hb-ye4-cellname { display: flex; align-items: center; gap: 10px; min-width: 0; }\n.hb-ye4-cellname > span:last-child { overflow: hidden; text-overflow: ellipsis; }\n.hb-ye4-ico { display: grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 7px; }\n.hb-ye4-ico svg { width: 15px; height: 15px; }\n.hb-ye4-hide { display: none; }\n.hb-ye4-empty { padding: 60px 20px; color: #737373; text-align: center; }\n.hb-ye4-bulk { position: absolute; left: 50%; bottom: 18px; z-index: 4; display: flex; align-items: center; gap: 4px; padding: 6px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; background: rgba(28,28,28,.94); box-shadow: 0 18px 40px rgba(0,0,0,.55); backdrop-filter: blur(10px); transform: translate(-50%, 0); animation: hb-ye4-up .3s cubic-bezier(.2,.9,.2,1) both; white-space: nowrap; }\n.hb-ye4-bulk-n { padding: 0 10px 0 8px; font-size: 13px; font-weight: 600; }\n.hb-ye4-bulk button { display: inline-flex; align-items: center; gap: 6px; height: 30px; margin: 0; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: #d4d4d4; font: inherit; font-size: 13px; cursor: pointer; }\n.hb-ye4-bulk button:hover { background: #2a2a2a; color: #fff; }\n.hb-ye4-bulk button[data-tone=\"danger\"] { color: #ff8a8a; }\n.hb-ye4-bulk svg { width: 15px; height: 15px; }\n.hb-ye4-sep { width: 1px; height: 18px; margin: 0 2px; background: #333; }\n.hb-ye4-drop { position: absolute; inset: 8px; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 2px dashed color-mix(in srgb, var(--hb-ye4-accent) 70%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--hb-ye4-accent) 10%, rgba(10,10,10,.88)); backdrop-filter: blur(4px); pointer-events: none; animation: hb-ye4-fade .18s ease both; }\n.hb-ye4-drop-ico { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--hb-ye4-accent); color: #fff; animation: hb-ye4-bob 1.2s ease-in-out infinite; }\n.hb-ye4-drop-ico svg { width: 26px; height: 26px; }\n.hb-ye4-drop b { font-size: 16px; }\n.hb-ye4-drop span { color: #a1a1a1; font-size: 13px; }\n@keyframes hb-ye4-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }\n@keyframes hb-ye4-up { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }\n@keyframes hb-ye4-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }\n@keyframes hb-ye4-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-ye4-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }\n@keyframes hb-ye4-flash { 0% { box-shadow: 0 0 0 2px var(--hb-ye4-accent); } 100% { box-shadow: 0 0 0 0 transparent; } }\n@container (min-width: 700px) {\n  .hb-ye4-shell { grid-template-columns: 220px 1fr; }\n  .hb-ye4-side { display: flex; }\n  .hb-ye4-main { padding: 20px 22px; }\n  .hb-ye4-hide { display: table-cell; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ye4 *, .hb-ye4 *::before, .hb-ye4 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction Icon({ d, color }: { d: string; color?: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke={color ?? \"currentColor\"} strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n}\n\nfunction Art({ file }: { file: AppFile }) {\n  const h = hash(file.name);\n  const a = h % 360;\n  const b = (a + 40 + (h % 60)) % 360;\n  if (file.kind === \"image\") {\n    return (\n      <svg className=\"hb-ye4-art\" viewBox=\"0 0 160 96\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <defs>\n          <linearGradient id={`hb-ye4-g${file.id}`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n            <stop offset=\"0\" stopColor={`hsl(${a} 70% 55%)`} />\n            <stop offset=\"1\" stopColor={`hsl(${b} 60% 22%)`} />\n          </linearGradient>\n        </defs>\n        <rect width=\"160\" height=\"96\" fill={`url(#hb-ye4-g${file.id})`} />\n        <circle cx={(110 + (h % 30)).toFixed(0)} cy=\"30\" r=\"12\" fill=\"rgba(255,255,255,.75)\" />\n        <path d=\"M0 96 L46 50 L78 78 L104 58 L160 96 Z\" fill=\"rgba(0,0,0,.35)\" />\n      </svg>\n    );\n  }\n  if (file.kind === \"video\") {\n    return (\n      <svg className=\"hb-ye4-art\" viewBox=\"0 0 160 96\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <rect width=\"160\" height=\"96\" fill=\"#1a1410\" />\n        <rect y=\"0\" width=\"160\" height=\"96\" fill={`hsl(${a} 50% 30% / .5)`} />\n        <circle cx=\"80\" cy=\"48\" r=\"16\" fill=\"rgba(0,0,0,.5)\" stroke=\"rgba(255,255,255,.5)\" />\n        <path d=\"M75 40 L88 48 L75 56 Z\" fill=\"#fff\" />\n        <rect x=\"8\" y=\"84\" width=\"144\" height=\"3\" rx=\"1.5\" fill=\"rgba(255,255,255,.2)\" />\n        <rect x=\"8\" y=\"84\" width=\"58\" height=\"3\" rx=\"1.5\" fill=\"#fb923c\" />\n      </svg>\n    );\n  }\n  return null;\n}\n\nexport function AppFileManager({\n  files: filesProp = defaultFiles,\n  path = [\"My files\", \"Marketing\", \"Q4 Launch\"],\n  defaultView = \"grid\",\n  defaultSelected = [],\n  usedBytes = 68.4 * GB,\n  totalBytes = 100 * GB,\n  accent = \"#2f7bff\",\n  onUpload,\n  onDelete,\n  onOpenFile,\n  onPathSelect,\n  className,\n  style,\n  ...rest\n}: AppFileManagerProps) {\n  const [files, setFiles] = React.useState<AppFile[]>(filesProp);\n  const [view, setView] = React.useState<\"grid\" | \"list\">(defaultView);\n  const [selected, setSelected] = React.useState<Set<string>>(() => new Set(defaultSelected));\n  const [query, setQuery] = React.useState(\"\");\n  const [dragging, setDragging] = React.useState(false);\n  const [fresh, setFresh] = React.useState<Set<string>>(new Set());\n  const depth = React.useRef(0);\n  const counter = React.useRef(0);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n  const allRef = React.useRef<HTMLInputElement>(null);\n\n  const visible = files.filter((f) => f.name.toLowerCase().includes(query.trim().toLowerCase()));\n  const allSelected = visible.length > 0 && visible.every((f) => selected.has(f.id));\n  const someSelected = visible.some((f) => selected.has(f.id));\n\n  React.useEffect(() => {\n    if (allRef.current) allRef.current.indeterminate = someSelected && !allSelected;\n  }, [someSelected, allSelected, view]);\n\n  React.useEffect(() => {\n    if (!fresh.size) return;\n    const t = window.setTimeout(() => setFresh(new Set()), 1800);\n    return () => window.clearTimeout(t);\n  }, [fresh]);\n\n  const toggle = (id: string) => {\n    setSelected((s) => {\n      const next = new Set(s);\n      if (next.has(id)) next.delete(id);\n      else next.add(id);\n      return next;\n    });\n  };\n\n  const toggleAll = () => setSelected(allSelected ? new Set() : new Set(visible.map((f) => f.id)));\n  const clear = () => setSelected(new Set());\n\n  const remove = () => {\n    const ids = [...selected];\n    setFiles((list) => list.filter((f) => !selected.has(f.id)));\n    clear();\n    onDelete?.(ids);\n  };\n\n  const addFiles = (list: File[]) => {\n    if (!list.length) return;\n    const added: AppFile[] = list.map((f) => {\n      counter.current += 1;\n      return { id: `up-${counter.current}`, name: f.name, kind: kindFromName(f.name, f.type), size: f.size, modified: \"Just now\", owner: \"You\" };\n    });\n    setFiles((cur) => [...added, ...cur]);\n    setFresh(new Set(added.map((f) => f.id)));\n    onUpload?.(list);\n  };\n\n  const onDragEnter = (e: React.DragEvent) => {\n    if (!e.dataTransfer.types.includes(\"Files\")) return;\n    e.preventDefault();\n    depth.current += 1;\n    setDragging(true);\n  };\n  const onDragOver = (e: React.DragEvent) => {\n    if (!e.dataTransfer.types.includes(\"Files\")) return;\n    e.preventDefault();\n    e.dataTransfer.dropEffect = \"copy\";\n  };\n  const onDragLeave = () => {\n    depth.current = Math.max(0, depth.current - 1);\n    if (depth.current === 0) setDragging(false);\n  };\n  const onDrop = (e: React.DragEvent) => {\n    e.preventDefault();\n    depth.current = 0;\n    setDragging(false);\n    addFiles(Array.from(e.dataTransfer.files));\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent) => {\n    const tag = (e.target as HTMLElement).tagName;\n    if (e.key === \"Escape\" && selected.size) clear();\n    if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === \"a\" && tag !== \"INPUT\") {\n      e.preventDefault();\n      setSelected(new Set(visible.map((f) => f.id)));\n    }\n    if ((e.key === \"Delete\" || e.key === \"Backspace\") && selected.size && tag !== \"INPUT\") {\n      e.preventDefault();\n      remove();\n    }\n  };\n\n  const onItemKey = (e: React.KeyboardEvent, f: AppFile) => {\n    if (e.target !== e.currentTarget) return;\n    if (e.key === \"Enter\") onOpenFile?.(f);\n    if (e.key === \" \") { e.preventDefault(); toggle(f.id); }\n  };\n\n  const used = files.reduce((n, f) => (f.id.startsWith(\"up-\") ? n + (f.size ?? 0) : n), usedBytes);\n  const segments = [\n    { label: \"Video\", color: \"#fb923c\", share: 0.34 },\n    { label: \"Images\", color: \"#c084fc\", share: 0.22 },\n    { label: \"Docs\", color: \"#60a5fa\", share: 0.08 },\n    { label: \"Other\", color: \"#facc15\", share: 0.044 },\n  ];\n  const pct = Math.min(1, used / totalBytes);\n  const scale = pct / segments.reduce((n, s) => n + s.share, 0);\n  const selecting = selected.size > 0;\n\n  const sub = (f: AppFile) => (f.kind === \"folder\" ? `${f.items ?? 0} items` : fmtSize(f.size));\n\n  return (\n    <div\n      className={[\"hb-ye4\", className].filter(Boolean).join(\" \")}\n      style={{ \"--hb-ye4-accent\": accent, ...style } as React.CSSProperties}\n      data-selecting={selecting}\n      onKeyDown={onKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-app-file-manager\" precedence=\"default\">{css}</style>\n      <div className=\"hb-ye4-shell\">\n        <nav className=\"hb-ye4-side\" aria-label=\"Locations\">\n          <button type=\"button\" className=\"hb-ye4-new\" onClick={() => inputRef.current?.click()}><Icon d=\"M12 16V4m-5 5 5-5 5 5M5 20h14\" />Upload</button>\n          {places.map((p, i) => (\n            <button key={p.label} type=\"button\" className=\"hb-ye4-place\" aria-current={i === 0 ? \"page\" : undefined}>\n              <Icon d={p.icon} />\n              {p.label}\n            </button>\n          ))}\n          <div className=\"hb-ye4-storage\">\n            <div className=\"hb-ye4-storage-h\"><b>Storage</b><span>{fmtSize(used)} of {fmtSize(totalBytes)}</span></div>\n            <div className=\"hb-ye4-meter\" role=\"meter\" aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(pct * 100)} aria-label=\"Storage used\">\n              {segments.map((s, i) => (\n                <i key={s.label} style={{ width: `${(s.share * scale * 100).toFixed(2)}%`, background: s.color, animationDelay: `${(i * 0.08).toFixed(2)}s` }} />\n              ))}\n            </div>\n            <div className=\"hb-ye4-legend\">\n              {segments.map((s) => <span key={s.label}><i style={{ background: s.color }} />{s.label}</span>)}\n            </div>\n            <a className=\"hb-ye4-upgrade\" href=\"#upgrade\" style={{ display: \"inline-block\" }}>Get 2 TB for $9.99/mo</a>\n          </div>\n        </nav>\n        <section\n          className=\"hb-ye4-main\"\n          aria-label={path[path.length - 1]}\n          onDragEnter={onDragEnter}\n          onDragOver={onDragOver}\n          onDragLeave={onDragLeave}\n          onDrop={onDrop}\n        >\n          <div className=\"hb-ye4-top\">\n            <ol className=\"hb-ye4-crumbs\" aria-label=\"Breadcrumb\">\n              {path.map((p, i) => (\n                <li key={`${p}-${i}`}>\n                  <button type=\"button\" className=\"hb-ye4-crumb\" aria-current={i === path.length - 1 ? \"page\" : undefined} onClick={() => onPathSelect?.(i)}>{p}</button>\n                </li>\n              ))}\n            </ol>\n            <label className=\"hb-ye4-search\">\n              <Icon d=\"M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14Zm9 2-4-4\" />\n              <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder=\"Search in folder\" aria-label=\"Search in folder\" />\n            </label>\n            <div className=\"hb-ye4-seg\" role=\"radiogroup\" aria-label=\"View\">\n              {([\"grid\", \"list\"] as const).map((v) => (\n                <button\n                  key={v}\n                  type=\"button\"\n                  role=\"radio\"\n                  aria-checked={view === v}\n                  aria-label={v === \"grid\" ? \"Grid view\" : \"List view\"}\n                  tabIndex={view === v ? 0 : -1}\n                  onClick={() => setView(v)}\n                  onKeyDown={(e) => { if (e.key.startsWith(\"Arrow\")) { e.preventDefault(); setView(view === \"grid\" ? \"list\" : \"grid\"); } }}\n                >\n                  <Icon d={v === \"grid\" ? \"M4 4h7v7H4V4Zm9 0h7v7h-7V4ZM4 13h7v7H4v-7Zm9 0h7v7h-7v-7Z\" : \"M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01\"} />\n                </button>\n              ))}\n            </div>\n          </div>\n          <div className=\"hb-ye4-sum\">\n            <span>{visible.length} items{query && ` matching \"${query}\"`}</span>\n            {view === \"grid\" && visible.length > 0 && (\n              <label style={{ display: \"flex\", alignItems: \"center\", gap: 6, cursor: \"pointer\" }}>\n                <input ref={allRef} type=\"checkbox\" className=\"hb-ye4-check\" style={{ position: \"static\", opacity: 1 }} checked={allSelected} onChange={toggleAll} />\n                Select all\n              </label>\n            )}\n          </div>\n          <div className=\"hb-ye4-area\">\n            {visible.length === 0 && <div className=\"hb-ye4-empty\">No files match that search.</div>}\n            {view === \"grid\" ? (\n              <div className=\"hb-ye4-grid\" role=\"list\">\n                {visible.map((f, i) => {\n                  const k = kindMeta[f.kind];\n                  return (\n                    <div\n                      key={f.id}\n                      role=\"listitem\"\n                      tabIndex={0}\n                      className=\"hb-ye4-card\"\n                      data-selected={selected.has(f.id)}\n                      data-new={fresh.has(f.id)}\n                      aria-label={`${f.name}, ${k.label}`}\n                      style={{ animationDelay: `${(i * 0.03).toFixed(2)}s` }}\n                      onClick={(e) => { if (selecting || e.metaKey || e.ctrlKey || e.shiftKey) toggle(f.id); else onOpenFile?.(f); }}\n                      onKeyDown={(e) => onItemKey(e, f)}\n                    >\n                      <input type=\"checkbox\" className=\"hb-ye4-check\" checked={selected.has(f.id)} aria-label={`Select ${f.name}`} onClick={(e) => e.stopPropagation()} onChange={() => toggle(f.id)} />\n                      <div className=\"hb-ye4-thumb\" style={{ background: `linear-gradient(160deg, color-mix(in srgb, ${k.color} 14%, #151515), #121212)` }}>\n                        <Art file={f} />\n                        {f.kind !== \"image\" && f.kind !== \"video\" && <Icon d={k.icon} color={k.color} />}\n                      </div>\n                      <div className=\"hb-ye4-info\">\n                        <span className=\"hb-ye4-name\" title={f.name}>{f.name}</span>\n                        <span className=\"hb-ye4-meta\">{sub(f)} · {f.modified}</span>\n                      </div>\n                    </div>\n                  );\n                })}\n              </div>\n            ) : visible.length > 0 && (\n              <table className=\"hb-ye4-table\">\n                <thead>\n                  <tr>\n                    <th style={{ width: 32 }}><input ref={allRef} type=\"checkbox\" className=\"hb-ye4-check\" checked={allSelected} onChange={toggleAll} aria-label=\"Select all\" /></th>\n                    <th>Name</th>\n                    <th className=\"hb-ye4-hide\">Owner</th>\n                    <th className=\"hb-ye4-hide\">Modified</th>\n                    <th style={{ textAlign: \"right\" }}>Size</th>\n                  </tr>\n                </thead>\n                <tbody>\n                  {visible.map((f, i) => {\n                    const k = kindMeta[f.kind];\n                    return (\n                      <tr\n                        key={f.id}\n                        className=\"hb-ye4-tr\"\n                        tabIndex={0}\n                        data-selected={selected.has(f.id)}\n                        data-new={fresh.has(f.id)}\n                        style={{ animationDelay: `${(i * 0.025).toFixed(3)}s` }}\n                        onClick={() => toggle(f.id)}\n                        onDoubleClick={() => onOpenFile?.(f)}\n                        onKeyDown={(e) => onItemKey(e, f)}\n                      >\n                        <td><input type=\"checkbox\" className=\"hb-ye4-check\" checked={selected.has(f.id)} aria-label={`Select ${f.name}`} onClick={(e) => e.stopPropagation()} onChange={() => toggle(f.id)} /></td>\n                        <td>\n                          <span className=\"hb-ye4-cellname\">\n                            <span className=\"hb-ye4-ico\" style={{ background: `color-mix(in srgb, ${k.color} 16%, transparent)` }}><Icon d={k.icon} color={k.color} /></span>\n                            <span>{f.name}</span>\n                          </span>\n                        </td>\n                        <td className=\"hb-ye4-hide\">{f.owner}</td>\n                        <td className=\"hb-ye4-hide\">{f.modified}</td>\n                        <td style={{ textAlign: \"right\", fontVariantNumeric: \"tabular-nums\" }}>{sub(f)}</td>\n                      </tr>\n                    );\n                  })}\n                </tbody>\n              </table>\n            )}\n          </div>\n          {selecting && (\n            <div className=\"hb-ye4-bulk\" role=\"toolbar\" aria-label=\"Bulk actions\">\n              <span className=\"hb-ye4-bulk-n\" aria-live=\"polite\">{selected.size} selected</span>\n              <span className=\"hb-ye4-sep\" />\n              <button type=\"button\"><Icon d=\"M16 6l-4-4-4 4m4-4v13M5 12v8h14v-8\" />Share</button>\n              <button type=\"button\"><Icon d=\"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Zm9 3v6m-3-3h6\" />Move</button>\n              <button type=\"button\"><Icon d=\"M12 4v12m-5-5 5 5 5-5M5 20h14\" />Download</button>\n              <button type=\"button\" data-tone=\"danger\" onClick={remove}><Icon d=\"M5 7h14M10 11v6m4-6v6M6 7l1 13h10l1-13M9 7V4h6v3\" />Delete</button>\n              <span className=\"hb-ye4-sep\" />\n              <button type=\"button\" aria-label=\"Clear selection\" onClick={clear}><Icon d=\"M6 6l12 12M18 6 6 18\" /></button>\n            </div>\n          )}\n          {dragging && (\n            <div className=\"hb-ye4-drop\" aria-hidden=\"true\">\n              <span className=\"hb-ye4-drop-ico\"><Icon d=\"M12 16V4m-5 5 5-5 5 5M5 20h14\" /></span>\n              <b>Drop to upload</b>\n              <span>Files go into {path[path.length - 1]}</span>\n            </div>\n          )}\n          <input ref={inputRef} type=\"file\" multiple hidden onChange={(e) => { addFiles(Array.from(e.target.files ?? [])); e.target.value = \"\"; }} />\n        </section>\n      </div>\n    </div>\n  );\n}\n\nexport default AppFileManager;\n"
    }
  ]
}