
// pwa_followups.js - list recent followups across customers
window.showFollowupsFromHash = window.showFollowupsFromHash || (async function(){
  const cont = document.getElementById('view_followups'); if(!cont) return;
  cont.innerHTML = '<div class="card"><h3>Recent Followups</h3></div><div id="followup_list" class="card"></div>';
  const list = document.getElementById('followup_list');
  list.innerHTML = '<div class="loading">Loading followups...</div>';
  try{
    const res = await fetch((window.API_BASE||'') + '/api/followups.php?action=list&page=1&per=50', { headers: Auth.authHeaders() });
    const j = await res.json();
    if(!j.status){ list.innerHTML = '<div class="error">Auth</div>'; return; }
    if(!j.data.length){ list.innerHTML = '<div class="loading">No followups</div>'; return; }
    list.innerHTML = j.data.map(f=>'<div class="card"><div><strong>'+ (f.note||'') +'</strong><div style="font-size:12px;color:#666">Cust:'+ (f.customer_id||'') + ' • ' + (f.created_at||'') +'</div></div></div>').join('');
  }catch(err){ list.innerHTML = '<div class="error">Network</div>'; }
});