"use client";
function n(t) {
  if (!t) return "";
  const s = t.split(/[?#]/)[0].split("/").pop() || "", e = s.lastIndexOf(".");
  return e >= 0 ? s.substring(e + 1).toLowerCase() : "";
}
const l = /* @__PURE__ */ new Set([
  "jpg",
  "jpeg",
  "png",
  "gif",
  "webp",
  "bmp",
  "svg",
  "tiff"
]), x = /* @__PURE__ */ new Set(["pdf"]), u = /* @__PURE__ */ new Set(["txt", "md", "csv", "log", "json"]), p = /* @__PURE__ */ new Set(["mp3", "wav", "ogg", "m4a", "aac"]), m = /* @__PURE__ */ new Set(["mp4", "webm", "ogv", "mov"]);
function h(t) {
  return !!t && /^(https?:)?\/\//i.test(t);
}
function C(t) {
  return `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(t)}`;
}
function v({
  mimeType: t,
  filename: o,
  url: s
}) {
  const e = n(o || s);
  return t?.startsWith("image/") || l.has(e) ? "image" : t === "application/pdf" || x.has(e) ? "pdf" : t?.startsWith("audio/") || p.has(e) ? "audio" : t?.startsWith("video/") || m.has(e) ? "video" : u.has(e) || t?.startsWith("text/") ? "text" : "office";
}
const a = (t) => "type" in t && typeof t.type == "string" && t instanceof File, d = (t) => t.name || "url" in t && t.url || "", g = (t) => {
  if (a(t)) return t.type || "";
  const o = t.type;
  return typeof o == "string" ? o : "";
}, N = (t, o) => {
  const s = {
    pdf: { iconName: "FileText", colorClass: "text-red-600" },
    doc: { iconName: "FileText", colorClass: "text-blue-600" },
    docx: { iconName: "FileText", colorClass: "text-blue-600" },
    ppt: { iconName: "FileText", colorClass: "text-orange-600" },
    pptx: { iconName: "FileText", colorClass: "text-orange-600" },
    txt: { iconName: "FileText", colorClass: "text-gray-600" },
    md: { iconName: "FileText", colorClass: "text-gray-600" }
  }, e = (r, i) => r.forEach((c) => s[c] = i);
  return e(["xls", "xlsx", "csv"], {
    iconName: "FileSpreadsheet",
    colorClass: "text-green-600"
  }), e(["zip", "rar", "7z", "tar", "gz", "tgz"], {
    iconName: "FileArchive",
    colorClass: "text-amber-600"
  }), e(["mp3", "wav", "ogg", "flac", "m4a"], {
    iconName: "FileAudio",
    colorClass: "text-violet-600"
  }), e(["mp4", "mov", "avi", "mkv", "webm"], {
    iconName: "FileVideo",
    colorClass: "text-rose-600"
  }), e(
    [
      "js",
      "ts",
      "jsx",
      "tsx",
      "json",
      "xml",
      "yml",
      "yaml",
      "html",
      "css",
      "scss"
    ],
    {
      iconName: "FileCode",
      colorClass: "text-indigo-600"
    }
  ), t && s[t] ? s[t] : o?.startsWith("audio/") ? { iconName: "FileAudio", colorClass: "text-violet-600" } : o?.startsWith("video/") ? { iconName: "FileVideo", colorClass: "text-rose-600" } : o?.startsWith("text/") ? {
    iconName: "FileText",
    colorClass: "text-gray-600 dark:text-gray-400"
  } : o?.startsWith("image/") ? {
    iconName: "FileImage",
    colorClass: "text-teal-600 dark:text-teal-500"
  } : { iconName: "FileIcon", colorClass: "text-d-secondary-foreground" };
}, f = (t) => {
  if (!Number.isFinite(t) || t < 0) return "";
  if (t === 0) return "0B";
  const o = ["B", "KB", "MB", "GB", "TB"], s = Math.min(
    Math.floor(Math.log(t) / Math.log(1024)),
    o.length - 1
  ), e = t / 1024 ** s, r = s > 0 && e < 100 ? 2 : 0;
  return `${e.toFixed(r)}${o[s]}`;
}, F = (t) => {
  const o = n(d(t));
  if (o) return o.toUpperCase();
  const s = g(t);
  if (!s) return "";
  if (s === "application/pdf") return "PDF";
  const [e, r] = s.split("/");
  return e === "image" ? r?.toUpperCase() || "IMAGE" : e === "audio" || e === "video" || e === "text" ? e.toUpperCase() : /(officedocument|msword|ms-excel|ms-powerpoint)/.test(s) ? "OFFICE" : "";
}, w = (t) => {
  const o = a(t) ? f(t.size) : "", s = F(t);
  return { sizeLabel: o, formatLabel: s };
}, b = (t, o) => t && o ? `${t} · ${o}` : t || o || null;
export {
  p as audioExts,
  f as formatBytes,
  b as formatMetadata,
  n as getExt,
  w as getFileMetadata,
  N as getFormatIcon,
  F as getFormatLabel,
  g as getMimeFromFile,
  d as getNameOrUrl,
  C as getOfficeEmbedUrl,
  v as guessKind,
  l as imageExts,
  a as isFile,
  h as isHttpUrl,
  x as pdfExts,
  u as textExts,
  m as videoExts
};
