// Groma data — Lagos LGAs, pipeline plots, demo data. All illustrative.

const LAGOS_BBOX = { west: 3.28, east: 3.66, south: 6.39, north: 6.63 };

const LGAS = [
  { id:"ikoyi", name:"Ikoyi", tier:"prime", pop:118000, medianIncomeNGN:2400000,
    pts:[[3.43,6.456],[3.46,6.455],[3.465,6.442],[3.44,6.437],[3.425,6.44],[3.42,6.45]] },
  { id:"vi", name:"Victoria Island", tier:"prime", pop:92000, medianIncomeNGN:2100000,
    pts:[[3.40,6.438],[3.43,6.438],[3.445,6.422],[3.42,6.415],[3.40,6.418]] },
  { id:"lekki1", name:"Lekki Phase 1", tier:"prime", pop:180000, medianIncomeNGN:1800000,
    pts:[[3.45,6.445],[3.49,6.448],[3.50,6.432],[3.47,6.425],[3.45,6.428]] },
  { id:"oniru", name:"Oniru", tier:"prime", pop:46000, medianIncomeNGN:1900000,
    pts:[[3.435,6.44],[3.46,6.44],[3.46,6.426],[3.44,6.42]] },
  { id:"ibejulekki", name:"Ibeju-Lekki", tier:"growth", pop:310000, medianIncomeNGN:720000,
    pts:[[3.52,6.468],[3.65,6.47],[3.66,6.44],[3.58,6.414],[3.52,6.428]] },
  { id:"ajah", name:"Ajah", tier:"growth", pop:240000, medianIncomeNGN:840000,
    pts:[[3.56,6.478],[3.62,6.47],[3.61,6.455],[3.55,6.455]] },
  { id:"ikeja", name:"Ikeja", tier:"mature", pop:360000, medianIncomeNGN:1100000,
    pts:[[3.32,6.57],[3.38,6.572],[3.40,6.612],[3.34,6.625],[3.305,6.6]] },
  { id:"yaba", name:"Yaba", tier:"mature", pop:220000, medianIncomeNGN:880000,
    pts:[[3.36,6.5],[3.40,6.51],[3.40,6.535],[3.36,6.528]] },
  { id:"surulere", name:"Surulere", tier:"mature", pop:310000, medianIncomeNGN:760000,
    pts:[[3.33,6.485],[3.37,6.49],[3.37,6.51],[3.33,6.505]] },
  { id:"mainland", name:"Lagos Mainland", tier:"mature", pop:290000, medianIncomeNGN:720000,
    pts:[[3.29,6.478],[3.345,6.49],[3.36,6.53],[3.32,6.54],[3.285,6.515]] },
  { id:"island", name:"Lagos Island", tier:"prime", pop:210000, medianIncomeNGN:1100000,
    pts:[[3.385,6.45],[3.42,6.452],[3.42,6.44],[3.385,6.438]] },
  { id:"apapa", name:"Apapa", tier:"industrial", pop:220000, medianIncomeNGN:620000,
    pts:[[3.34,6.44],[3.38,6.445],[3.38,6.42],[3.34,6.418]] },
  { id:"ojo", name:"Ojo", tier:"emerging", pop:410000, medianIncomeNGN:420000,
    pts:[[3.18,6.47],[3.22,6.48],[3.22,6.455],[3.18,6.45]] },
  { id:"alimosho", name:"Alimosho", tier:"emerging", pop:620000, medianIncomeNGN:560000,
    pts:[[3.24,6.58],[3.30,6.59],[3.30,6.555],[3.24,6.55]] },
];

const PIPELINE = [
  { id:"p1", name:"Bourdillon Tower", lga:"ikoyi", status:"building", units:48, valueNGN:12_000_000_000, lng:3.438, lat:6.452 },
  { id:"p2", name:"Eko Atlantic West", lga:"vi", status:"building", units:210, valueNGN:58_000_000_000, lng:3.418, lat:6.418 },
  { id:"p3", name:"Chevron Gardens", lga:"lekki1", status:"completed", units:84, valueNGN:7_800_000_000, lng:3.478, lat:6.440 },
  { id:"p4", name:"Oniru Pearl", lga:"oniru", status:"stalled", units:36, valueNGN:4_200_000_000, lng:3.448, lat:6.432 },
  { id:"p5", name:"Ajah Heights", lga:"ajah", status:"planned", units:160, valueNGN:6_400_000_000, lng:3.595, lat:6.466 },
  { id:"p6", name:"Lakowe Villas", lga:"ibejulekki", status:"planned", units:240, valueNGN:12_000_000_000, lng:3.620, lat:6.450 },
  { id:"p7", name:"Yaba Grand", lga:"yaba", status:"building", units:72, valueNGN:3_800_000_000, lng:3.380, lat:6.512 },
  { id:"p8", name:"Allen Crest", lga:"ikeja", status:"completed", units:52, valueNGN:4_100_000_000, lng:3.345, lat:6.596 },
  { id:"p9", name:"Marina Quarter", lga:"island", status:"building", units:120, valueNGN:9_400_000_000, lng:3.398, lat:6.449 },
  { id:"p10", name:"Apapa Logistics Park", lga:"apapa", status:"planned", units:0, valueNGN:28_000_000_000, lng:3.365, lat:6.435 },
  { id:"p11", name:"Surulere Residences", lga:"surulere", status:"building", units:64, valueNGN:2_800_000_000, lng:3.350, lat:6.498 },
  { id:"p12", name:"Lekki Corniche", lga:"lekki1", status:"planned", units:180, valueNGN:11_000_000_000, lng:3.488, lat:6.432 },
  { id:"p13", name:"Ajah Gateway", lga:"ajah", status:"stalled", units:120, valueNGN:5_600_000_000, lng:3.585, lat:6.462 },
  { id:"p14", name:"Magodo Park", lga:"ikeja", status:"building", units:44, valueNGN:3_200_000_000, lng:3.365, lat:6.605 },
];

