let currentEntries = []; let seenEntryIds = new Set(); let highlightNewIds = new Set(); let highlightClearTimer = null; let editId = null; let editGroups = []; let editModules = []; let moduleNames = new Map(); let moduleFilterId = ''; let moduleSearchTimer = null; let editModuleSearchTimer = null; let modulesLoaded = false; let groupsLoaded = false; let studentsLoaded = false; const PAGE_SIZE = 20; let page = 1; let totalEntries = 0; let searchTimer = null; let view = localStorage.getItem('journalView') === 'cards' ? 'cards' : 'list'; let aiCorrecting = false; let editDeletePhoto = false; let editAiSuggestion = null; let linkSettings = null; async function loadLinkSettings() { if (!linkSettings) { const res = await fetch(`${API}/api/settings`, { headers: hdr() }); linkSettings = await res.json().catch(() => ({})); } return linkSettings; } function isImageFile(name) { return /\.(jpe?g|jfif|png|gif|webp|bmp|avif|svg|ico)$/i.test(name || ''); } function isPlayableVideoFile(name) { return /\.(mp4|m4v|webm|ogv)$/i.test(name || ''); } function isVideoFile(name) { return /\.(mp4|m4v|webm|ogv|mov|mkv|avi|mpeg|mpg|3gp|ts)$/i.test(name || ''); } function mainPhotoPath(e) { if (e.photo_path) return e.photo_path; if (e.photos && e.photos.length) return e.photos[0].photo_path; return null; } function openReportCard(id) { const e = currentEntries.find(x => x.id === id); if (!e) return; const mp = mainPhotoPath(e); const photo = document.getElementById('reportCardPhoto'); const noPhoto = document.getElementById('reportCardNoPhoto'); if (mp) { photo.src = thumbSrc(mp); photo.dataset.img = `${API}${mp}`; photo.alt = e.student_name || ''; photo.hidden = false; noPhoto.hidden = true; } else { photo.src = ''; delete photo.dataset.img; photo.alt = ''; photo.hidden = true; noPhoto.hidden = false; } document.getElementById('reportCardName').textContent = e.student_name || ''; document.getElementById('reportCardText').textContent = e.description || ''; const groupBadge = document.getElementById('reportCardTime'); const group = e.group_name || ''; groupBadge.textContent = group; groupBadge.parentElement.hidden = !group; const toolBadge = document.getElementById('reportCardModule').parentElement; const tool = e.module_name || ''; document.getElementById('reportCardModule').textContent = tool; toolBadge.hidden = !tool; document.getElementById('reportCardModal').classList.add('open'); } function closeReportCard() { document.getElementById('reportCardModal').classList.remove('open'); } function filesHTML(files) { if (!files || !files.length) return ''; return `