export const UI = { showDashboard: () => { const db = document.getElementById('dashboardModal'); if (db) db.style.display='flex'; if (window.App && window.App.loadSessionList) window.App.loadSessionList(); }, hideDashboard: () => { const db = document.getElementById('dashboardModal'); if (db) db.style.display='none'; }, showExportModal: () => { const em = document.getElementById('exportModal'); if (em) em.style.display='flex'; if (window.App && window.App.renderDlGrid) window.App.renderDlGrid(); // Load persisted export preferences try { const prefs = JSON.parse(localStorage.getItem('colorRm_exportPrefs') || '{}'); const exHiQuality = document.getElementById('exHiQuality'); const exIncludeBackground = document.getElementById('exIncludeBackground'); const exVectorExport = document.getElementById('exVectorExport'); if (exHiQuality && prefs.hiQuality !== undefined) { exHiQuality.checked = prefs.hiQuality; } if (exIncludeBackground && prefs.includeBackground !== undefined) { exIncludeBackground.checked = prefs.includeBackground; } else if (exIncludeBackground) { // Default to checked for infinite/custom pages exIncludeBackground.checked = true; } if (exVectorExport && prefs.vectorExport !== undefined) { exVectorExport.checked = prefs.vectorExport; } } catch (e) { console.log('Could not load export preferences'); } }, toggleLoader: (show, text) => { const loader = document.getElementById('loader'); if (loader) loader.style.display = show ? 'grid' : 'none'; if(text) { const lt = document.getElementById('loadText'); if (lt) lt.innerText = text; } if(show) { const pb = document.getElementById('progBar'); if (pb) pb.style.width='0%'; const pd = document.getElementById('progDetail'); if (pd) pd.innerText=''; } }, updateProgress: (pct, msg) => { const pb = document.getElementById('progBar'); if (pb) pb.style.width = pct + '%'; const pd = document.getElementById('progDetail'); if (msg && pd) pd.innerText = msg; }, showInput: (title, placeholder, callback) => { const m = document.getElementById('inputModal'); const i = document.getElementById('inputField'); const b = document.getElementById('inputConfirmBtn'); const t = document.getElementById('inputTitle'); if (!m || !i || !b) return; if (t) t.innerText = title; i.value = ''; i.placeholder = placeholder; m.style.display = 'flex'; i.focus(); const confirm = () => { const val = i.value.trim(); if(val) { m.style.display = 'none'; callback(val); } }; b.onclick = confirm; i.onkeydown = (e) => { if(e.key==='Enter') confirm(); }; }, showToast: (msg) => { const t = document.getElementById('toast'); if (!t) return; t.innerText = msg; t.classList.add('show'); setTimeout(() => t.classList.remove('show'), 2000); }, showConfirm: (title, message, onConfirm, onCancel = null) => { return new Promise((resolve) => { // Check for existing confirm modal or create one dynamically let modal = document.getElementById('confirmModal'); if (!modal) { modal = document.createElement('div'); modal.id = 'confirmModal'; modal.className = 'overlay'; modal.innerHTML = `

`; document.body.appendChild(modal); } const titleEl = document.getElementById('confirmTitle'); const msgEl = document.getElementById('confirmMessage'); const okBtn = document.getElementById('confirmOkBtn'); const cancelBtn = document.getElementById('confirmCancelBtn'); if (titleEl) titleEl.innerText = title; if (msgEl) msgEl.innerText = message; modal.style.display = 'flex'; const cleanup = () => { modal.style.display = 'none'; okBtn.onclick = null; cancelBtn.onclick = null; }; okBtn.onclick = () => { cleanup(); if (onConfirm) onConfirm(); resolve(true); }; cancelBtn.onclick = () => { cleanup(); if (onCancel) onCancel(); resolve(false); }; }); }, showAlert: (title, message) => { return new Promise((resolve) => { let modal = document.getElementById('alertModal'); if (!modal) { modal = document.createElement('div'); modal.id = 'alertModal'; modal.className = 'overlay'; modal.innerHTML = `

`; document.body.appendChild(modal); } const titleEl = document.getElementById('alertTitle'); const msgEl = document.getElementById('alertMessage'); const okBtn = document.getElementById('alertOkBtn'); if (titleEl) titleEl.innerText = title; if (msgEl) msgEl.innerText = message; modal.style.display = 'flex'; okBtn.onclick = () => { modal.style.display = 'none'; resolve(); }; }); }, showPrompt: (title, placeholder, defaultValue = '') => { return new Promise((resolve) => { let modal = document.getElementById('promptModal'); if (!modal) { modal = document.createElement('div'); modal.id = 'promptModal'; modal.className = 'overlay'; modal.innerHTML = `

`; document.body.appendChild(modal); } const titleEl = document.getElementById('promptTitle'); const inputEl = document.getElementById('promptInput'); const okBtn = document.getElementById('promptOkBtn'); const cancelBtn = document.getElementById('promptCancelBtn'); if (titleEl) titleEl.innerText = title; if (inputEl) { inputEl.placeholder = placeholder; inputEl.value = defaultValue; } modal.style.display = 'flex'; inputEl.focus(); const cleanup = () => { modal.style.display = 'none'; okBtn.onclick = null; cancelBtn.onclick = null; inputEl.onkeydown = null; }; const submit = () => { const val = inputEl.value; cleanup(); resolve(val); }; okBtn.onclick = submit; cancelBtn.onclick = () => { cleanup(); resolve(null); }; inputEl.onkeydown = (e) => { if(e.key==='Enter') submit(); }; }); }, setSyncStatus: (status) => { const el = document.getElementById('syncStatus'); if (!el) return; if (status === 'saved') { el.innerHTML = ' Synced'; setTimeout(() => { if(el.innerText.includes('Synced')) el.innerHTML = ''; }, 3000); } else if (status === 'syncing') { el.innerHTML = ' Saving'; } else if (status === 'offline') { el.innerHTML = ' Offline'; } else if (status === 'new') { el.innerHTML = ' New Project'; setTimeout(() => el.innerHTML = '', 5000); } } };