// Fabric data: the Acme Corp cross-source story + learning stream feed

// Hero entity: Acme Corp — resolved from 6 sources
const ACME = {
  id: 'org_acme',
  type: 'Organization',
  name: 'Acme Corp',
  aka: ['Acme, Inc.', 'acme-corp.com', 'Acme Corporation'],
  domain: 'acme-corp.com',
  industry: 'Industrial Manufacturing',
  employees: '~2,400',
  arr: '$840k',
  owner: 'Priya Shah',
  firstSeen: 'Feb 14, 2026',
  lastSignal: '2s ago',
  health: 'attention', // good | attention | risk
  healthNote: 'Renewal in 47 days · 1 P1 ticket open',

  // What sources have a record of this entity, and what they contribute
  sources: [
    { id: 'salescrm',  vendor: 'salescrm',  kind: 'Account record',     count: 1,    primary: true, resolvedBy: 'Exact match', conf: 1.00 },
    { id: 'gmail',     vendor: 'gmail',     kind: 'Email threads',      count: 47,   resolvedBy: 'Domain @acme-corp.com', conf: 0.99 },
    { id: 'chatroom',  vendor: 'chatroom',  kind: '#acme-account channel', count: 318, resolvedBy: 'Channel name match + member overlap', conf: 0.96 },
    { id: 'deskzen',   vendor: 'deskzen',   kind: 'Support tickets',    count: 14,   resolvedBy: 'Contact email domain', conf: 0.98 },
    { id: 'cloudbin',  vendor: 'cloudbin',  kind: 'Shared Drive /Acme', count: 63,   resolvedBy: 'Folder name + share permissions', conf: 0.94 },
    { id: 'snowlake',  vendor: 'snowlake',  kind: 'customer_id = 8842', count: '2.1M events', resolvedBy: 'Join on SF ID', conf: 1.00 },
  ],

  // Key people at Acme (resolved cross-source)
  people: [
    { name: 'Sarah Kim',      role: 'VP Ops',        sources: ['salescrm', 'gmail', 'chatroom'], primary: true },
    { name: 'Marcus Leung',   role: 'Director, IT',  sources: ['salescrm', 'gmail', 'deskzen'] },
    { name: 'Jenny Torres',   role: 'Procurement',   sources: ['salescrm', 'gmail'] },
    { name: 'Raj Patel',      role: 'CFO',           sources: ['salescrm', 'gmail', 'cloudbin'] },
    { name: 'Elena Novak',    role: 'Security Lead', sources: ['deskzen', 'gmail'] },
  ],

  // Related internal people
  internal: [
    { name: 'Priya Shah',     role: 'Account Exec',        touches: 84 },
    { name: 'Daniel Wu',      role: 'Solutions Engineer',  touches: 42 },
    { name: 'Maya K.',        role: 'Support',             touches: 11 },
  ],
};

