export class FilePreview { constructor(options = {}) { this.options = { containerId: options.containerId || 'filePreviewModal', onClose: options.onClose || (() => {}), ...options }; this.modal = null; this.init(); } init() { // Create modal if it doesn't exist if (!document.getElementById(this.options.containerId)) { const modalHtml = `
`; document.body.insertAdjacentHTML('beforeend', modalHtml); } this.modal = new bootstrap.Modal(document.getElementById(this.options.containerId)); // Add event listener for modal close document.getElementById(this.options.containerId).addEventListener('hidden.bs.modal', () => { this.options.onClose(); }); } getFileIcon(filename) { const extension = filename.split('.').pop().toLowerCase(); const iconMap = { pdf: 'fa-file-pdf', doc: 'fa-file-word', docx: 'fa-file-word', xls: 'fa-file-excel', xlsx: 'fa-file-excel', ppt: 'fa-file-powerpoint', pptx: 'fa-file-powerpoint', txt: 'fa-file-alt', jpg: 'fa-file-image', jpeg: 'fa-file-image', png: 'fa-file-image', gif: 'fa-file-image', zip: 'fa-file-archive', rar: 'fa-file-archive', mp3: 'fa-file-audio', mp4: 'fa-file-video' }; return iconMap[extension] || 'fa-file'; } async previewFile(file) { const contentDiv = document.getElementById(`${this.options.containerId}Content`); const extension = file.name.split('.').pop().toLowerCase(); // Show loading spinner contentDiv.innerHTML = `Unable to load file preview. Please try downloading the file instead.
Download