
// pwa_dashboard.js - simple KPI dashboard and quick access
window.loadDashboard = window.loadDashboard || (async function(){
  const cont = document.getElementById('view_dashboard'); if(!cont) return;
  cont.innerHTML = '<div class="card"><h3>Dashboard</h3><div id="kpi_area">Loading KPIs...</div></div>';
  try{
    const res = await fetch((window.API_BASE||'') + '/api/kpi.php?action=summary', { headers: Auth.authHeaders() });
    if(!res.ok){ document.getElementById('kpi_area').innerHTML = 'KPI load failed'; return; }
    const j = await res.json();
    if(!j.status){ document.getElementById('kpi_area').innerHTML = 'Auth required'; return; }
    const k = j.kpi || {};
    document.getElementById('kpi_area').innerHTML = '<div style="display:flex;gap:12px"><div class="card">Customers: '+ (k.total_customers||0) +'</div></div>';
  }catch(err){ document.getElementById('kpi_area').innerHTML = 'Network'; }
});