/* ================================================================
 * Canonical synthetic dataset for the Developer + VVB demo.
 * One source of truth — read everywhere.
 *
 * Hero project: Pamoja EcoGreen Bamboo (PRJ-KE-BUS001)
 *   Methodology: VM0047 (ARR — bamboo restoration)
 *   Phase 3 Validation, VVB audit aud-8f2a9c assigned to Sarah C.
 *
 * Each project is shaped so it can be passed to ProjectDetail,
 * Phase3Workspace, the VVB AuditList, EvidenceBrowser, SamplingPanel
 * and SignOffForm without any further mapping.
 * ================================================================ */

const PROJECTS = [
  {
    id: 'PRJ-KE-BUS001',
    name: 'Pamoja EcoGreen Bamboo',
    location: 'Bungoma County, Kenya',
    coords: '0.5635° N, 34.5606° E',
    methodology: 'VM0047 v1.1',
    methodologyName: 'Afforestation, Reforestation & Revegetation',
    registry: 'VERRA',
    registryVariant: 'verra',
    phase: 3,
    phaseName: 'Validation',
    status: 'desk review',
    statusVariant: 'amber',
    area: '12,450 ha',
    species: 'Bambusa vulgaris (Oxytenanthera abyssinica intercrop)',
    households: 1840,
    credits: 0,
    available: 0,
    projected: 142308,
    vvb: 84,
    auditId: 'aud-8f2a9c',
    vvbAssigned: { name: 'Sarah Chen', firm: 'SCS Global Services', accreditation: 'VVB-007' },
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 3,
    findingsOpen: 2,
    capsOpen: 1,
    documents: 47,
    plots: 42,
    plotsFlagged: 1,
    hero: true,
    phases: [
      { num:1, weight:20, name:'Eligibility',  state:'done',    detail:'100% · committed · @128' },
      { num:2, weight:25, name:'PDD',          state:'done',    detail:'100% · committed · @141' },
      { num:3, weight:25, name:'Validation',   state:'current', detail:'8 of 14 fields · 57%' },
      { num:4, weight:20, name:'Monitoring',   state:'todo',    detail:'Awaits validation sign-off' },
      { num:5, weight:10, name:'Issuance',     state:'todo',    detail:'Not started' },
    ],
  },
  {
    id: 'PRJ-KE-WAM002',
    name: 'Wamunyu Biochar',
    location: 'Machakos County, Kenya',
    coords: '1.4636° S, 37.4486° E',
    methodology: 'Puro CORC Methodology 2024',
    methodologyName: 'Biochar carbon removal',
    registry: 'PURO',
    registryVariant: 'puro',
    phase: 3,
    phaseName: 'Validation',
    status: 'site visit',
    statusVariant: 'amber',
    area: '— (4 production sites)',
    species: '—',
    households: 86,
    credits: 31180,
    available: 18200,
    projected: 64500,
    vvb: 78,
    auditId: 'aud-3d22e1',
    vvbAssigned: { name: 'Sarah Chen', firm: 'SCS Global Services', accreditation: 'VVB-007' },
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 5,
    findingsOpen: 3,
    capsOpen: 2,
    documents: 38,
    plots: 0,
    plotsFlagged: 0,
    phases: [
      { num:1, weight:20, name:'Eligibility', state:'done',    detail:'100% · @71' },
      { num:2, weight:25, name:'PDD',         state:'done',    detail:'100% · @118' },
      { num:3, weight:25, name:'Validation',  state:'current', detail:'11 of 18 fields · 61%' },
      { num:4, weight:20, name:'Monitoring',  state:'todo',    detail:'Quarterly' },
      { num:5, weight:10, name:'Issuance',    state:'todo',    detail:'Not started' },
    ],
  },
  {
    id: 'PRJ-UG-KMP003',
    name: 'Kampala Urban Agroforestry',
    location: 'Kampala, Uganda',
    coords: '0.3476° N, 32.5825° E',
    methodology: 'ACM0022 v1.0',
    methodologyName: 'Avoided urban deforestation',
    registry: 'VERRA',
    registryVariant: 'verra',
    phase: 2,
    phaseName: 'PDD',
    status: 'pre-review',
    statusVariant: 'blue',
    area: '8,210 ha',
    species: 'Mixed indigenous (62 species)',
    households: 412,
    credits: 0,
    available: 0,
    projected: 88200,
    vvb: 62,
    auditId: 'aud-7b91c4',
    vvbAssigned: null,
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 0,
    findingsOpen: 0,
    capsOpen: 0,
    documents: 24,
    plots: 18,
    plotsFlagged: 0,
    phases: [
      { num:1, weight:20, name:'Eligibility', state:'done',    detail:'100% · @42' },
      { num:2, weight:25, name:'PDD',         state:'current', detail:'4 of 12 fields · 33%' },
      { num:3, weight:25, name:'Validation',  state:'todo',    detail:'Not started' },
      { num:4, weight:20, name:'Monitoring',  state:'todo',    detail:'Not started' },
      { num:5, weight:10, name:'Issuance',    state:'todo',    detail:'Not started' },
    ],
  },
  {
    id: 'PRJ-MW-LIL004',
    name: 'Lilongwe Improved Cookstoves',
    location: 'Lilongwe, Malawi',
    coords: '13.9626° S, 33.7741° E',
    methodology: 'TPDDTEC v4.0',
    methodologyName: 'Improved cookstove technologies',
    registry: 'GOLDSTANDARD',
    registryVariant: 'gold',
    phase: 1,
    phaseName: 'Eligibility',
    status: 'scoping',
    statusVariant: 'gray',
    area: '— (household)',
    species: '—',
    households: 6200,
    credits: 0,
    available: 0,
    projected: 22400,
    vvb: 41,
    auditId: null,
    vvbAssigned: null,
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 0,
    findingsOpen: 0,
    capsOpen: 0,
    documents: 8,
    plots: 0,
    plotsFlagged: 0,
    phases: [
      { num:1, weight:20, name:'Eligibility', state:'current', detail:'3 of 7 fields · 43%' },
      { num:2, weight:25, name:'PDD',         state:'todo',    detail:'Not started' },
      { num:3, weight:25, name:'Validation',  state:'todo',    detail:'Not started' },
      { num:4, weight:20, name:'Monitoring',  state:'todo',    detail:'Not started' },
      { num:5, weight:10, name:'Issuance',    state:'todo',    detail:'Not started' },
    ],
  },
  {
    id: 'PRJ-RW-BUG005',
    name: 'Bugesera Mangrove Restoration',
    location: 'Bugesera District, Rwanda',
    coords: '2.2367° S, 30.1828° E',
    methodology: 'VM0007 v3.0',
    methodologyName: 'REDD+ Methodology Framework',
    registry: 'VERRA',
    registryVariant: 'verra',
    phase: 5,
    phaseName: 'Issuance',
    status: 'active',
    statusVariant: 'green',
    area: '4,820 ha',
    species: 'Rhizophora mucronata, Avicennia marina',
    households: 920,
    credits: 67100,
    available: 8400,
    projected: 67100,
    vvb: 94,
    auditId: 'aud-1f44b8',
    vvbAssigned: { name: 'Sarah Chen', firm: 'SCS Global Services', accreditation: 'VVB-007' },
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 0,
    findingsOpen: 0,
    capsOpen: 0,
    documents: 64,
    plots: 31,
    plotsFlagged: 0,
    phases: [
      { num:1, weight:20, name:'Eligibility', state:'done', detail:'100% · @22' },
      { num:2, weight:25, name:'PDD',         state:'done', detail:'100% · @58' },
      { num:3, weight:25, name:'Validation',  state:'done', detail:'100% · @142' },
      { num:4, weight:20, name:'Monitoring',  state:'done', detail:'100% · @188' },
      { num:5, weight:10, name:'Issuance',    state:'current', detail:'67,100 tCO2e issued · 8,400 available' },
    ],
  },
  {
    id: 'PRJ-CD-VIR006',
    name: 'Virunga Agroforestry',
    location: 'Rutshuru, DR Congo',
    coords: '1.1862° S, 29.4501° E',
    methodology: 'CAR Forest Protocol v5.0',
    methodologyName: 'Avoided forest conversion',
    registry: 'CAR',
    registryVariant: 'gray',
    phase: 1,
    phaseName: 'Eligibility',
    status: 'scoping',
    statusVariant: 'gray',
    area: '18,940 ha',
    species: 'Mixed afromontane',
    households: 240,
    credits: 0,
    available: 0,
    projected: 110000,
    vvb: 31,
    auditId: null,
    vvbAssigned: null,
    developer: { name: 'Grace Kimani', org: 'Pamoja EcoGreen Co-operative', email: 'grace@ecogreen.co.ke' },
    findings: 0,
    findingsOpen: 0,
    capsOpen: 0,
    documents: 4,
    plots: 0,
    plotsFlagged: 0,
    phases: [
      { num:1, weight:20, name:'Eligibility', state:'current', detail:'1 of 7 fields · 14%' },
      { num:2, weight:25, name:'PDD',         state:'todo', detail:'Not started' },
      { num:3, weight:25, name:'Validation',  state:'todo', detail:'Not started' },
      { num:4, weight:20, name:'Monitoring',  state:'todo', detail:'Not started' },
      { num:5, weight:10, name:'Issuance',    state:'todo', detail:'Not started' },
    ],
  },
];