const DEMOGRAPHY_BY_LGA = Object.fromEntries(LGAS.map(l => [l.id, {
  pop: l.pop,
  medianAge: l.tier === "growth" ? 27 : l.tier === "prime" ? 36 : l.tier === "emerging" ? 24 : 32,
  households: Math.round(l.pop / 3.8),
  medianIncomeNGN: l.medianIncomeNGN,
  sectors: l.tier === "prime"
    ? { finance: 32, tech: 18, oilgas: 14, services: 26, other: 10 }
    : l.tier === "industrial"
      ? { logistics: 38, manufacturing: 22, services: 18, informal: 14, other: 8 }
      : { services: 30, informal: 26, manufacturing: 18, finance: 12, other: 14 },
}]));

const COMPETITORS_BY_LGA = Object.fromEntries(LGAS.map(l => [l.id, {
  activeListings: Math.round(l.pop * 0.002 + Math.random()*40),
  agentCount: Math.round(l.pop * 0.0004 + 8),
  askingMedianNGN: l.tier === "prime" ? 380_000_000 : l.tier === "growth" ? 120_000_000 : l.tier === "emerging" ? 28_000_000 : 65_000_000,
  daysOnMarket: l.tier === "prime" ? 42 : l.tier === "growth" ? 78 : 110,
}]));

const PORTFOLIO = [
  { id:"LAG-001A", addr:"14 Bourdillon Rd", lga:"Ikoyi",       type:"Residential", collateralNGN: 2_400_000_000, lastValueNGN: 2_580_000_000, status:"ok",   ltv: 52 },
  { id:"LAG-002B", addr:"22 Ahmadu Bello Way", lga:"V.I.",     type:"Residential", collateralNGN:   980_000_000, lastValueNGN:   924_500_000, status:"warn", ltv: 68 },
  { id:"LAG-003C", addr:"Plot 18, Lekki Phase 1", lga:"Lekki1",type:"Residential", collateralNGN:   640_000_000, lastValueNGN:   712_000_000, status:"ok",   ltv: 44 },
  { id:"LAG-004D", addr:"Oniru Pearl, Blk 2", lga:"Oniru",     type:"Mixed-use",   collateralNGN: 1_240_000_000, lastValueNGN: 1_060_000_000, status:"risk", ltv: 81 },
  { id:"LAG-005E", addr:"Marina Quarter T3", lga:"L. Island",  type:"Commercial",  collateralNGN: 4_200_000_000, lastValueNGN: 4_380_000_000, status:"ok",   ltv: 58 },
  { id:"LAG-006F", addr:"Ajah Gateway B7",  lga:"Ajah",        type:"Residential", collateralNGN:   220_000_000, lastValueNGN:   184_000_000, status:"risk", ltv: 86 },
  { id:"LAG-007G", addr:"Allen Crest A2",   lga:"Ikeja",       type:"Residential", collateralNGN:   480_000_000, lastValueNGN:   502_000_000, status:"ok",   ltv: 49 },
  { id:"LAG-008H", addr:"Apapa Logistics Pk",lga:"Apapa",      type:"Industrial",  collateralNGN: 3_800_000_000, lastValueNGN: 3_520_000_000, status:"warn", ltv: 71 },
];

const fmtNGN = (n) => {
  if (n >= 1e9) return `₦ ${(n/1e9).toFixed(2)}B`;
  if (n >= 1e6) return `₦ ${(n/1e6).toFixed(0)}M`;
  return `₦ ${n.toLocaleString()}`;
};
const fmtN = (n) => n.toLocaleString('en-NG');

Object.assign(window, { LAGOS_BBOX, LGAS, PIPELINE, DEMOGRAPHY_BY_LGA, COMPETITORS_BY_LGA, PORTFOLIO, fmtNGN, fmtN });
