/* ROLE PATHS — Guided learning tracks for each pilot role
 *
 * Each path combines ordered Learn lessons with matching Practice scenarios.
 * Paths are role-specific, curated from existing Chairside curriculum.
 */

const ROLE_PATHS = {
  tc: {
    id: "tc",
    name: "Treatment Coordinator",
    description: "Master case acceptance through structured learning and AI practice",
    color: "#C77A2A",
    steps: [
      {
        id: "tc-step-1",
        type: "learn",
        title: "Understand patient decision-making",
        moduleId: "m1",
        lessonId: "l1-1",
        duration: 16,
        description: "Learn how patients actually decide — the foundation for everything that follows"
      },
      {
        id: "tc-step-2",
        type: "learn",
        title: "Master the criteria elicitation",
        moduleId: "m5",
        lessonId: "l5-1",
        duration: 22,
        description: "The four-question framework that surfaces what patients really value"
      },
      {
        id: "tc-step-3",
        type: "practice",
        title: "Practice: Criteria elicitation",
        scriptId: "tc-script-1",
        roleId: "tc",
        description: "Run the opening conversation with AI before presenting treatment"
      },
      {
        id: "tc-step-4",
        type: "learn",
        title: "Learn the 12-move presentation",
        moduleId: "m6",
        lessonId: "l6-1",
        duration: 28,
        description: "The complete structure of a high-acceptance case presentation"
      },
      {
        id: "tc-step-5",
        type: "practice",
        title: "Practice: Full case presentation",
        scriptId: "tc-script-2",
        roleId: "tc",
        description: "Present a complete treatment plan with AI patient"
      },
      {
        id: "tc-step-6",
        type: "learn",
        title: "Handle the seven objections",
        moduleId: "m7",
        lessonId: "l7-1",
        duration: 16,
        description: "Master the reframes for 'it doesn't hurt' and six other common objections"
      },
      {
        id: "tc-step-7",
        type: "practice",
        title: "Practice: Financial transition",
        scriptId: "tc-script-3",
        roleId: "tc",
        description: "Move from clinical to financial conversation without creating tension"
      },
      {
        id: "tc-step-8",
        type: "learn",
        title: "Master the financial conversation",
        moduleId: "m11",
        lessonId: "l11-1",
        duration: 18,
        description: "Quote fees in a way that doesn't sting"
      }
    ]
  },

  hyg: {
    id: "hyg",
    name: "Hygienist",
    description: "Build trust and surface treatment through clinical conversation",
    color: "#2A8A88",
    steps: [
      {
        id: "hyg-step-1",
        type: "learn",
        title: "Understand your role in case acceptance",
        moduleId: "m1",
        lessonId: "l1-1",
        duration: 16,
        description: "Why the first 90 seconds with you set up everything that follows"
      },
      {
        id: "hyg-step-2",
        type: "learn",
        title: "Master co-diagnosis",
        moduleId: "m4",
        lessonId: "l4-1",
        duration: 22,
        description: "The hygienist as first witness — how to set up the doctor's recommendation"
      },
      {
        id: "hyg-step-3",
        type: "practice",
        title: "Practice: The recall opening",
        scriptId: "hyg-script-1",
        roleId: "hyg",
        description: "Open the visit with rapport-building before clinical work"
      },
      {
        id: "hyg-step-4",
        type: "practice",
        title: "Practice: The perio conversation",
        scriptId: "hyg-script-2",
        roleId: "hyg",
        description: "Deliver perio diagnosis clearly and recommend next steps"
      },
      {
        id: "hyg-step-5",
        type: "learn",
        title: "Pace the anxious patient",
        moduleId: "m8",
        lessonId: "l8-1",
        duration: 18,
        description: "Transform dental anxiety instead of working around it"
      },
      {
        id: "hyg-step-6",
        type: "practice",
        title: "Practice: Anxious patient reassurance",
        scriptId: "hyg-script-4",
        roleId: "hyg",
        description: "Handle dental anxiety with structure and empathy"
      },
      {
        id: "hyg-step-7",
        type: "practice",
        title: "Practice: Surface unscheduled treatment",
        scriptId: "hyg-script-3",
        roleId: "hyg",
        description: "Recover diagnosed treatment that never got scheduled"
      }
    ]
  },

  doc: {
    id: "doc",
    name: "Doctor",
    description: "Earn trust and land recommendations that the patient accepts",
    color: "#4A5899",
    steps: [
      {
        id: "doc-step-1",
        type: "learn",
        title: "Understand patient decision-making",
        moduleId: "m1",
        lessonId: "l1-1",
        duration: 16,
        description: "What happens in the patient's nervous system before they say yes or no"
      },
      {
        id: "doc-step-2",
        type: "learn",
        title: "Master the objection reframes",
        moduleId: "m7",
        lessonId: "l7-1",
        duration: 16,
        description: "The seven objections you'll hear every week and how to address them"
      },
      {
        id: "doc-step-3",
        type: "practice",
        title: "Practice: The diagnostic exam",
        scriptId: "doc-script-1",
        roleId: "doc",
        description: "Build trust and surface patient priorities during the routine exam"
      },
      {
        id: "doc-step-4",
        type: "learn",
        title: "Understand your role in acceptance",
        moduleId: "m9",
        lessonId: "l9-1",
        duration: 18,
        description: "What the doctor is actually for — authority without pressure"
      },
      {
        id: "doc-step-5",
        type: "practice",
        title: "Practice: The TC pre-frame",
        scriptId: "doc-script-2",
        roleId: "doc",
        description: "Hand off to the TC in a way that makes their job easier"
      },
      {
        id: "doc-step-6",
        type: "learn",
        title: "Master Clarity → Motion",
        moduleId: "edge",
        lessonId: "edge-1",
        duration: 16,
        description: "Present one best option with conviction — the doctor's edge"
      },
      {
        id: "doc-step-7",
        type: "practice",
        title: "Practice: Handle clinical pushback",
        scriptId: "doc-script-4",
        roleId: "doc",
        description: "Defend your diagnosis with reasoning while honoring patient agency"
      }
    ]
  },

  own: {
    id: "own",
    name: "Practice Owner",
    description: "Install this work in your practice and coach your team",
    color: "#64748B",
    steps: [
      {
        id: "own-step-1",
        type: "learn",
        title: "Understand patient decision-making",
        moduleId: "m1",
        lessonId: "l1-1",
        duration: 16,
        description: "The foundation every team member must share"
      },
      {
        id: "own-step-2",
        type: "learn",
        title: "The cost of 'let me think about it'",
        moduleId: "m1",
        lessonId: "l1-2",
        duration: 14,
        description: "Real numbers on unfinished treatment — why this work matters"
      },
      {
        id: "own-step-3",
        type: "learn",
        title: "Master team installation",
        moduleId: "m12",
        lessonId: "l12-1",
        duration: 14,
        description: "Why most communication training fails and the structural fix"
      },
      {
        id: "own-step-4",
        type: "practice",
        title: "Practice: Observe TC presentation",
        scriptId: "tc-script-2",
        roleId: "tc",
        description: "Watch what good looks like — the full case presentation"
      },
      {
        id: "own-step-5",
        type: "practice",
        title: "Practice: Observe hygiene handoff",
        scriptId: "hyg-script-7",
        roleId: "hyg",
        description: "See how hygienists set up the doctor's exam"
      },
      {
        id: "own-step-6",
        type: "practice",
        title: "Practice: Observe doctor exam",
        scriptId: "doc-script-1",
        roleId: "doc",
        description: "Watch the diagnostic exam that builds trust"
      },
      {
        id: "own-step-7",
        type: "learn",
        title: "Coach without micromanaging",
        moduleId: "m12",
        lessonId: "l12-2",
        duration: 16,
        description: "How to give feedback that lands and sticks"
      }
    ]
  }
};

// Helper: Get path for a role
function getPathForRole(roleId) {
  return ROLE_PATHS[roleId] || null;
}

// Helper: Get step by id
function getStep(roleId, stepId) {
  const path = ROLE_PATHS[roleId];
  if (!path) return null;
  return path.steps.find(s => s.id === stepId) || null;
}

// Helper: Get progress summary
function getPathProgress(roleId, completedSteps = []) {
  const path = ROLE_PATHS[roleId];
  if (!path) return { total: 0, completed: 0, percent: 0 };
  const total = path.steps.length;
  const completed = path.steps.filter(s => completedSteps.includes(s.id)).length;
  const percent = total > 0 ? Math.round((completed / total) * 100) : 0;
  return { total, completed, percent };
}

// Helper: Get next uncompleted step
function getNextStep(roleId, completedSteps = []) {
  const path = ROLE_PATHS[roleId];
  if (!path) return null;
  return path.steps.find(s => !completedSteps.includes(s.id)) || null;
}

// Export to window
Object.assign(window, { 
  ROLE_PATHS, 
  getPathForRole, 
  getStep, 
  getPathProgress,
  getNextStep
});
