import {
  FileText,
  FileImage,
  FileVideo,
  FileArchive,
  File as FileIcon,
  Presentation,
  type LucideIcon,
} from "lucide-react";

export type FileIconInfo = {
  Icon: LucideIcon;
  color: string;
};

const PDF = { Icon: FileText, color: "#ef4444" };
const AI = { Icon: FileImage, color: "#f97316" };
const PPT = { Icon: Presentation, color: "#dc2626" };
const DOC = { Icon: FileText, color: "#2563eb" };
const VIDEO = { Icon: FileVideo, color: "#8b5cf6" };
const IMAGE = { Icon: FileImage, color: "#10b981" };
const ARCHIVE = { Icon: FileArchive, color: "#a16207" };
const GENERIC = { Icon: FileIcon, color: "#6b7280" };

export function fileIcon(input: {
  mime: string;
  filename: string;
}): FileIconInfo {
  const ext = input.filename.split(".").pop()?.toLowerCase() ?? "";
  const mime = (input.mime || "").toLowerCase();

  if (mime === "application/pdf" || ext === "pdf") return PDF;
  if (ext === "ai" || mime === "application/illustrator") return AI;
  if (
    mime.includes("presentation") ||
    ext === "ppt" ||
    ext === "pptx" ||
    ext === "key"
  )
    return PPT;
  if (mime.includes("word") || ext === "doc" || ext === "docx") return DOC;
  if (mime.startsWith("video/")) return VIDEO;
  if (mime.startsWith("image/")) return IMAGE;
  if (
    mime.includes("zip") ||
    mime.includes("rar") ||
    mime.includes("tar") ||
    ext === "zip" ||
    ext === "rar" ||
    ext === "7z" ||
    ext === "tar" ||
    ext === "gz"
  )
    return ARCHIVE;
  return GENERIC;
}