// Merged timeline — interleaved events from all 6 sources around Acme
// Ordered newest-first. "lane" tells the timeline which side + color.
const ACME_TIMELINE = [
  { t: '2s ago',     date: 'Apr 21 · 10:42', src: 'chatroom', lane: 'chat',
    actor: 'Daniel Wu', verb: 'posted in', target: '#acme-account',
    preview: '“Confirming we\'re on for Thursday\'s QBR — agenda in Drive.”' },

  { t: '12 min ago', date: 'Apr 21 · 10:30', src: 'deskzen',  lane: 'support',
    actor: 'Elena Novak (Acme)', verb: 'opened ticket', target: '#T-8842',
    preview: 'SSO login loop for 14 users on mobile — P1' },

  { t: '41 min ago', date: 'Apr 21 · 10:01', src: 'gmail',    lane: 'email',
    actor: 'Sarah Kim', verb: 'replied to', target: 'Re: Q2 renewal terms',
    preview: '“Thanks — legal is reviewing. Let\'s sync Thursday after the QBR.”' },

  { t: '2 hours ago', date: 'Apr 21 · 08:40', src: 'snowlake', lane: 'events',
    actor: 'events.api_call', verb: 'spiked to', target: '84k/hr',
    preview: '+312% vs. trailing 7-day avg (their integration team is testing)' },

  { t: '1 day ago',  date: 'Apr 20 · 15:22', src: 'cloudbin', lane: 'files',
    actor: 'Raj Patel (Acme)', verb: 'opened', target: 'Contract-v3-redline.docx',
    preview: 'Viewed 4×, commented on clauses 7, 12, 14' },

  { t: '1 day ago',  date: 'Apr 20 · 14:01', src: 'salescrm', lane: 'crm',
    actor: 'Priya Shah', verb: 'moved deal to', target: 'Contract Sent',
    preview: 'Expansion · $240k ARR · close date Apr 30' },

  { t: '2 days ago', date: 'Apr 19 · 09:15', src: 'chatroom', lane: 'chat',
    actor: 'Priya Shah', verb: 'created channel', target: '#acme-renewal-q2',
    preview: '8 members · shared with Legal, Finance, Support' },

  { t: '3 days ago', date: 'Apr 18 · 16:48', src: 'deskzen',  lane: 'support',
    actor: 'Maya K.',  verb: 'resolved', target: '#T-8831',
    preview: 'Webhook delivery to acme-corp.com — cert chain mismatch, pinned new CA' },

  { t: '4 days ago', date: 'Apr 17 · 11:20', src: 'gmail',    lane: 'email',
    actor: 'Jenny Torres (Acme)', verb: 'sent', target: 'PO-2026-0418.pdf',
    preview: 'Net-30 terms, $840,000, for period May 2026 – April 2027' },

  { t: '5 days ago', date: 'Apr 16 · 13:05', src: 'cloudbin', lane: 'files',
    actor: 'Daniel Wu', verb: 'shared folder', target: '/Acme / Migration Plan',
    preview: '11 docs · granted access to sarah.kim@acme-corp.com' },

  { t: '1 week ago', date: 'Apr 14',         src: 'snowlake', lane: 'events',
    actor: 'monthly_active_users', verb: 'crossed', target: '1,000',
    preview: 'Milestone hit — expansion trigger fired to Salesforce' },

  { t: '2 weeks ago',date: 'Apr 07',         src: 'salescrm', lane: 'crm',
    actor: 'Priya Shah', verb: 'logged call', target: 'Discovery — expansion',
    preview: '45 min · key ask: multi-region support by Q3' },
];

// Lane config — left/right side + color hint per "kind"
const LANE_CONFIG = {
  chat:    { side: 'right', color: '#4A154B', icon: 'chat',    label: 'Chat' },
  support: { side: 'left',  color: '#03363D', icon: 'support', label: 'Support' },
  email:   { side: 'right', color: '#1A73E8', icon: 'email',   label: 'Email' },
  events:  { side: 'left',  color: '#29B5E8', icon: 'db',      label: 'Events' },
  files:   { side: 'right', color: '#0B8043', icon: 'file',    label: 'Files' },
  crm:     { side: 'left',  color: '#00A1E0', icon: 'crm',     label: 'CRM' },
};

