// JFJ Affiliate Portal - shared data and tokens

const ENTITIES = [
  {
    id: 'trusts',
    name: 'JFJ Trusts',
    short: 'Trusts',
    tag: 'TRUST',
    hue: 142, // emerald
    color: 'oklch(58% 0.14 142)',
    soft: 'oklch(94% 0.04 142)',
    onSoft: 'oklch(32% 0.10 142)',
    tagline: 'Asset protection & estate structures',
    avgCommission: 4200,
    payoutModel: '15% of setup fee',
    avgDealCycle: '21 days',
    certified: true,
    leads: 18,
  },
  {
    id: 'tax',
    name: 'JFJ Tax Strategy',
    short: 'Tax',
    tag: 'TAX',
    hue: 248,
    color: 'oklch(58% 0.14 248)',
    soft: 'oklch(94% 0.04 248)',
    onSoft: 'oklch(32% 0.10 248)',
    tagline: 'Advanced tax planning for high earners',
    avgCommission: 2850,
    payoutModel: '10% of engagement',
    avgDealCycle: '14 days',
    certified: true,
    leads: 11,
  },
  {
    id: 'consulting',
    name: 'JFJ Consulting',
    short: 'Consulting',
    tag: 'CONS',
    hue: 35,
    color: 'oklch(64% 0.14 35)',
    soft: 'oklch(94% 0.04 35)',
    onSoft: 'oklch(34% 0.10 35)',
    tagline: 'Operations & growth advisory',
    avgCommission: 1900,
    payoutModel: '8% of MRR (12mo)',
    avgDealCycle: '28 days',
    certified: false,
    leads: 4,
  },
  {
    id: 'leadgen',
    name: 'JFJ Lead Gen',
    short: 'Lead Gen',
    tag: 'LEAD',
    hue: 320,
    color: 'oklch(60% 0.14 320)',
    soft: 'oklch(94% 0.04 320)',
    onSoft: 'oklch(34% 0.10 320)',
    tagline: 'Done-for-you appointment setting',
    avgCommission: 1100,
    payoutModel: '$300 per qualified appt',
    avgDealCycle: '7 days',
    certified: false,
    leads: 6,
  },
];

const ENTITY_BY_ID = Object.fromEntries(ENTITIES.map(e => [e.id, e]));

const PIPELINE_STAGES = [
  { id: 'lead',     label: 'Lead Captured',    short: 'Lead',     order: 1 },
  { id: 'apptset',  label: 'Appointment Set',  short: 'Set',      order: 2 },
  { id: 'apptshow', label: 'Appointment Showed', short: 'Showed', order: 3 },
  { id: 'proposal', label: 'Proposal Sent',    short: 'Proposal', order: 4 },
  { id: 'invoice',  label: 'Invoice Sent',     short: 'Invoice',  order: 5 },
  { id: 'won',      label: 'Closed Won',       short: 'Won',      order: 6 },
];

const STAGE_BY_ID = Object.fromEntries(PIPELINE_STAGES.map(s => [s.id, s]));

