import type { EvidenceItemMeta } from "@/lib/applicationEvidenceApi";

export function isPdfEvidence(meta: EvidenceItemMeta): boolean {
  const m = (meta.mimeType || "").toLowerCase();
  if (m.includes("pdf")) return true;
  const n = (meta.originalName || "").toLowerCase();
  const k = (meta.storageKey || "").toLowerCase();
  return n.endsWith(".pdf") || k.includes(".pdf");
}

export function isImageEvidence(meta: EvidenceItemMeta): boolean {
  const m = (meta.mimeType || "").toLowerCase();
  if (m.startsWith("image/")) return true;
  const u = (meta.viewUrl || meta.downloadUrl || "").toLowerCase();
  return /\.(png|jpe?g|gif|webp)($|\?|&)/.test(u);
}

/** Presigned URL suited for an iframe PDF viewer (inline disposition when available). */
export function pdfIframeSrc(meta: EvidenceItemMeta): string | null {
  if (!isPdfEvidence(meta)) return null;
  return meta.viewUrl || meta.downloadUrl;
}

export function imagePreviewSrc(meta: EvidenceItemMeta): string | null {
  if (!isImageEvidence(meta)) return null;
  return meta.downloadUrl || meta.viewUrl;
}
