import {
  existsSync,
  statSync,
  readdirSync
} from "node:fs";
import { join } from "node:path";
function sizeOf(target) {
  if (!existsSync(target)) return 0;
  const st = statSync(target);
  if (st.isFile()) return st.size;
  if (!st.isDirectory()) return 0;
  let total = 0;
  const entries = readdirSync(target, { withFileTypes: true });
  for (const entry of entries) {
    const child = join(target, entry.name);
    if (entry.isFile()) {
      total += statSync(child).size;
    } else if (entry.isSymbolicLink()) {
    } else if (entry.isDirectory()) {
      total += sizeOf(child);
    }
  }
  return total;
}
const COMPONENT_DEFS = [
  { id: "cache", label: "Cache DB", subpath: "wigolo.db" },
  { id: "embeddings", label: "Embeddings index", subpath: "embeddings" },
  { id: "models", label: "ML models", subpath: "models" },
  { id: "browser", label: "Browser engine", subpath: "playwright-browsers" },
  { id: "searxng", label: "Search engine data", subpath: "searxng" }
];
async function computeStorage(dataDir) {
  const items = COMPONENT_DEFS.map(({ id, label, subpath }) => {
    const path = join(dataDir, subpath);
    const bytes = existsSync(dataDir) ? sizeOf(path) : 0;
    return { id, label, path, bytes };
  });
  const totalBytes = items.reduce((sum, i) => sum + i.bytes, 0);
  const hogs = items.filter((i) => i.bytes > 0).sort((a, b) => b.bytes - a.bytes);
  return { items, hogs, totalBytes };
}
export {
  computeStorage
};
//# sourceMappingURL=compute-storage.js.map