'use strict';

var chunkOLISEQHS_cjs = require('../chunk-OLISEQHS.cjs');
var react = require('react');
var lucideReact = require('lucide-react');
var lib = require('@djangocfg/ui-core/lib');
var jsxRuntime = require('react/jsx-runtime');

// src/tools/FileIcon/loader.ts
var cached;
var inflight = null;
async function loadMaterialIcons() {
  if (cached !== void 0) return cached;
  if (inflight) return inflight;
  inflight = (async () => {
    try {
      const specifier = "material-file-icons";
      const mod = await import(
        /* @vite-ignore */
        specifier
      );
      const fn = mod.getIcon ?? mod.default?.getIcon ?? null;
      cached = fn;
      return fn;
    } catch {
      cached = null;
      return null;
    } finally {
      inflight = null;
    }
  })();
  return inflight;
}
chunkOLISEQHS_cjs.__name(loadMaterialIcons, "loadMaterialIcons");
function getMaterialIconsSync() {
  return cached ?? null;
}
chunkOLISEQHS_cjs.__name(getMaterialIconsSync, "getMaterialIconsSync");
var SPECIAL_FOLDERS = {
  src: lucideReact.FolderCode,
  source: lucideReact.FolderCode,
  lib: lucideReact.FolderCode,
  app: lucideReact.FolderCode,
  packages: lucideReact.Package,
  node_modules: lucideReact.Package,
  vendor: lucideReact.Package,
  public: lucideReact.FolderInput,
  static: lucideReact.FolderInput,
  assets: lucideReact.Image,
  images: lucideReact.Image,
  media: lucideReact.Image,
  dist: lucideReact.FolderOutput,
  build: lucideReact.FolderOutput,
  out: lucideReact.FolderOutput,
  ".next": lucideReact.FolderOutput,
  ".nuxt": lucideReact.FolderOutput,
  ".turbo": lucideReact.FolderOutput,
  docs: lucideReact.BookOpen,
  documentation: lucideReact.BookOpen,
  tests: lucideReact.FlaskConical,
  test: lucideReact.FlaskConical,
  __tests__: lucideReact.FlaskConical,
  __test__: lucideReact.FlaskConical,
  scripts: lucideReact.Terminal,
  bin: lucideReact.Terminal,
  config: lucideReact.Settings,
  configs: lucideReact.Settings,
  ".config": lucideReact.Settings,
  ".vscode": lucideReact.Settings,
  ".idea": lucideReact.Settings,
  ".git": lucideReact.FolderGit2,
  ".github": lucideReact.Github,
  ".gitlab": lucideReact.FolderGit2
};
function resolveFolderIcon({
  name,
  isExpanded = false,
  overrides
}) {
  const key = name.trim().toLowerCase();
  if (overrides?.[key]) return overrides[key];
  const special = SPECIAL_FOLDERS[key];
  if (special) return special;
  return isExpanded ? lucideReact.FolderOpen : lucideReact.Folder;
}
chunkOLISEQHS_cjs.__name(resolveFolderIcon, "resolveFolderIcon");
function FileIcon({
  name,
  isFolder = false,
  isExpanded = false,
  size = 16,
  folderOverrides,
  className
}) {
  const [svg, setSvg] = react.useState(() => {
    if (isFolder) return null;
    const fn = getMaterialIconsSync();
    return fn ? fn(name)?.svg ?? null : null;
  });
  react.useEffect(() => {
    if (isFolder) {
      setSvg(null);
      return;
    }
    let cancelled = false;
    void loadMaterialIcons().then((fn) => {
      if (cancelled) return;
      setSvg(fn ? fn(name)?.svg ?? null : null);
    });
    return () => {
      cancelled = true;
    };
  }, [isFolder, name]);
  if (isFolder) {
    const Icon = resolveFolderIcon({
      name,
      isExpanded,
      overrides: folderOverrides
    });
    return /* @__PURE__ */ jsxRuntime.jsx(
      Icon,
      {
        className: lib.cn("shrink-0 text-amber-500", className),
        style: { width: size, height: size }
      }
    );
  }
  if (!svg) {
    return /* @__PURE__ */ jsxRuntime.jsx(
      lucideReact.File,
      {
        className: lib.cn("shrink-0 text-muted-foreground/80", className),
        style: { width: size, height: size }
      }
    );
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    "span",
    {
      role: "img",
      "aria-hidden": true,
      className: lib.cn("inline-block shrink-0", className),
      style: { width: size, height: size },
      dangerouslySetInnerHTML: { __html: svg }
    }
  );
}
chunkOLISEQHS_cjs.__name(FileIcon, "FileIcon");
function createFileIconSlot({
  getName,
  size = 16,
  folderOverrides
}) {
  return ({ node, isFolder, isExpanded }) => /* @__PURE__ */ jsxRuntime.jsx(
    FileIcon,
    {
      name: getName(node),
      isFolder,
      isExpanded,
      size,
      folderOverrides
    }
  );
}
chunkOLISEQHS_cjs.__name(createFileIconSlot, "createFileIconSlot");

exports.FileIcon = FileIcon;
exports.createFileIconSlot = createFileIconSlot;
exports.getMaterialIconsSync = getMaterialIconsSync;
exports.loadMaterialIcons = loadMaterialIcons;
exports.resolveFolderIcon = resolveFolderIcon;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map