// Realistic referrals — names + state of pipeline
const REFERRALS = [
  { id: 'R-2841', name: 'Marcus Webb',       company: 'Webb Holdings LLC',     entity: 'trusts',     stage: 'won',      potential: 6300, days: 22, stalled: false, source: 'Email • May 2', email: 'mwebb@webb.co' },
  { id: 'R-2840', name: 'Priya Shah',        company: 'Shah Family Office',    entity: 'trusts',     stage: 'invoice',  potential: 4200, days: 18, stalled: false, source: 'SMS • Apr 28',  email: 'priya@shafam.io' },
  { id: 'R-2839', name: 'Dwayne Foster',     company: 'Foster Mech. Group',    entity: 'tax',        stage: 'proposal', potential: 2850, days: 9,  stalled: false, source: 'Direct link',   email: 'd@fostermech.com' },
  { id: 'R-2838', name: 'Lila Okonkwo',      company: 'Bright Path Ventures',  entity: 'trusts',     stage: 'apptshow', potential: 4200, days: 6,  stalled: false, source: 'Email • Apr 30', email: 'lila@bpv.fund' },
  { id: 'R-2837', name: 'Ethan Cross',       company: 'Cross & Sons',          entity: 'leadgen',    stage: 'apptset',  potential: 1100, days: 4,  stalled: false, source: 'SMS • May 1',   email: 'ethan@crossandsons.com' },
  { id: 'R-2836', name: 'Sasha Lindgren',    company: 'Northpoint Capital',    entity: 'tax',        stage: 'invoice',  potential: 2850, days: 31, stalled: true,  source: 'Email • Apr 4',  email: 'sasha@northpointcap.com' },
  { id: 'R-2835', name: 'Henrik Vasquez',    company: 'HV Holdings',           entity: 'consulting', stage: 'apptset',  potential: 1900, days: 12, stalled: false, source: 'Direct link',   email: 'h.vasquez@hvh.co' },
  { id: 'R-2834', name: 'Rita Bellamy',      company: 'Bellamy Wealth',        entity: 'trusts',     stage: 'lead',     potential: 4200, days: 2,  stalled: false, source: 'SMS • May 3',   email: 'rita@bellamy.io' },
  { id: 'R-2833', name: 'Kenji Park',        company: 'Park Aesthetics',       entity: 'tax',        stage: 'apptshow', potential: 2850, days: 8,  stalled: false, source: 'Email • Apr 27', email: 'kenji@parkaesthetics.co' },
  { id: 'R-2832', name: 'Yusra Mohamed',     company: 'Sahel Logistics',       entity: 'leadgen',    stage: 'won',      potential: 1100, days: 11, stalled: false, source: 'Direct link',   email: 'ym@sahel.co' },
  { id: 'R-2831', name: 'Theo Brandt',       company: 'Brandt Industrial',     entity: 'tax',        stage: 'proposal', potential: 2850, days: 7,  stalled: false, source: 'Email • Apr 29', email: 't.brandt@bind.co' },
  { id: 'R-2830', name: 'Camille Acosta',    company: 'Acosta Realty Group',   entity: 'trusts',     stage: 'apptset',  potential: 4200, days: 14, stalled: true,  source: 'SMS • Apr 21',  email: 'cami@acostarealty.com' },
  { id: 'R-2829', name: 'Jordan Sloane',     company: 'Sloane Dental',         entity: 'consulting', stage: 'lead',     potential: 1900, days: 1,  stalled: false, source: 'Direct link',   email: 'jordan@sloanedental.com' },
  { id: 'R-2828', name: 'Imani Reyes',       company: 'Reyes Capital Partners',entity: 'tax',        stage: 'won',      potential: 5700, days: 25, stalled: false, source: 'Email • Apr 11', email: 'imani@reyescp.com' },
  { id: 'R-2827', name: 'Bram Halvorsen',    company: 'Halvorsen Bros.',       entity: 'leadgen',    stage: 'apptshow', potential: 1100, days: 5,  stalled: false, source: 'SMS • May 1',   email: 'bram@halbros.com' },
];

const LEADERBOARD = [
  { rank: 1, name: 'Avery Thompson',   handle: '@averyt',   gmv: 184500, deals: 31, you: false },
  { rank: 2, name: 'Marcus Liu',       handle: '@marcus.l', gmv: 162300, deals: 28, you: false },
  { rank: 3, name: 'Sienna Park',      handle: '@sienna',   gmv: 144900, deals: 22, you: false },
  { rank: 4, name: 'Daniela Vargas',   handle: '@dvargas',  gmv: 131200, deals: 19, you: false },
  { rank: 5, name: 'Jordan Chen',      handle: '@jchen',    gmv: 118400, deals: 17, you: false },
  { rank: 6, name: 'You — Ryan Mercer', handle: '@ryanm',   gmv: 96850,  deals: 14, you: true  },
  { rank: 7, name: 'Tariq Bennett',    handle: '@tariqb',   gmv: 91200,  deals: 13, you: false },
  { rank: 8, name: 'Mei-Ling Wu',      handle: '@meiling',  gmv: 84300,  deals: 11, you: false },
  { rank: 9, name: 'Drew Saunders',    handle: '@drewsaun', gmv: 78900,  deals: 10, you: false },
  { rank: 10, name: 'Olamide Hart',    handle: '@olahart',  gmv: 71450,  deals: 9,  you: false },
];