// Inferred relationships (for the Graph tab, centered on Acme)
const ACME_GRAPH_NODES = [
  { id: 'acme',     type: 'Org',     label: 'Acme Corp',    x: 400, y: 220, r: 36, hero: true },
  // People
  { id: 'sarah',    type: 'Person',  label: 'Sarah Kim',    x: 620, y: 110, r: 20, sub: 'VP Ops · Acme' },
  { id: 'marcus',   type: 'Person',  label: 'Marcus Leung', x: 680, y: 220, r: 18, sub: 'Director IT · Acme' },
  { id: 'raj',      type: 'Person',  label: 'Raj Patel',    x: 640, y: 330, r: 18, sub: 'CFO · Acme' },
  { id: 'priya',    type: 'Person',  label: 'Priya Shah',   x: 190, y: 110, r: 20, sub: 'AE · internal' },
  { id: 'daniel',   type: 'Person',  label: 'Daniel Wu',    x: 130, y: 220, r: 18, sub: 'SE · internal' },
  // Deals, tickets, docs
  { id: 'deal',     type: 'Deal',    label: 'Q2 Expansion', x: 400, y: 60,  r: 22, sub: '$240k · Contract Sent' },
  { id: 'ticket',   type: 'Ticket',  label: 'T-8842',       x: 140, y: 350, r: 16, sub: 'SSO loop · P1', danger: true },
  { id: 'contract', type: 'Doc',     label: 'Contract v3',  x: 400, y: 400, r: 20, sub: 'Redline · 4 opens' },
  { id: 'channel',  type: 'Channel', label: '#acme-account',x: 690, y: 410, r: 18, sub: '318 messages' },
  { id: 'snow',     type: 'Dataset', label: 'customer 8842',x: 200, y: 410, r: 18, sub: '2.1M events' },
];

const ACME_GRAPH_EDGES = [
  // Acme ↔ people
  { s: 'acme', t: 'sarah',    label: 'employs',     conf: 1.0 },
  { s: 'acme', t: 'marcus',   label: 'employs',     conf: 1.0 },
  { s: 'acme', t: 'raj',      label: 'employs',     conf: 1.0 },
  { s: 'priya', t: 'acme',    label: 'owns',        conf: 1.0 },
  { s: 'daniel', t: 'acme',   label: 'supports',    conf: 0.95 },
  // Deal
  { s: 'deal', t: 'acme',     label: 'belongs to',  conf: 1.0 },
  { s: 'sarah', t: 'deal',    label: 'champion',    conf: 0.86, inferred: true },
  { s: 'raj', t: 'deal',      label: 'approves',    conf: 0.92, inferred: true },
  // Ticket
  { s: 'ticket', t: 'acme',   label: 'filed by',    conf: 1.0 },
  { s: 'marcus', t: 'ticket', label: 'impacts',     conf: 0.88, inferred: true },
  // Contract + channel
  { s: 'contract', t: 'deal', label: 'attached',    conf: 1.0 },
  { s: 'raj', t: 'contract',  label: 'reviewing',   conf: 0.94, inferred: true },
  { s: 'channel', t: 'acme',  label: 'about',       conf: 1.0 },
  // Snowflake
  { s: 'snow', t: 'acme',     label: 'joined on CRM id', conf: 1.0 },
];

