// MarketForge demo — static data. All precomputed (simulating Cosolvent output).

const PROFILES = {
  shop: {
    role: 'Machine Shop',
    callsign: 'MS-0417',
    name: 'Ardent Precision Works',
    location: 'Grand Rapids, MI',
    founded: 1987,
    headcount: 34,
    certifications: ['ISO 9001:2015', 'AS9100D', 'ITAR registered'],
    processes: ['5-axis milling', '3-axis milling', 'Turning', 'Wire EDM'],
    materials: ['Inconel 718', 'Ti-6Al-4V', '17-4 PH SS', '7075-T6 Al', 'A286'],
    envelope: '600 × 400 × 320 mm',
    tolerance: '±0.0005"',
    capacity: { current: 62, pipeline: 84 },
    constraints: ['Confidential until mutual opt-in', 'No automotive volume work'],
    incomplete: [
      { field: 'Surface finish capability', impact: 'high', hint: 'Adding Ra achievable tolerances would improve match accuracy on aerospace work.' },
      { field: 'Inspection equipment list', impact: 'medium', hint: 'Listing CMM + scanner specs unlocks inspector-verified match flags.' },
    ],
  },
  buyer: {
    role: 'Buyer',
    callsign: 'BU-2208',
    name: 'Helios Aerospace Systems',
    location: 'Torrance, CA',
    founded: 2011,
    headcount: 210,
    certifications: ['AS9100D'],
    processes: ['Requires 5-axis milling', 'Requires CMM inspection'],
    materials: ['Inconel 718 (primary)', 'Ti-6Al-4V'],
    envelope: 'Parts up to 480 × 320 × 240 mm',
    tolerance: '±0.001" required, ±0.0005" preferred',
    capacity: { current: 0, pipeline: 12 },
    constraints: ['ITAR clearance required', 'US-based supplier only'],
    incomplete: [
      { field: 'Annual volume forecast', impact: 'high', hint: 'Sharing 12-month projections helps shops model capacity reservations.' },
    ],
  },
  inspector: {
    role: 'Inspector',
    callsign: 'IN-0091',
    name: 'Meridian Metrology Services',
    location: 'Independence, OH',
    founded: 2003,
    headcount: 18,
    certifications: ['ISO/IEC 17025', 'NADCAP Measurement & Inspection'],
    processes: ['CMM (Zeiss Prismo)', 'Laser scanning', 'FAI per AS9102'],
    materials: ['Any metallic', 'Composites (select)'],
    envelope: 'Parts up to 1200 × 800 × 600 mm',
    tolerance: 'Uncertainty ±0.0001"',
    capacity: { current: 71, pipeline: 45 },
    constraints: ['Source inspection on-site (+surcharge)', 'NDA required pre-engagement'],
    incomplete: [
      { field: 'Digital thread integration', impact: 'medium', hint: 'Declaring QIF/MBD support surfaces higher-value digital-first buyers.' },
    ],
  },
};

// Counterparty (what the demo matches YOU against)
const COUNTERPARTIES = {
  shop: { // shop sees Helios as top match (buyer)
    callsign: 'BU-████',
    revealedName: 'Helios Aerospace Systems',
    role: 'Buyer',
    location: 'Southern California',
    summary: 'Tier-2 aerospace buyer. Recurring tight-tolerance Inconel work.',
  },
  buyer: { // buyer sees Ardent as top match (shop)
    callsign: 'MS-████',
    revealedName: 'Ardent Precision Works',
    role: 'Machine Shop',
    location: 'Great Lakes region',
    summary: 'Mid-size 5-axis shop. AS9100D, ITAR. Aerospace-heavy book.',
  },
  inspector: { // inspector sees a match with both sides needing FAI
    callsign: 'MS-████',
    revealedName: 'Ardent Precision Works',
    role: 'Machine Shop',
    location: 'Great Lakes region',
    summary: 'Requesting third-party FAI on aerospace parts. Recurring.',
  },
};