/* ------ Phase-3 field-state data for EcoGreen Bamboo ------ */
const PHASE3_FIELDS = [
  { id:'species',    label:'Species mix',                state:'confirmed', value:'Bambusa vulgaris (60%) · Oxytenanthera (40%)', who:'Grace K. · 14 Mar' },
  { id:'area',       label:'Project area',               state:'confirmed', value:'12,450 ha across 3 strata',                    who:'Grace K. · 14 Mar' },
  { id:'boundary',   label:'Geographic boundary',        state:'committed', value:'GeoJSON · 1.4 MB · sha256:a3f9…',              who:'HCS 0.0.8321350 @ seq 142' },
  { id:'method',     label:'Methodology',                state:'imported',  value:'VM0047 v1.1 (ARR)',                            who:'Verra Registry API · 12 Mar' },
  { id:'baseline',   label:'Baseline carbon stock',      state:'ai',        value:'48.2 tC/ha (±4.1)',                            who:'Extracted PDD §3.1 · 89% conf.' },
  { id:'leakage',    label:'Leakage belt',               state:'ai',        value:'0.5 km buffer · 412 ha',                       who:'Extracted PDD §4.2 · 76% conf.' },
  { id:'permanence', label:'Permanence safeguard',       state:'ai',        value:'20% buffer pool',                              who:'Extracted PDD §5.3 · 92% conf.' },
  { id:'stratify',   label:'Stratification rationale',   state:'confirmed', value:'3 strata (lowland / mid / riparian)',          who:'Joseph M. · 12 Mar' },
  { id:'plot42',     label:'DBH plot 42',                state:'flagged',   value:'84 cm — 5σ above plot mean',                   who:'Anomaly Pipeline · 4 hrs ago' },
  { id:'tenure',     label:'Land tenure docs',           state:'empty',     value:'—',                                            who:'Required by VCS §3.4' },
  { id:'consent',    label:'Community consent (FPIC)',   state:'empty',     value:'—',                                            who:'Required by VM0047 §2.4' },
  { id:'monitoring', label:'Monitoring plan',            state:'confirmed', value:'Annual + 5-yr full re-inventory',              who:'Grace K. · 13 Mar' },
  { id:'addnl',      label:'Additionality argument',     state:'confirmed', value:'Investment + barrier analysis',                who:'Grace K. · 14 Mar' },
  { id:'safeguards', label:'Environmental safeguards',   state:'confirmed', value:'8 of 8 SDG markers addressed',                 who:'Grace K. · 14 Mar' },
];

