
// ─── Project detail data ─────────────────────────────────────────────
// Rich per-project overrides for flagship projects, merged over a sensible
// default so every card in the portfolio opens a coherent page.

const slug = (s) => String(s).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');

// best (investor TYPE id) → invest PROFILE id used in the Invest tab
const BEST_TO_PROFILE = { visionary: 'growth', pragmatist: 'safety', early: 'growth', rent: 'lifestyle' };

const PD_DEFAULT = {
  district: 'Panama City',
  region: 'Panama',
  coords: '8.98° N · 79.52° W',
  sketch: 'StandardTower',
  tagline: 'A structured position in a market we know intimately.',
  liveIt: {
    units: 148,
    priceFrom: '$195,000',
    priceRange: '$195K — $520K',
    blurb: 'Designed around the resident, not the brochure — light, air, and a building that works as well at 7am as it does at midnight.',
    amenities: ['Rooftop pool & sun deck', 'Fully-equipped gym', 'Co-working lounge', 'Social & events room', '24/7 concierge & security', 'Visitor parking', 'Pet-friendly areas', 'EV charging'],
    nearby: [
      { name: 'Multiplaza Mall', dist: '6 min' },
      { name: 'Metro station', dist: '4 min' },
      { name: 'Tocumen Airport', dist: '22 min' },
      { name: 'Punta Pacífica Hospital', dist: '9 min' },
      { name: 'Cinta Costera', dist: '8 min' },
      { name: 'International school', dist: '12 min' },
    ],
    distribution: [
      { type: 'Studio',     cfg: '1 bath',        sqm: '46 m²',  count: 32, price: 'from $195K' },
      { type: '1 Bedroom',  cfg: '1 bed · 1 bath', sqm: '64 m²',  count: 64, price: 'from $258K' },
      { type: '2 Bedroom',  cfg: '2 bed · 2 bath', sqm: '92 m²',  count: 42, price: 'from $372K' },
      { type: 'Penthouse',  cfg: '3 bed · 3 bath', sqm: '148 m²', count: 10, price: 'from $520K' },
    ],
  },
  investIt: {
    accessTier: 'Pre-sale',
    entryPrice: 195000,
    estRoi: '~24%',
    annualized: '~10% p.a.',
    horizon: 4,
    currency: 'USD',
    constructionMonths: 28,
    completionPct: 22,
    delivery: 'Q4 2027',
    appreciation: 0.07,
  },
};