const CONTESTS = [
  { id: 'may-trust-blitz', title: 'May Trust Blitz', entity: 'trusts', prize: '$5,000 + Vegas trip', endsIn: '14d 06h', metric: 'Closed Won', myRank: 4, leaderRank: 'Avery Thompson', leaderValue: '11 deals' },
  { id: 'q2-tax-rampup',   title: 'Q2 Tax Ramp-Up', entity: 'tax',    prize: '$2,500 cash bonus', endsIn: '38d 12h', metric: 'Appointments Showed', myRank: 7, leaderRank: 'Marcus Liu', leaderValue: '24 appts' },
  { id: 'spring-newbie',   title: 'Newbie Spring Sprint', entity: null, prize: 'Apple Vision Pro', endsIn: '6d 20h', metric: 'First Closed Won', myRank: null, leaderRank: 'Tariq Bennett', leaderValue: '3 deals' },
];

const ASSETS = [
  { id: 'a1', kind: 'SMS',    entity: 'trusts',  title: 'Cold intro — high-net-worth',  copy: 'Hey {{first}} — saw your post about wanting to protect what you\'ve built. Quick question: do you have a trust set up yet, or still in an LLC?', uses: 412 },
  { id: 'a2', kind: 'SMS',    entity: 'trusts',  title: 'Re-engage stalled lead',       copy: '{{first}} — circling back on the trust convo. The team has 2 strategy slots open this week. Worth a 15-min call?', uses: 188 },
  { id: 'a3', kind: 'Email',  entity: 'tax',     title: 'CPA referral — value first',   copy: 'Subject: Quick gift for {{first}}\n\nHey {{first}}, recorded a 4-min Loom on the 199A loophole for service businesses your size. Link inside…', uses: 273 },
  { id: 'a4', kind: 'Email',  entity: 'tax',     title: 'Year-end planning urgency',    copy: 'Subject: 47 days left — and one thing you can still do\n\nQ4 is the only window for…', uses: 96 },
  { id: 'a5', kind: 'Script', entity: 'trusts',  title: 'Objection: "Too expensive"',   copy: 'Acknowledge → reframe → calculator. "I hear you — most clients say that *before* we map their actual exposure. Let me show you what one audit costs vs. what setup costs…"', uses: 504 },
  { id: 'a6', kind: 'Script', entity: 'leadgen', title: 'Discovery call opener',        copy: 'First 90 seconds: 1) Permission, 2) Their #1 KPI, 3) What\'s blocking it, 4) Pivot to outcome story.', uses: 221 },
  { id: 'a7', kind: 'Form',   entity: 'consulting', title: 'Pre-call qualification',   copy: '8-question Typeform link. Auto-routes hot leads to your inbox + sets a Cal.com meeting.', uses: 134 },
  { id: 'a8', kind: 'Deck',   entity: 'tax',     title: '"Tax Strategy 101" — co-brand', copy: '12-slide PDF you can share or screen-share. Your name + photo auto-stamped on slide 12.', uses: 179 },
  { id: 'a9', kind: 'Email',  entity: 'leadgen', title: 'Booked-call confirmation',     copy: 'Subject: You\'re booked, {{first}} — read this before we talk\n\nThree things to have ready…', uses: 311 },
];