/* ------ Findings/CAPs raised against EcoGreen Bamboo ------ */
const FINDINGS = [
  {
    id: 'FND-001',
    severity: 'major',
    raised: '14:08 today',
    by: 'Sarah Chen (VVB)',
    title: 'Stratum B baseline samples below minimum',
    detail: 'Only 8 plots sampled in Stratum B (riparian); VM0047 §6.2 requires ≥12. Either expand sampling or merge Stratum B into Stratum A with statistical justification.',
    cap: true,
    capDueDays: 14,
    status: 'open',
    requiresResponse: true,
  },
  {
    id: 'FND-002',
    severity: 'minor',
    raised: '11:22 today',
    by: 'Sarah Chen (VVB)',
    title: 'Plot 42 outlier — confirm or exclude',
    detail: 'DBH 84 cm is 5σ above plot mean. Need field-agent re-measurement or written justification before validation can proceed.',
    cap: true,
    capDueDays: 7,
    status: 'open',
    requiresResponse: true,
  },
  {
    id: 'FND-003',
    severity: 'observation',
    raised: 'Yesterday 16:40',
    by: 'Sarah Chen (VVB)',
    title: 'Tenure documentation missing',
    detail: 'No customary/statutory tenure record uploaded for the 412 ha leakage belt. Not a stop-ship but recommended before site visit.',
    cap: false,
    capDueDays: null,
    status: 'open',
    requiresResponse: false,
  },
];

