import { api } from '../api.js'; import { BaseFileList } from './base-file-list.js'; export class DeletedFiles extends BaseFileList { constructor() { super(); } async connectedCallback() { super.connectedCallback(); await this.loadDeletedFiles(); } async loadDeletedFiles() { try { this.files = await api.listDeletedFiles(); this.folders = []; this.selectedFiles.clear(); this.selectedFolders.clear(); this.render(); } catch (error) { console.error('Failed to load deleted files:', error); this.innerHTML = '

Failed to load deleted files.

'; } } render() { const hasSelected = this.selectedFiles.size > 0; const totalSelected = this.selectedFiles.size; const allSelected = this.files.length > 0 && this.selectedFiles.size === this.files.length; const someSelected = hasSelected && !allSelected; if (this.files.length === 0) { this.innerHTML = `

Deleted Files

No deleted files found.

`; return; } this.innerHTML = `

Deleted Files

${this.files.length > 0 ? `
` : ''}
${hasSelected ? `
` : ''}
${this.files.map(file => this.renderDeletedFile(file)).join('')}
`; this.attachListeners(); this.updateIndeterminateState(); } renderDeletedFile(file) { const isSelected = this.selectedFiles.has(file.id); const icon = this.getFileIcon(file.mime_type); const size = this.formatFileSize(file.size); const deletedAt = file.deleted_at ? new Date(file.deleted_at).toLocaleString() : 'N/A'; return `
${icon}
${file.name}
${size}
Deleted: ${deletedAt}
`; } createBatchActionsBar() { const container = this.querySelector('.file-list-container'); const header = container.querySelector('.file-list-header'); const batchBar = document.createElement('div'); batchBar.className = 'batch-actions'; batchBar.innerHTML = ` `; header.insertAdjacentElement('afterend', batchBar); } attachListeners() { const batchRestoreBtn = this.querySelector('#batch-restore-btn'); if (batchRestoreBtn) { batchRestoreBtn.addEventListener('click', () => this.handleBatchRestore()); } } async handleBatchRestore() { const totalSelected = this.selectedFiles.size; if (totalSelected === 0) return; if (!confirm(`Restore ${totalSelected} files?`)) return; try { for (const fileId of this.selectedFiles) { await api.restoreFile(fileId); } document.dispatchEvent(new CustomEvent('show-toast', { detail: { message: 'Files restored successfully!', type: 'success' } })); await this.loadDeletedFiles(); } catch (error) { document.dispatchEvent(new CustomEvent('show-toast', { detail: { message: 'Failed to restore files: ' + error.message, type: 'error' } })); } } async handleAction(action, id) { try { if (action === 'restore') { await api.restoreFile(id); document.dispatchEvent(new CustomEvent('show-toast', { detail: { message: 'File restored successfully!', type: 'success' } })); await this.loadDeletedFiles(); } } catch (error) { document.dispatchEvent(new CustomEvent('show-toast', { detail: { message: 'Action failed: ' + error.message, type: 'error' } })); } } } customElements.define('deleted-files', DeletedFiles);