// Learning stream — what the system just figured out
// Each row is a discrete "learning" event with a source trail
const LEARNING_STREAM = [
  { id: 's1', t: '2 min ago',  type: 'entity',   icon: 'Sparkle', accent: true,
    title: 'Resolved Acme Corp across 6 sources',
    body: 'Merged Salesforce account #8842, Gmail domain @acme-corp.com, #acme-account Slack channel, Zendesk org Acme, Drive /Acme folder, and Snowflake customer_id 8842.',
    status: 'auto', conf: 0.97, evidence: 6 },

  { id: 's2', t: '8 min ago',  type: 'dedupe',
    title: 'Merged concept: "Project Titan" ↔ "Acme migration"',
    body: 'Used interchangeably across 9 Notion pages, 4 Slack threads, and 2 email chains. Unified into a single concept; queries for either term now resolve to both.',
    status: 'auto', conf: 0.91, evidence: 15 },

  { id: 's3', t: '14 min ago', type: 'relation',
    title: 'New relationship: Sarah Kim — champion → Q2 Expansion',
    body: 'Inferred from email thread engagement (7 replies on pricing), calendar overlaps, and mentions in #acme-renewal-q2.',
    status: 'needs_review', conf: 0.86, evidence: 12 },

  { id: 's4', t: '22 min ago', type: 'rerank',
    title: 'Re-ranking: down-weighted "pricing-archive.md"',
    body: 'Flagged stale by 3 users last week. Cited 7× in the last 7 days; expected ~1×/week after adjustment.',
    status: 'applied', conf: 1.00, evidence: 3 },

  { id: 's5', t: '37 min ago', type: 'entity',
    title: 'New entity: Elena Novak (Security Lead · Acme Corp)',
    body: 'First seen in Zendesk ticket T-8842 (Apr 21). Resolved to existing domain @acme-corp.com. Linked to Acme Corp org.',
    status: 'auto', conf: 0.94, evidence: 2 },

  { id: 's6', t: '1 h ago',    type: 'relation',
    title: 'Inferred: T-8842 (SSO) — blocks → Q2 Expansion close',
    body: 'Same account, same week, deal in Contract Sent stage. Historical pattern: 78% of P1 tickets on accounts in late stages delay close by avg. 6 days.',
    status: 'needs_review', conf: 0.74, evidence: 4 },

  { id: 's7', t: '2 h ago',    type: 'dedupe',
    title: 'De-duplicated: "Acme Corporation" → "Acme Corp"',
    body: 'Found 3 HubSpot records and 1 Salesforce record referring to same org. Merged under canonical Acme Corp (SF #8842). 412 activities unified.',
    status: 'applied', conf: 0.98, evidence: 4 },

  { id: 's8', t: '3 h ago',    type: 'gap',
    title: 'Coverage gap: Acme legal docs',
    body: 'Mentions of "MSA Appendix C" appear in 5 emails with no matching Drive file. Suggest connecting a legal folder.',
    status: 'needs_review', conf: 0.82, evidence: 5, cta: 'Connect folder' },

  { id: 's9', t: '4 h ago',    type: 'schema',
    title: 'Field learned: "renewal_risk" on Account',
    body: 'A custom Salesforce field with 12 distinct values was normalized into a 3-bucket risk score (low/med/high) for retrieval filtering.',
    status: 'auto', conf: 0.89, evidence: 1 },

  { id: 's10', t: '5 h ago',   type: 'rerank',
    title: 'Promoted: onboarding-runbook-v4 for "new hire" queries',
    body: '5 positive thumbs-up in the last 24h. Weight increased; v3 archived from retrieval set.',
    status: 'applied', conf: 1.00, evidence: 5 },

  { id: 's11', t: '1 d ago',   type: 'relation',
    title: 'Inferred: Daniel Wu — works with → Sarah Kim',
    body: 'Based on 18 co-attended meetings, 42 shared email threads, and 9 joint Slack conversations over 90 days.',
    status: 'auto', conf: 0.93, evidence: 69 },

  { id: 's12', t: '1 d ago',   type: 'entity',
    title: 'New entity: "Project Phoenix" (Initiative)',
    body: 'Mentioned in 23 messages, 8 Notion pages, 2 Jira epics. Classified as Initiative. Linked to Acme Corp (primary beneficiary).',
    status: 'auto', conf: 0.88, evidence: 33 },
];

// Aggregate metrics for Fabric overview
const FABRIC_METRICS = {
  entities:   { total: 34211, delta: '+128 today', spark: [6,7,8,7,9,10,12,11,13,14,15,16] },
  relations:  { total: 128430, delta: '+612 today', spark: [10,12,14,13,15,16,18,17,19,20,22,24] },
  resolved:   { total: 4812,  delta: '+47 today',   spark: [2,3,4,3,5,6,7,6,8,9,10,11], label: 'cross-source merges' },
  learnings:  { total: 312,   delta: '+12 today',   spark: [4,6,5,7,8,7,9,10,9,11,12,12] },
};

Object.assign(window, {
  ACME, ACME_TIMELINE, LANE_CONFIG,
  ACME_GRAPH_NODES, ACME_GRAPH_EDGES,
  LEARNING_STREAM, FABRIC_METRICS
});