const TRAINING = {
  trusts: {
    progress: 1.0,
    modules: [
      { id: 'm1', title: 'Why trusts? The 3-minute pitch', length: '12 min', done: true },
      { id: 'm2', title: 'Spotting a qualified prospect', length: '18 min', done: true },
      { id: 'm3', title: 'Handling the top 7 objections', length: '24 min', done: true },
      { id: 'm4', title: 'Compliance — what NOT to say', length: '15 min', done: true },
      { id: 'm5', title: 'Certification quiz', length: '10 q', done: true, isQuiz: true },
    ],
  },
  tax: {
    progress: 1.0,
    modules: [
      { id: 'm1', title: 'The tax-strategy market', length: '14 min', done: true },
      { id: 'm2', title: 'Who is and isn\'t a fit', length: '11 min', done: true },
      { id: 'm3', title: 'Translating CPA-speak', length: '22 min', done: true },
      { id: 'm4', title: 'Certification quiz', length: '10 q', done: true, isQuiz: true },
    ],
  },
  consulting: {
    progress: 0.4,
    modules: [
      { id: 'm1', title: 'JFJ Consulting overview', length: '16 min', done: true },
      { id: 'm2', title: 'Operator vs. founder language', length: '20 min', done: true },
      { id: 'm3', title: 'Pricing & engagement models', length: '18 min', done: false, current: true },
      { id: 'm4', title: 'Case studies — three wins', length: '25 min', done: false },
      { id: 'm5', title: 'Certification quiz', length: '12 q', done: false, isQuiz: true, locked: true },
    ],
  },
  leadgen: {
    progress: 0.0,
    modules: [
      { id: 'm1', title: 'The Lead Gen offer in 90 seconds', length: '9 min', done: false, current: true },
      { id: 'm2', title: 'Ideal client profile', length: '14 min', done: false },
      { id: 'm3', title: 'Pricing & SLAs', length: '16 min', done: false },
      { id: 'm4', title: 'Certification quiz', length: '8 q', done: false, isQuiz: true, locked: true },
    ],
  },
};

const QUIZ = {
  entityId: 'consulting',
  title: 'JFJ Consulting — Certification',
  questions: [
    {
      q: 'Which of the following is the BEST signal that a prospect fits JFJ Consulting?',
      options: [
        '$1M+ revenue and a clear KPI they can\'t move',
        'They\'ve "always wanted" to grow but don\'t know how',
        'They have a marketing agency they\'re unhappy with',
        'They are pre-revenue and need a co-founder',
      ],
      correct: 0,
    },
    {
      q: 'JFJ Consulting\'s standard engagement model is:',
      options: [
        'Hourly billing, no retainer',
        '$15k–$45k/mo retainer for 6-month minimum',
        'Pure equity with no cash component',
        'Per-deliverable flat fees',
      ],
      correct: 1,
    },
    {
      q: 'A prospect says: "We tried consultants before — they didn\'t deliver." Best response?',
      options: [
        '"Most consultants don\'t. Here\'s how we\'re structurally different…"',
        '"That\'s on you for picking the wrong one."',
        '"Just trust us this time."',
        '"Then maybe consulting isn\'t right for you."',
      ],
      correct: 0,
    },
  ],
};

const ANNOUNCEMENTS = [
  { id: 'an1', priority: 'high',   from: 'Ops',     ts: '2h ago',  title: 'New comp plan — Trusts payouts +20% through May 31', body: 'We\'re testing higher payouts on Trusts to push closed-won. Effective immediately — applies to any deal closing this month.' },
  { id: 'an2', priority: 'normal', from: 'Product', ts: '1d ago',  title: 'Pipeline view: bulk-update referrals shipped', body: 'Select multiple referrals → tag stalled or send a follow-up template.' },
  { id: 'an3', priority: 'normal', from: 'Comms',   ts: '3d ago',  title: 'Office Hours moved to Thursdays at 2pm CT', body: 'Same Zoom link. Bring deals you want pressure-tested.' },
  { id: 'an4', priority: 'high',   from: 'CEO',     ts: '5d ago',  title: 'Quarterly all-hands recording is live', body: 'Skip to 14:30 for the affiliate roadmap.' },
];

// Affiliate identity (the logged-in user)
const ME = {
  name: 'Ryan Mercer',
  handle: '@ryanm',
  initials: 'RM',
  joined: 'Mar 2026',
  rank: 6,
  totalEarned: 18420,
  pendingEarned: 7540,
  closedDeals: 14,
  stalledCount: 2,
};

// Aggregate KPIs
const KPIS = {
  earnedThisMonth: 12480,
  earnedDelta: 0.34,
  pendingPayout: 7540,
  liveReferrals: 23,
  liveReferralsDelta: 0.12,
  conversionRate: 0.41,
  conversionDelta: -0.03,
};

window.JFJ = {
  ENTITIES, ENTITY_BY_ID, PIPELINE_STAGES, STAGE_BY_ID,
  REFERRALS, LEADERBOARD, CONTESTS, ASSETS, TRAINING, QUIZ,
  ANNOUNCEMENTS, ME, KPIS,
};