// Capability comparison rows — same structure per role, tailored values
const COMPARISONS = {
  shop: [
    { param: 'Process',      type: 'hard', you: '5-axis milling',        them: 'Requires 5-axis milling',   status: 'match',    note: 'Exact capability alignment' },
    { param: 'Tolerance',    type: 'pref', you: '±0.0005"',              them: '±0.001" req, ±0.0005" pref', status: 'exceeds', note: 'You exceed preferred spec' },
    { param: 'Material',     type: 'hard', you: 'Inconel 718',           them: 'Inconel 718 (primary)',     status: 'match',    note: 'Primary material in stock' },
    { param: 'Envelope',     type: 'hard', you: '600 × 400 × 320 mm',    them: '480 × 320 × 240 mm',        status: 'exceeds',  note: 'Work envelope sufficient' },
    { param: 'Certifications', type: 'hard', you: 'AS9100D, ITAR',     them: 'AS9100D + ITAR required',   status: 'match',    note: 'All required certs on file' },
    { param: 'Location',     type: 'hard', you: 'Grand Rapids, MI',      them: 'US-based required',         status: 'match',    note: 'Domestic supplier condition met' },
    { param: 'Capacity',     type: 'comm', you: '38% available',         them: '12-part pipeline Q3',       status: 'partial',  note: 'Capacity tight, viable with staging' },
    { param: 'Surface finish', type: 'pref', you: 'Not specified',       them: 'Ra 32 μin preferred',       status: 'unknown',  note: 'KnowledgeSlot prompt active', ksYou: 'Ra 16 μin verified', ksStatus: 'exceeds', ksNote: 'KnowledgeSlot reveals capability exceeding reqs' },
  ],
  buyer: [
    { param: 'Process',      type: 'hard', you: 'Requires 5-axis milling', them: '5-axis milling',          status: 'match',    note: 'Capability confirmed' },
    { param: 'Tolerance',    type: 'pref', you: '±0.001" required',        them: '±0.0005"',                status: 'exceeds',  note: 'Supplier exceeds required spec' },
    { param: 'Material',     type: 'hard', you: 'Inconel 718',             them: 'Inconel 718 in stock',    status: 'match',    note: 'Primary material available' },
    { param: 'Envelope',     type: 'hard', you: '480 × 320 × 240 mm',      them: '600 × 400 × 320 mm',      status: 'exceeds',  note: 'Supplier envelope sufficient' },
    { param: 'Certifications', type: 'hard', you: 'AS9100D, ITAR req',     them: 'AS9100D, ITAR registered',status: 'match',    note: 'All certs verified' },
    { param: 'Location',     type: 'hard', you: 'US-based required',       them: 'Grand Rapids, MI',        status: 'match',    note: 'Domestic supplier' },
    { param: 'Volume',       type: 'comm', you: '12 parts Q3',             them: '38% capacity open',       status: 'partial',  note: 'Fits but will consume most slack' },
    { param: 'Volume forecast', type: 'comm', you: 'Not specified',      them: 'Pricing depends on qty',  status: 'unknown',  note: 'KnowledgeSlot prompt active', ksYou: '48 parts / 12 mo', ksStatus: 'match', ksNote: 'Forecast shared, unlocking tiered pricing' },
  ],
  inspector: [
    { param: 'Scope',        type: 'hard', you: 'FAI per AS9102',          them: 'Requires AS9102 FAI',      status: 'match',    note: 'Standardized report format' },
    { param: 'Equipment',    type: 'hard', you: 'Zeiss Prismo CMM',        them: 'CMM + scan data requested',status: 'match',    note: 'Capability confirmed' },
    { param: 'Part size',    type: 'hard', you: 'Up to 1200 × 800 × 600',  them: '480 × 320 × 240 mm',       status: 'exceeds',  note: 'Envelope supported' },
    { param: 'Uncertainty',  type: 'hard', you: '±0.0001"',                them: '±0.0005" feature tol',     status: 'exceeds',  note: '10:1 rule satisfied' },
    { param: 'Accreditation',type: 'hard', you: 'ISO/IEC 17025',           them: 'Requires accredited lab',  status: 'match',    note: 'Valid scope of accreditation' },
    { param: 'Turnaround',   type: 'comm', you: '5 business days',         them: '7 days target',            status: 'match',    note: 'Within buyer timeline' },
    { param: 'Location',     type: 'hard', you: 'Independence, OH',        them: 'US-based required',        status: 'match',    note: 'Domestic lab' },
    { param: 'Digital thread', type: 'pref', you: 'Not specified',         them: 'QIF preferred',            status: 'unknown',  note: 'KnowledgeSlot prompt active', ksYou: 'Native QIF + MBD support', ksStatus: 'match', ksNote: 'Model-based integration verified' },
  ],
};

