# Stage-Driven Lead Profile Plan (0.1% Standard)

## Overview

Transform the lead profile so that **platform stage DRIVES the entire experience**. Not just a badge - the stage determines what Tony sees, what actions are prominent, and what scripts he uses.

---

## Architecture

```
Lead Profile Page
├── Stage Progress Visualizer (top hero section)
│   ├── Visual pipeline with checkmarks
│   ├── Progress bar with percentage
│   └── Stuck alert badge
├── AI Diagnosis Card (primary action area)
│   ├── Pattern detection (forgot vs avoiding)
│   ├── Likely blocker reason
│   ├── "Your Play" script
│   └── Quick action buttons
├── Dynamic Primary CTA (big button)
│   └── Stage-specific action
├── Similar Wins Card
│   └── Leads who progressed from same stage
├── Stage Journey Timeline
│   ├── Stage transitions with dates
│   ├── Platform logins
│   ├── Your calls/SMS
│   └── Stuck indicators
└── Existing Profile Sections
    └── Contact info, Intel Brief, etc.
```

---

## Components

### 1. Stage Progress Visualizer

**Component:** `StageProgressVisualizer.jsx`

**Visual:**
```
┌──────────────────────────────────────────────────────────────────┐
│  CONTRACTOR ACTIVATION                              80% to Active │
│                                                                   │
│  ✅ Signed Up → ✅ Profile → 🟡 STRIPE READY → ⬜ Job → ⬜ Hired │
│  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━░░░░░░░░░░░░░░░░░│
│                               ▲                                   │
│                          STUCK 12 DAYS                            │
│                     "Next: Connect Stripe Payments"               │
└──────────────────────────────────────────────────────────────────┘
```

**Props:**
- `type`: 'worker' | 'contractor'
- `currentStage`: string
- `daysInStage`: number
- `stageChangedAt`: Date
- `platformData`: object

**Logic:**
- Worker stages: signed_up → profile_complete → job_ready → applied → working → proven
- Contractor stages: signed_up → profile_complete → stripe_ready → job_posted → hired → active
- Calculate percentage: (currentStageIndex / totalStages) * 100
- Show stuck badge if daysInStage >= 7

---

### 2. AI Diagnosis Card

**Component:** `StageDiagnosisCard.jsx`

**Visual:**
```
┌──────────────────────────────────────────────────────────────────┐
│ 🔍 AI DIAGNOSIS                                                  │
│                                                                   │
│ Pattern: 😴 FORGOT (hasn't logged in for 12 days)                │
│                                                                   │
│ Likely Blocker:                                                   │
│ "Stripe setup feels intimidating. They started but didn't finish │
│  the verification step."                                         │
│                                                                   │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ 📋 YOUR PLAY                                                 │ │
│ │                                                               │ │
│ │ "Hey John, noticed you started setting up payments but       │ │
│ │  didn't quite finish. It's actually just 2 more steps -      │ │
│ │  want me to walk you through it real quick? Takes 3 mins."   │ │
│ └──────────────────────────────────────────────────────────────┘ │
│                                                                   │
│ [📋 Copy Script]  [📞 Call with Script]  [💬 Send Guide SMS]     │
└──────────────────────────────────────────────────────────────────┘
```

**Pattern Detection:**
- `forgot`: No login > 7 days, low login frequency
- `avoiding`: Recent logins but no progress
- `confused`: High logins but stuck
- `blocked`: External blocker (technical, etc.)

---

### 3. Stage Journey Timeline

**Component:** `StageJourneyTimeline.jsx`

**Visual:**
```
┌──────────────────────────────────────────────────────────────────┐
│ 📍 STAGE JOURNEY                                                 │
│                                                                   │
│ ● Jan 15  Signed Up (via Google search)                         │
│ │                                                                │
│ │  Jan 16  Logged in, viewed dashboard                          │
│ │  Jan 17  You called - discussed needs (3 min)                 │
│ │                                                                │
│ ● Jan 18  Profile Complete                                       │
│ │                                                                │
│ │  Jan 19  Logged in, started Stripe setup                      │
│ │  Jan 20  Abandoned at verification step                       │
│ │                                                                │
│ ● Jan 20  Stripe Ready (current)                                │
│ │                                                                │
│ │  Jan 21  You sent SMS reminder - no response                  │
│ │  ⚠️ Jan 22-Feb 1: NO ACTIVITY (12 days)                       │
│ │                                                                │
│ ○ ─ ─ ─  Job Posted (next)                                      │
│ ○ ─ ─ ─  Hired                                                  │
│ ○ ─ ─ ─  Active                                                 │
└──────────────────────────────────────────────────────────────────┘
```

---

### 4. Dynamic Primary Action

**Component:** `DynamicPrimaryAction.jsx`

**Stage-to-Action Mapping:**

| Stage | Type | Primary Action | Secondary Actions |
|-------|------|----------------|-------------------|
| `signed_up` | Both | "Help Complete Profile" | Send profile tips SMS |
| `profile_complete` | Worker | "Explain Job Search" | Send job search guide |
| `profile_complete` | Contractor | "Walk Through Stripe Setup" | Send Stripe guide |
| `stripe_ready` | Contractor | "Walk Through Stripe Setup" | Send setup reminder |
| `job_ready` | Worker | "Help Find First Job" | Send job alerts |
| `job_posted` | Contractor | "Check In On Applicants" | Send applicant tips |
| `applied` | Worker | "Follow Up On Application" | Send interview tips |
| `hired` | Contractor | "Ensure First Job Success" | Send onboarding tips |
| `working` | Worker | "Check In On Job" | Send completion tips |

