// Regions group states for the map's regional views.
// Extensible: add a region and its member states here. The Midwest is the
// launch region (the one we announce); other drillable states stay live
// underneath and still work when reached.
const REGIONS = {
  midwest: { key: 'midwest', name: 'Midwest', states: ['Michigan', 'Wisconsin', 'Minnesota'] },
  // Future: northeast: { key:'northeast', name:'Northeast', states:['Pennsylvania', ...] }, etc.
};
const REGION_ORDER = ['midwest'];

const STATE_REGION = {};
Object.keys(REGIONS).forEach(k => REGIONS[k].states.forEach(s => { STATE_REGION[s] = k; }));

function fwRegionOf(name) { return STATE_REGION[name] || null; }
function fwRegionStates(key) { return (REGIONS[key] || {}).states || []; }
function fwRegionTotals(key, year) {
  let paid = 0, claims = 0, providers = 0;
  fwRegionStates(key).forEach(name => {
    const s = window.STATE_INFO && window.STATE_INFO[name];
    if (s) { paid += (s.paid[year] || 0); claims += (s.claims[year] || 0); providers += (s.providers[year] || 0); }
  });
  return { paid, claims, providers };
}

Object.assign(window, { REGIONS, REGION_ORDER, fwRegionOf, fwRegionStates, fwRegionTotals });