// Signals that drive confidence
const SIGNALS = {
  shop: [
    { label: 'Process fit',        weight: 20, scoreFull: 20, scoreBase: 20 },
    { label: 'Material fit',       weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Tolerance headroom', weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Certifications',     weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Capacity fit',       weight: 10, scoreFull: 8,  scoreBase: 8  },
    { label: 'Finish capability',  weight: 15, scoreFull: 13, scoreBase: 0  }, // KnowledgeSlot
    { label: 'Inspection readiness', weight: 10, scoreFull: 8, scoreBase: 3 }, // KnowledgeSlot
  ],
  buyer: [
    { label: 'Supplier fit',       weight: 25, scoreFull: 25, scoreBase: 25 },
    { label: 'Material fit',       weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Tolerance',          weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Certifications',     weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Lead time fit',      weight: 10, scoreFull: 8,  scoreBase: 8  },
    { label: 'Volume alignment',   weight: 20, scoreFull: 17, scoreBase: 4  }, // KnowledgeSlot
  ],
  inspector: [
    { label: 'Scope fit',          weight: 20, scoreFull: 20, scoreBase: 20 },
    { label: 'Equipment',          weight: 20, scoreFull: 20, scoreBase: 20 },
    { label: 'Uncertainty budget', weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Accreditation',      weight: 15, scoreFull: 15, scoreBase: 15 },
    { label: 'Turnaround',         weight: 10, scoreFull: 10, scoreBase: 10 },
    { label: 'Digital thread',     weight: 20, scoreFull: 17, scoreBase: 5  }, // KnowledgeSlot
  ],
};

const NARRATIVES = {
  shop: {
    headline: 'Recurring tight-tolerance Inconel work — aligned on both sides.',
    paragraphs: [
      'The counterparty — a Tier-2 aerospace buyer — has a recurring Q3 program for twelve Inconel 718 components requiring 5-axis milling and AS9102 first-article inspection. Their envelope, tolerance, and material specs fall cleanly inside your capability window.',
      'From their side, your AS9100D + ITAR posture, 5-axis cell with ±0.0005" headroom, and Inconel stocking position clear every hard requirement. The match clears because neither party is compromising on a non-negotiable.',
      'Two frictions remain. First, your Q3 capacity absorbs roughly 34% of their program, and your standard transit time misses their assembly window. To bridge this, the system has automatically assigned a Logistics Facilitator (Interline) to overnight the delivery natively. Second, surface-finish capability is unpublished on your profile — the system has flagged this as the highest-impact completion opportunity.',
    ],
  },
  buyer: {
    headline: 'Domestic supplier clears every hard requirement — volume conversation open.',
    paragraphs: [
      'The counterparty is a Midwest 5-axis shop carrying AS9100D, ITAR registration, and an Inconel 718 stocking position. They clear your supplier-qualification floor without an exception.',
      'From their side, your Q3 program is a clean fit — material, tolerance, and process land inside their working envelope. Your AS9100D buyer posture and ITAR clearance remove their confidentiality friction.',
      'However, their Michigan location combined with their production lead times normally forces you to miss your Friday line-down deadline. The system preserves the deal by injecting an expedited Logistics Facilitator into the loop. The outstanding signal is your 12-month volume forecast to secure pricing.',
    ],
  },
  inspector: {
    headline: 'Accredited third-party FAI with 10:1 uncertainty headroom.',
    paragraphs: [
      'A buyer-shop pair has assembled around Inconel 718 aerospace parts and flagged a need for independent AS9102 first-article inspection. Your ISO/IEC 17025 scope and Zeiss Prismo CMM cover the feature set without exception.',
      'From both counterparties\' sides, your ±0.0001" measurement uncertainty clears the 10:1 rule against the tightest ±0.001" feature. Your 5-day turnaround lands inside their 7-day window.',
      'A minor friction involves the geographical spread; rather than shipping the FAI articles to Ohio, the system is leveraging your on-site source inspection option. The remaining signal is digital-thread support — declaring QIF/MBD capability elevates you with digitally-native buyers.',
    ],
  },
};

const DEALS = {
  shop: {
    title: 'Deal Brief — MF-2026-04-0412',
    parties: ['Ardent Precision Works', 'Helios Aerospace Systems'],
    scope: '12× Inconel 718 structural brackets, 5-axis milled, AS9102 FAI on first article',
    pricing: { unit: '$1,840 / ea', total: '$22,080', terms: 'Net 30' },
    timeline: { kickoff: 'May 04, 2026', fai: 'May 22, 2026', delivery: 'Jun 30, 2026' },
    facilitators: [
      { role: 'Inspection', party: 'Meridian Metrology Services', note: 'AS9102 FAI, on-site source option' },
      { role: 'Logistics', party: 'Interline Freight', note: 'Domestic ground, insured' },
    ],
    documents: ['MSA-draft-v2.pdf', 'NDA-mutual.pdf', 'ITAR-attestation.pdf', 'Quality-agreement-AS9100.pdf'],
    valueDrivers: [
      { party: 'Ardent Precision', outcome: 'Secures high-margin 6-month recurring volume filling low-yield Q3 capacity gaps.' },
      { party: 'Helios Aerospace', outcome: 'Locates verified ITAR/AS9100D supplier matching tight lead-times missing on open market.' },
      { party: 'System Resolution', outcome: 'Interline Freight automatically bridging 2-day delivery gap to meet buyer line-down condition.' }
    ]
  },
  buyer: {
    title: 'Deal Brief — MF-2026-04-0412',
    parties: ['Helios Aerospace Systems', 'Ardent Precision Works'],
    scope: '12× Inconel 718 structural brackets, 5-axis milled, AS9102 FAI on first article',
    pricing: { unit: '$1,840 / ea', total: '$22,080', terms: 'Net 30' },
    timeline: { kickoff: 'May 04, 2026', fai: 'May 22, 2026', delivery: 'Jun 30, 2026' },
    facilitators: [
      { role: 'Inspection', party: 'Meridian Metrology Services', note: 'AS9102 FAI, on-site source option' },
      { role: 'Logistics', party: 'Interline Freight', note: 'Domestic ground, insured' },
    ],
    documents: ['MSA-draft-v2.pdf', 'NDA-mutual.pdf', 'PO-template.pdf', 'Quality-agreement-AS9100.pdf'],
    valueDrivers: [
      { party: 'Helios Aerospace', outcome: 'Eliminates 3-week sourcing search; verifies hard compliance limits immediately.' },
      { party: 'Ardent Precision', outcome: 'Locks in volume discount structure replacing spot-rate volatility.' },
      { party: 'System Resolution', outcome: 'Interline logistics injected to reconcile Michigan origin with California demand window.' }
    ]
  },
  inspector: {
    title: 'Deal Brief — MF-2026-04-0415',
    parties: ['Meridian Metrology Services', 'Ardent Precision Works (on behalf of Helios)'],
    scope: 'AS9102 first-article inspection, 12-part Inconel 718 program, digital report + CMM data',
    pricing: { unit: '$3,200 / FAI', total: '$3,200', terms: 'Net 30' },
    timeline: { kickoff: 'May 18, 2026', fai: 'May 22, 2026', delivery: 'May 27, 2026' },
    facilitators: [
      { role: 'Source inspection option', party: 'Meridian on-site', note: 'Surcharge $850, waivable for recurring' },
    ],
    documents: ['Inspection-SOW.pdf', 'NDA-mutual.pdf', '17025-scope.pdf', 'AS9102-template.pdf'],
    valueDrivers: [
      { party: 'Meridian Metrology', outcome: 'Acquires new aerospace prime relationship with pre-vetted machine shop.' },
      { party: 'Ardent + Helios', outcome: 'Fulfilled AS9102 requirement without shipping parts out of state, reducing risk.' },
      { party: 'System Resolution', outcome: 'Replaced logistics overhead with automated source-inspection on-site dispatch.' }
    ]
  },
};

Object.assign(window, { PROFILES, COUNTERPARTIES, COMPARISONS, SIGNALS, NARRATIVES, DEALS });