/* ------ Hedera audit trail (last 12 events) ------ */
const HEDERA_EVENTS = [
  { t:'14:08 today',     actor:'Grace K.',      action:'confirmed project area · 12,450 ha',          tx:'0.0.8321350@142', kind:'confirm' },
  { t:'14:02 today',     actor:'System',        action:'committed Phase 2 batch (37 items)',          tx:'0.0.8321350@141', kind:'commit' },
  { t:'13:55 today',     actor:'Joseph M.',     action:'uploaded PDD v3.2.pdf · sha256:1c7e…',        tx:'0.0.8321350@140', kind:'upload' },
  { t:'13:22 today',     actor:'Verra API',     action:'imported methodology VM0047',                  tx:'0.0.8321350@138', kind:'import' },
  { t:'11:04 today',     actor:'Field Agent',   action:'submitted plot 42 (DBH outlier flagged)',     tx:'0.0.8321350@135', kind:'flag' },
  { t:'09:18 today',     actor:'Sarah C. (VVB)',action:'raised finding FND-002 · plot 42 outlier',    tx:'0.0.8321350@133', kind:'finding' },
  { t:'Yesterday 18:22', actor:'System',        action:'Phase 2 sealed · readiness 74→84',            tx:'0.0.8321350@131', kind:'commit' },
  { t:'Yesterday 16:40', actor:'Sarah C. (VVB)',action:'raised finding FND-003 · tenure docs',        tx:'0.0.8321350@128', kind:'finding' },
  { t:'13 Mar 11:08',    actor:'Field Agent',   action:'submitted plot batch 30-42 (13 plots)',       tx:'0.0.8321350@121', kind:'upload' },
  { t:'12 Mar 09:30',    actor:'Grace K.',      action:'registered project PRJ-KE-BUS001',            tx:'0.0.8321350@103', kind:'register' },
];

window.PROJECTS = PROJECTS;
window.PHASE3_FIELDS = PHASE3_FIELDS;
window.FINDINGS = FINDINGS;
window.HEDERA_EVENTS = HEDERA_EVENTS;
window.getProject = (id) => PROJECTS.find(p => p.id === id);
