// Generated, do not edit. sha256:ce839cfe04c94b47ff548f20a8992356bcbc456e5e878e1829f94a38a663c5f1 import { currentNotifications, notificationDetail, dismissNotification } from '../data/notifications.js'; import { localDateNl } from '../../shared/time.js'; import { t } from '../i18n/index.js'; import { TARGETS, NOTIFICATION_TARGETS, NOTIFICATION_PRIORITY, targetHash } from '../../shared/config.js'; import { CHECK, CHEVRON_RIGHT } from '../ui/icons.js'; import { esc } from '../ui/escape.js'; import { taskCardHtml, nothingPendingHtml } from '../ui/task-card.js'; const targetFor = kind => targetHash(NOTIFICATION_TARGETS[kind] || TARGETS.ACTIONS); const rank = kind => NOTIFICATION_PRIORITY.indexOf(kind); async function detailFor(n) { if (n.kind === 'schedule_ended') { const d = await notificationDetail(n); if (!d) return ''; return `${d.account} ยท ${d.asset}${d.extra ? ` +${d.extra}` : ''}`; } return t('notify.hint.' + n.kind); } async function rowHtml(n) { const target = targetFor(n.kind); const detail = await detailFor(n); const date = localDateNl(n.createdAt); const info = n.kind === 'schedule_ended' ? ' is-info' : ''; return `
${t('notify.' + n.kind)}
${detail ? `
${esc(detail)}
` : ''}
${date || ''}
`; } export async function renderNotifications(host, onChanged) { const rerender = () => renderNotifications(host, onChanged); const items = await currentNotifications(); const sorted = [...items].sort((a, b) => rank(a.kind) - rank(b.kind)); const body = sorted.length === 0 ? nothingPendingHtml() : `
${(await Promise.all(sorted.map(rowHtml))).join('')}
`; host.innerHTML = taskCardHtml({ title: t('notify.title'), body }); host.querySelectorAll('[data-dismiss]').forEach(b => b.onclick = async e => { e.stopPropagation(); await dismissNotification(Number(b.dataset.dismiss)); (onChanged || rerender)(); }); host.querySelectorAll('.notify-row').forEach(row => { const go = () => { location.hash = row.dataset.target; }; row.onclick = e => { if (e.target.closest('[data-dismiss]') || e.target.closest('a')) return; go(); }; row.onkeydown = e => { if (e.key === 'Enter' && e.target === row) go(); }; }); }