const PD_DETAILS = {
  'Bioma': {
    developer: 'TheVelopers', district: 'Costa del Este', coords: '9.01° N · 79.46° W',
    mapQuery: 'PH Bioma Costa del Este Panama', mapLabel: 'Costa del Este, Panama City',
    sketch: 'StandardTower', best: 'pragmatist',
    tagline: 'Reliable ground in the financial heartland of the republic.',
    liveIt: {
      units: 184, priceFrom: '$220,000', priceRange: '$220K — $640K',
      blurb: 'Costa del Este is the most established premium district in Panama City. Bioma is built for the resident who wants the address to do quiet, permanent work.',
      amenities: ['Rooftop infinity pool', 'Wellness spa & sauna', 'Two-level fitness club', 'Business centre & co-working', 'Gourmet social room', '24/7 concierge & valet', 'Children\u2019s play area', 'Three-level parking'],
      nearby: [
        { name: 'Town Center mall', dist: '3 min' }, { name: 'Metro Line 2', dist: '7 min' },
        { name: 'Tocumen Airport', dist: '15 min' }, { name: 'Pacífica Hospital', dist: '10 min' },
        { name: 'Intl. school', dist: '5 min' }, { name: 'Costa del Este beach', dist: '6 min' },
      ],
      distribution: [
        { type: 'Studio',    cfg: '1 bath',         sqm: '48 m²',  count: 40, price: 'from $220K' },
        { type: '1 Bedroom', cfg: '1 bed · 1 bath', sqm: '68 m²',  count: 72, price: 'from $288K' },
        { type: '2 Bedroom', cfg: '2 bed · 2 bath', sqm: '98 m²',  count: 60, price: 'from $410K' },
        { type: 'Penthouse', cfg: '3 bed · 3.5 bath', sqm: '162 m²', count: 12, price: 'from $640K' },
      ],
    },
    investIt: { accessTier: 'Lista Cero', entryPrice: 220000, estRoi: '~28%', annualized: '~11% p.a.', horizon: 5, currency: 'USD', constructionMonths: 26, completionPct: 8, delivery: '2026' },
  },

  'Mova': {
    developer: 'Pacific Developers', district: 'Obarrio', region: 'Panama',
    coords: '8.98° N · 79.52° W', mapQuery: 'MOVA Obarrio Panama City Panama', mapLabel: 'Obarrio, Panama City', sketch: 'LowRiseBuilding', best: 'early',
    tagline: 'Urban life in Obarrio, redesigned around movement, design and daily convenience.',
    liveIt: {
      units: 96, priceFrom: '$145,000', priceRange: '$145K — $390K',
      blurb: 'Mova sits in Obarrio, one of Panama City’s most connected districts. It is built around urban movement, mixed-use convenience and a design-led residential experience.',
      amenities: ['Design-led residences', 'Wellness amenities', 'Resident lounge', 'Co-working areas', 'Retail and hospitality mix', 'Concierge', 'Urban gardens', 'Walkable Obarrio access'],
      nearby: [
        { name: 'Soho City Center', dist: '4 min' }, { name: 'Financial district', dist: '3 min' },
        { name: 'Cinta Costera', dist: '7 min' }, { name: 'Multiplaza Mall', dist: '8 min' },
        { name: 'Casco Viejo', dist: '15 min' }, { name: 'Tocumen Airport', dist: '22 min' },
      ],
      distribution: [
        { type: 'Studio loft', cfg: '1 bath',         sqm: '52 m²',  count: 36, price: 'from $145K' },
        { type: '1 Bedroom',   cfg: '1 bed · 1 bath', sqm: '74 m²',  count: 44, price: 'from $208K' },
        { type: '2 Bed villa',  cfg: '2 bed · 2 bath', sqm: '116 m²', count: 16, price: 'from $390K' },
      ],
    },
    investIt: { accessTier: 'Under construction', entryPrice: 145000, estRoi: '8–14%', annualized: '~9% p.a.', horizon: 6, currency: 'USD', constructionMonths: 18, completionPct: 54, delivery: 'Q1 2027' },
  },

  'Playa Escondida': {
    developer: 'Playa Escondida', district: 'María Chiquita', region: 'Colón', coords: '9.43° N · 79.77° W',
    mapQuery: 'Playa Escondida Resort & Marina Maria Chiquita Colon Panama', mapLabel: 'María Chiquita, Colón',
    sketch: 'CoastalTower', best: 'pragmatist',
    tagline: 'A Caribbean resort thesis on the Colón coast, structured for lifestyle and long-term value.',
    liveIt: {
      units: 132, priceFrom: '$178,000', priceRange: '$178K — $560K',
      blurb: 'Playa Escondida is positioned in María Chiquita, Colón, on Panama’s Caribbean side — a resort-style coastal address with beach, marina and wellness infrastructure.',
      amenities: ['Oceanfront infinity pool', 'Private beach boardwalk', 'Spa & thermal circuit', 'Surf & paddle centre', 'Sunset rooftop bar', 'Concierge & housekeeping', 'Kids\u2019 club', 'Covered parking'],
      nearby: [
        { name: 'María Chiquita', dist: '4 min' }, { name: 'Portobelo', dist: '20 min' },
        { name: 'Colón city', dist: '30 min' }, { name: 'Panama City', dist: '60 min' },
        { name: 'Agua Clara locks', dist: '35 min' }, { name: 'Caribbean coast', dist: '1 min' },
      ],
      distribution: [
        { type: 'Studio',    cfg: '1 bath',         sqm: '50 m²',  count: 30, price: 'from $178K' },
        { type: '1 Bedroom', cfg: '1 bed · 1 bath', sqm: '70 m²',  count: 56, price: 'from $246K' },
        { type: '2 Bedroom', cfg: '2 bed · 2 bath', sqm: '104 m²', count: 38, price: 'from $398K' },
        { type: 'Sky villa', cfg: '3 bed · 3 bath', sqm: '158 m²', count: 8,  price: 'from $560K' },
      ],
    },
    investIt: { accessTier: 'Lista Cero', entryPrice: 178000, estRoi: '~26%', annualized: '~10% p.a.', horizon: 5, currency: 'USD', constructionMonths: 30, completionPct: 14, delivery: 'Q3 2027' },
  },



  'Boreal': {
    developer: 'GK Developers', district: 'Obarrio', region: 'Panama', coords: '8.98° N · 79.52° W',
    mapQuery: 'Boreal Obarrio Panama City GK Properties', mapLabel: 'Obarrio, Panama City',
    sketch: 'StandardTower', best: 'early',
    tagline: 'A wellness-driven urban retreat in the heart of Obarrio.',
    liveIt: {
      units: 133, priceFrom: '$200,800', priceRange: '$200K — $382K+',
      blurb: 'Boreal is designed around daily wellbeing: natural light, cross ventilation, intentional amenities and a walkable Obarrio location that keeps services, restaurants and city life close.',
      amenities: ['Pool Haven', 'Yoga Den', 'Wellness Spa', 'Open Garden', 'Training Studio', 'Café & lobby', 'Co-working areas', 'Five-minute district lifestyle'],
      nearby: [
        { name: 'Financial district', dist: '3 min' }, { name: 'Soho City Center', dist: '4 min' },
        { name: 'Metro station', dist: '5 min' }, { name: 'Multiplaza Mall', dist: '8 min' },
        { name: 'Cinta Costera', dist: '8 min' }, { name: 'Casco Viejo', dist: '15 min' },
      ],
      distribution: [
        { type: '1 Bedroom', cfg: '1 bed · 1 bath', sqm: '54 m²', count: 48, price: 'from $200.8K' },
        { type: '2 Bedroom', cfg: '2 bed · 2.5 bath', sqm: '78 m²', count: 56, price: 'on request' },
        { type: '3 Bedroom', cfg: '3 bed · 2.5 bath', sqm: '108 m²', count: 29, price: 'from $382K' },
      ],
    },
    investIt: { accessTier: 'Pre-sale', entryPrice: 200800, estRoi: '~22%', annualized: '~9% p.a.', horizon: 5, currency: 'USD', constructionMonths: 36, completionPct: 6, delivery: '2029' },
  },

  'Cavarrosa': {
    developer: 'TheVelopers', district: 'Amador', coords: '8.93° N · 79.54° W',
    mapQuery: 'Cavarosa Amador Panama', mapLabel: 'Amador Causeway, Panama City',
    sketch: 'CoastalTower', best: 'pragmatist',
    tagline: 'A quiet maritime address on the Amador Causeway.',
    liveIt: {
      units: 160, priceFrom: '$302,000', priceRange: '$302K — $780K',
      blurb: 'Cavarosa is positioned in Amador, close to the ocean, the Canal entrance, marinas and the city skyline — a residential statement built around privacy, views and daily calm.',
      amenities: ['Rooftop club', 'Ocean-view social areas', 'Fitness center', 'Resident lounge', 'Concierge', 'Covered parking', 'Marina access nearby', 'Waterfront boardwalk'],
      nearby: [
        { name: 'Amador Causeway', dist: '1 min' }, { name: 'Biomuseo', dist: '4 min' },
        { name: 'Panama Canal entrance', dist: '6 min' }, { name: 'Flamenco Marina', dist: '8 min' },
        { name: 'Casco Viejo', dist: '12 min' }, { name: 'Financial district', dist: '18 min' },
      ],
      distribution: [
        { type: '1 Bedroom', cfg: '1 bed · 1 bath', sqm: '60 m²', count: 48, price: 'from $302K' },
        { type: '2 Bedroom', cfg: '2 bed · 2 bath', sqm: '96 m²', count: 76, price: 'from $460K' },
        { type: 'Residence', cfg: '3 bed · 3 bath', sqm: '148 m²', count: 28, price: 'from $680K' },
        { type: 'Penthouse', cfg: '3+ bed · terrace', sqm: '190 m²', count: 8, price: 'on request' },
      ],
    },
    investIt: { accessTier: 'Pre-sale', entryPrice: 302000, estRoi: '~24%', annualized: '~10% p.a.', horizon: 5, currency: 'USD', constructionMonths: 28, completionPct: 18, delivery: '2027' },
  },

  'Nayamara': {
    developer: 'TheVelopers', district: 'Amador', coords: '8.93° N · 79.54° W',
    mapQuery: 'Nayamara Amador Panama', mapLabel: 'Amador Causeway, Panama City',
    sketch: 'FinancialTower', best: 'early',
    tagline: 'A faster, safer position — already rising out of the ground.',
    liveIt: {
      units: 210, priceFrom: '$205,000', priceRange: '$205K — $590K',
      blurb: 'Already under construction. A shorter horizon to delivery and a position built for the owner thinking about keeping, not flipping.',
      amenities: ['Sky-lounge & rooftop pool', 'Double-height gym', 'Co-working & meeting suites', 'Screening room', 'Resident lounge & bar', '24/7 security', 'Bicycle storage', 'EV-ready parking'],
      nearby: [
        { name: 'Soho Mall', dist: '5 min' }, { name: 'Metro station', dist: '3 min' },
        { name: 'Tocumen Airport', dist: '20 min' }, { name: 'Punta Pacífica', dist: '7 min' },
        { name: 'Cinta Costera', dist: '6 min' }, { name: 'Financial district', dist: '4 min' },
      ],
      distribution: [
        { type: 'Studio',    cfg: '1 bath',         sqm: '45 m²',  count: 56, price: 'from $205K' },
        { type: '1 Bedroom', cfg: '1 bed · 1 bath', sqm: '63 m²',  count: 88, price: 'from $268K' },
        { type: '2 Bedroom', cfg: '2 bed · 2 bath', sqm: '90 m²',  count: 56, price: 'from $384K' },
        { type: 'Penthouse', cfg: '3 bed · 3 bath', sqm: '150 m²', count: 10, price: 'from $590K' },
      ],
    },
    investIt: { accessTier: 'Under construction', entryPrice: 205000, estRoi: '~22%', annualized: '~10% p.a.', horizon: 4, currency: 'USD', constructionMonths: 16, completionPct: 62, delivery: 'Q2 2026' },
  },
};