---

### 5. Similar Wins Card

**Component:** `SimilarWinsCard.jsx`

**Visual:**
```
┌──────────────────────────────────────────────────────────────────┐
│ 🏆 SIMILAR WINS                                                  │
│                                                                   │
│ Leads who were stuck at STRIPE READY and progressed:             │
│                                                                   │
│ ┌────────────────────────────────────────────────────────────┐   │
│ │ Mike's Plumbing                                            │   │
│ │ Stuck 9 days → You called → Active in 2 days               │   │
│ │ Revenue: $4,200  │  Key: Walked through Stripe on call     │   │
│ └────────────────────────────────────────────────────────────┘   │
│                                                                   │
│ 💡 Pattern: 80% progressed after a CALL (not SMS)                │
└──────────────────────────────────────────────────────────────────┘
```

---

## API Endpoints

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/api/activation/diagnose/:leadId` | GET | AI diagnosis with pattern, blocker, script |
| `/api/activation/journey/:leadId` | GET | Full stage journey with activities |
| `/api/activation/similar-wins/:leadId` | GET | Leads who progressed from same stage |

### Diagnosis Response
```json
{
  "pattern": "forgot",
  "patternConfidence": 0.85,
  "patternEvidence": "No login for 12 days, opened 2 reminder emails",
  "likelyBlocker": "Stripe verification feels complex",
  "script": "Hey John, noticed you started...",
  "smsTemplate": "Hi John! Quick Q - need help finishing...",
  "recommendedAction": "call",
  "actionLabel": "Walk Through Stripe Setup"
}
```

### Journey Response
```json
{
  "stages": [
    {
      "stage": "signed_up",
      "label": "Signed Up",
      "reachedAt": "2025-01-15T10:00:00Z",
      "status": "completed"
    }
  ],
  "activities": [
    {
      "type": "platform_login",
      "date": "2025-01-19T09:00:00Z",
      "description": "Logged in, started Stripe setup"
    },
    {
      "type": "your_call",
      "date": "2025-01-17T14:30:00Z",
      "description": "Discussed hiring needs",
      "duration": "3 min"
    }
  ]
}
```

### Similar Wins Response
```json
{
  "wins": [
    {
      "company": "Mike's Plumbing",
      "stuckStage": "stripe_ready",
      "daysStuck": 9,
      "progressedVia": "call",
      "daysToProgress": 2,
      "revenue": 4200,
      "keyFactor": "Walked through Stripe setup on call"
    }
  ],
  "pattern": {
    "insight": "80% progressed after a CALL (not SMS)",
    "recommendedAction": "call"
  }
}
```

---

## Files to Create

| File | Purpose |
|------|---------|
| `src/services/stageDiagnosis.js` | Pattern detection + script generation |
| `admin/src/components/StageProgressVisualizer.jsx` | Visual pipeline + progress bar |
| `admin/src/components/StageDiagnosisCard.jsx` | AI diagnosis + script + actions |
| `admin/src/components/StageJourneyTimeline.jsx` | Full timeline visualization |
| `admin/src/components/DynamicPrimaryAction.jsx` | Stage-specific CTA |
| `admin/src/components/SimilarWinsCard.jsx` | Success stories from same stage |

## Files to Modify

| File | Changes |
|------|---------|
| `src/routes/activation.js` | Add 3 new endpoints |
| `admin/src/pages/LeadProfile.jsx` | Add all new components to layout |
| `admin/src/api/client.js` | Add new activation API methods |
| `src/services/ai.js` | Update Intel Brief prompt with stage context |
| `admin/src/components/IntelBriefModal.jsx` | Add stage context section |

---

## Build Order

### Phase 1: Data & API Layer
1. Add stage diagnosis service (`src/services/stageDiagnosis.js`)
2. Add journey endpoint (`GET /api/activation/journey/:leadId`)
3. Add diagnosis endpoint (`GET /api/activation/diagnose/:leadId`)
4. Add similar-wins endpoint (`GET /api/activation/similar-wins/:leadId`)
5. Add API client methods

### Phase 2: Core Components
6. `StageProgressVisualizer.jsx`
7. `StageDiagnosisCard.jsx`
8. `DynamicPrimaryAction.jsx`
9. `SimilarWinsCard.jsx`

### Phase 3: Timeline & Integration
10. `StageJourneyTimeline.jsx`
11. Update `LeadProfile.jsx` layout
12. Update Intel Brief (prompt + modal)

### Phase 4: Polish
13. Add copy-to-clipboard for scripts
14. Add "Call with Script" flow
15. Build, test, deploy

---

## Progress Tracking

- [x] Phase 1: Data & API Layer
- [x] Phase 2: Core Components
- [x] Phase 3: Timeline & Integration
- [x] Phase 4: Polish

**BUILD COMPLETE** - All 15 steps implemented and deployed.
