"use client"; import { useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { Download, Trash2, X } from "lucide-react"; import { DocView } from "./DocView"; import { getDocumentUrl } from "@/app/lib/mikeApi"; import type { MikeDocument } from "./types"; interface Props { doc: MikeDocument | null; /** Optional specific version to display. Only honoured for DOCX. */ versionId?: string | null; /** Optional label suffix for the header (e.g. "V3"). */ versionLabel?: string | null; onClose: () => void; onDelete?: (doc: MikeDocument) => void; } export function DocViewModal({ doc, versionId, versionLabel, onClose, onDelete, }: Props) { const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); if (!doc || !mounted) return null; async function handleDownload() { if (!doc) return; const { url, filename } = await getDocumentUrl(doc.id, versionId ?? null); const a = document.createElement("a"); a.href = url; a.download = filename; a.click(); } return createPortal(