/* portal/notifications/public/notifications.js — 알림 센터: 분류·읽지 않음 필터, 읽음 처리, 사건 반복 횟수, 조치 링크. */ (() => { const list = document.getElementById('nlist'); const tabs = document.getElementById('ncats'); if (!list) return; let cat = ''; let unread = false; const SEV = { critical: 'failed', warning: 'warning', info: 'info' }; async function load() { try { const d = await aw.api('GET', `/api/notifications?category=${encodeURIComponent(cat)}&unread=${unread ? 1 : 0}`); if (!d.items.length) return aw.state(list, 'empty'); list.innerHTML = `
` + d.items.map((n) => `
${n.severity === 'critical' ? '⚠' : n.severity === 'warning' ? '!' : 'ⓘ'} ${aw.esc(n.categoryLabel)} ${n.mandatory ? '필수' : ''} ${n.count > 1 ? `${n.count}회 반복` : ''} ${n.state === 'resolved' ? '✔ 해결됨' : ''}
${aw.esc(aw.fmt(n.lastAt))}

${aw.esc(n.title)}

${n.body ? `

${aw.esc(n.body)}

` : ''}${n.actionRequired ? `

필요한 조치: ${aw.esc(n.actionRequired)}

` : ''}
${n.link ? `조치 화면으로` : ''}${!n.readAt ? `` : ''}
`).join(''); list.querySelectorAll('[data-read]').forEach((b) => { b.onclick = async () => { await aw.api('POST', `/api/notifications/${b.dataset.read}/read`); load(); }; }); document.getElementById('read-all').onclick = async () => { await aw.api('POST', '/api/notifications/read-all'); load(); }; } catch (err) { aw.state(list, err.status === 403 ? 'forbidden' : 'failed', err.message, { retry: load }); } } tabs.addEventListener('click', (e) => { const a = e.target.closest('a'); if (!a) return; e.preventDefault(); tabs.querySelectorAll('a').forEach((x) => x.classList.remove('on')); a.classList.add('on'); if (a.dataset.unread) { unread = true; cat = ''; } else { unread = false; cat = a.dataset.cat || ''; } load(); }); load(); })();