import { DirectusClient } from '../services/directus-client.js'; import { FileDownloader } from '../services/file-downloader.js'; import { DocumentFormatter } from '../utils/document-formatter.js'; export class DocumentCardView { constructor(item) { this.item = item; this.title = item.nama_berkas; this.tags = DocumentFormatter.parseTags(item.tag); this.category = DocumentFormatter.categoryFromTags(this.tags); this.fileType = DocumentFormatter.fileTypeFromName(this.title); this.assetUrl = DirectusClient.assetUrl(item.file); this.viewerUrl = DirectusClient.viewerUrl(item); this.downloadName = DocumentFormatter.downloadFilename(this.title, this.fileType); this.dateIso = item.tanggal_upload || ''; this.dateKey = this.dateIso ? this.dateIso.substring(0, 10) : ''; } render() { const card = document.createElement('article'); card.className = 'document-card'; card.dataset.date = this.dateKey; const typeUpper = this.fileType.toUpperCase(); const typeClass = this.fileType === 'pdf' ? 'doc-type-pdf' : 'doc-type-docx'; const iconClass = this.fileType === 'pdf' ? 'fas fa-file-pdf' : 'fas fa-file-word'; const formattedDate = DocumentFormatter.formatDate(this.dateIso); const safeTitle = DocumentFormatter.escapeHtml(this.title); const safeViewerUrl = DocumentFormatter.escapeAttr(this.viewerUrl); const safeAssetUrl = DocumentFormatter.escapeAttr(this.assetUrl); // Build tag badges HTML. const tagBadgesHtml = this.tags.length ? `
` : ''; card.innerHTML = `