/** * Toast notification and clipboard copy helpers for the dashboard. * Depends on: core/utils.js ($) */ let toastTimer = null; /** * Show a toast notification for 2.8 seconds. * @param {string} msg - Message to display. * @param {'default'|'success'|'error'} [type='default'] - Visual style class. */ function showToast(msg, type = 'default') { const el = $('toast'); if (!el) return; el.textContent = msg; el.className = 'toast show' + (type !== 'default' ? ' ' + type : ''); clearTimeout(toastTimer); toastTimer = setTimeout(() => { el.className = 'toast'; }, 2800); } /** * Copy text to the clipboard and show a success toast. * Briefly adds a `copied` class to `btnEl` for visual feedback. * @param {string} text - Text to copy. * @param {HTMLElement} [btnEl] - Optional button element to animate. */ function copyToClipboard(text, btnEl) { navigator.clipboard.writeText(text).then(() => { if (btnEl) { btnEl.classList.add('copied'); setTimeout(() => btnEl.classList.remove('copied'), 1500); } showToast('Copied to clipboard', 'success'); }).catch(() => showToast('Copy failed', 'error')); }