// Resolve a project by name → merged record with developer / best inferred from the portfolio data.
const getProjectDetail = (name) => {
  const core = (window.CORE || []).find(c => c.name === name);
  let devName, best;
  (window.DEVELOPERS || []).forEach(d => d.projects.forEach(p => { if (p.name === name) { devName = d.name; best = p.best; } }));

  const o = PD_DETAILS[name] || {};
  const developer = o.developer || (core && core.developer) || devName || 'Dproperty Partner';
  const bestType  = o.best || best || (core && core.best) || 'pragmatist';

  return {
    name,
    developer,
    sketch: o.sketch || (core && core.sketch) || PD_DEFAULT.sketch,
    district: o.district || (core && core.loc) || PD_DEFAULT.district,
    region: o.region || PD_DEFAULT.region,
    location: `${o.district || (core && core.loc) || PD_DEFAULT.district} — ${o.region || PD_DEFAULT.region}`,
    coords: o.coords || PD_DEFAULT.coords,
    mapQuery: o.mapQuery || `${name} ${o.district || (core && core.loc) || PD_DEFAULT.district} ${o.region || PD_DEFAULT.region}`,
    mapLabel: o.mapLabel || `${o.district || (core && core.loc) || PD_DEFAULT.district}, ${o.region || PD_DEFAULT.region}`,
    tagline: o.tagline || PD_DEFAULT.tagline,
    bestType,
    bestProfileId: o.bestProfileId || BEST_TO_PROFILE[bestType] || 'safety',
    liveIt:   { ...PD_DEFAULT.liveIt,   ...(o.liveIt   || {}) },
    investIt: { ...PD_DEFAULT.investIt, ...(o.investIt || {}) },
  };
};

window.getProjectDetail = getProjectDetail;
window.PD_slug = slug;
