import { useCallback, useEffect, useRef, useState } from 'react' import { ArrowLeft, Download, File, Folder, FolderOpen, LoaderCircle, Eye, X, Image, FileText, ShieldCheck, Maximize2, Minimize2 } from 'lucide-react' import { Button } from '@/components/ui/button' import { drive, message, publicFileUrl } from '@/api/client' import { fmtSize } from '@/lib/drive-format' function typeOf(item) { const n = (item.name || '').toLowerCase(), m=(item.mime_type || '').toLowerCase() if(m.startsWith('image/') && m!=='image/svg+xml' || /\.(png|jpe?g|gif|webp|bmp|avif)$/.test(n)) return 'image' if(n.endsWith('.docx'))return 'word' if(m==='application/pdf' || n.endsWith('.pdf'))return 'pdf' if(m.startsWith('video/') || /\.(mp4|webm|mov|m4v|ogv)$/.test(n))return 'video' if(m.startsWith('audio/') || /\.(mp3|ogg|wav|m4a|flac|aac)$/.test(n))return 'audio' if(m.startsWith('text/') || /\.(txt|md|json|csv|xml|log|py|js|css)$/.test(n))return 'text' return null } function Viewer({item,token,fullscreen}) { const kind=typeOf(item) const src=publicFileUrl(token,item.id,true) const mediaHeight=fullscreen?'max-h-[calc(100dvh-5rem)]':'max-h-[72vh]' const frameHeight=fullscreen?'h-[calc(100dvh-5rem)]':'h-[70vh]' if(kind==='image')return {item.name} if(kind==='word')return