'use strict';

var chunkWGEGR3DF_cjs = require('../chunk-WGEGR3DF.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;
}
chunkWGEGR3DF_cjs.__name(loadMaterialIcons, "loadMaterialIcons");
function getMaterialIconsSync() {
  return cached ?? null;
}
chunkWGEGR3DF_cjs.__name(getMaterialIconsSync, "getMaterialIconsSync");
function FileIcon({
  name,
  isFolder = false,
  isExpanded = false,
  size = 16,
  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 = isExpanded ? lucideReact.FolderOpen : lucideReact.Folder;
    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 }
    }
  );
}
chunkWGEGR3DF_cjs.__name(FileIcon, "FileIcon");
function createFileIconSlot({
  getName,
  size = 16
}) {
  return ({ node, isFolder, isExpanded }) => /* @__PURE__ */ jsxRuntime.jsx(
    FileIcon,
    {
      name: getName(node),
      isFolder,
      isExpanded,
      size
    }
  );
}
chunkWGEGR3DF_cjs.__name(createFileIconSlot, "createFileIconSlot");

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