/**
 * TabataFit Program Workouts
 * 3 Programs × 4 Weeks × 5 Workouts = 60 physiotherapist-designed workouts
 * All workouts: 8 exercises × 20s work / 10s rest = 4 minutes
 */

import { Program, Assessment, ProgramId, WeekNumber, Week } from '../types/program'
import type { WorkoutLevel, WorkoutCategory, MusicVibe } from '../types/workout'

type ProgramWorkoutInput = {
  id: string
  week: 1 | 2 | 3 | 4
  order: number
  title: string
  description: string
  exercises: string[]
  equipment: string[]
  focus: string[]
  tips: string[]
}

/** Derive difficulty level from the week number in a progressive program */
function getLevelFromWeek(week: number): WorkoutLevel {
  if (week <= 2) return 'Beginner'
  if (week === 3) return 'Intermediate'
  return 'Advanced'
}

// Helper to create exercises with consistent structure
const createExercise = (name: string, modification?: string, progression?: string) => ({
  name,
  duration: 20,
  modification,
  progression,
})

// ═══════════════════════════════════════════════════════════════════════════
// UPPER BODY PROGRAM
// ═══════════════════════════════════════════════════════════════════════════

const upperBodyWorkouts: ProgramWorkoutInput[] = [
  // WEEK 1: Foundation
  {
    id: 'ub-w1-d1',
    week: 1,
    order: 1,
    title: 'Posture Perfect',
    description: 'Build foundational shoulder stability and correct rounded posture',
    exercises: [
      'Wall Angels',
      'Scapular Push-ups',
      'Arm Circles Forward',
      'Arm Circles Backward',
      'Doorway Chest Opens',
      'Band Pull-Aparts',
      'Wall Push-ups',
      'Shoulder Blade Squeezes',
    ],
    equipment: ['Resistance band', 'Wall'],
    focus: ['Posture', 'Shoulder Mobility', 'Scapular Control'],
    tips: [
      'Keep movements slow and controlled',
      'Focus on feeling shoulder blades move',
      'Breathe deeply throughout',
    ],
  },
  {
    id: 'ub-w1-d2',
    week: 1,
    order: 2,
    title: 'Shoulder Stability',
    description: 'Strengthen the rotator cuff and stabilize shoulder joints',
    exercises: [
      'Y-T-W Raises',
      'Arm Hugs',
      'Band External Rotation L',
      'Band External Rotation R',
      'Plank to Down Dog',
      'Band Face Pulls',
      'Incline Push-ups',
      'Dead Bug Hold',
    ],
    equipment: ['Resistance band', 'Wall or elevated surface'],
    focus: ['Rotator Cuff', 'Shoulder Stability', 'Core'],
    tips: [
      'Keep elbows at 90° for rotations',
      'Move with intention, not speed',
      'Stop if you feel any pinching',
    ],
  },
  {
    id: 'ub-w1-d3',
    week: 1,
    order: 3,
    title: 'Chest & Back Balance',
    description: 'Create muscular balance between pushing and pulling muscles',
    exercises: [
      'Standing Band Rows',
      'Push-up Plank Hold',
      'Band Chest Opens',
      'Wall Slide Holds',
      'Renegade Row Prep',
      'Modified Push-ups',
      'Band Reverse Flyes',
      'Prone Y Raises',
    ],
    equipment: ['Resistance band', 'Wall'],
    focus: ['Chest', 'Back', 'Postural Balance'],
    tips: [
      'Squeeze shoulder blades on rows',
      'Keep core engaged throughout',
      'Quality over quantity',
    ],
  },
  {
    id: 'ub-w1-d4',
    week: 1,
    order: 4,
    title: 'Arm Foundations',
    description: 'Build arm strength with joint-friendly movements',
    exercises: [
      'Wall Push-ups',
      'Tricep Wall Dips',
      'Band Bicep Curls',
      'Plank Shoulder Taps',
      'Push-up Hold Low',
      'Tricep Kickbacks',
      'Hammer Curls with Band',
      'Arm Circles Combo',
    ],
    equipment: ['Resistance band', 'Wall'],
    focus: ['Arms', 'Biceps', 'Triceps'],
    tips: [
      'Control the lowering phase',
      'Full range of motion',
      'Keep elbows close on tricep work',
    ],
  },
  {
    id: 'ub-w1-d5',
    week: 1,
    order: 5,
    title: 'Full Upper Mobility',
    description: 'Improve range of motion and movement quality',
    exercises: [
      'Arm Swings Forward',
      'Arm Swings Backward',
      'Shoulder Rolls',
      'Neck Mobility Flow',
      'Thoracic Spine Rotations',
      'Chest Openers Dynamic',
      'Scapular Push-ups',
      'Child\'s Pose to Up Dog',
    ],
    equipment: ['None'],
    focus: ['Mobility', 'Flexibility', 'Recovery'],
    tips: [
      'Move through full range',
      'Gentle and controlled',
      'Focus on breathing',
    ],
  },

  // WEEK 2: Building
  {
    id: 'ub-w2-d1',
    week: 2,
    order: 1,
    title: 'Dynamic Shoulders',
    description: 'Increase shoulder strength with dynamic movements',
    exercises: [
      'Band Overhead Press',
      'Push-ups with Rotation',
      'Band Lateral Raises',
      'Commando Planks',
      'Band Front Raises',
      'Spiderman Push-ups',
      'Band Upright Rows',
      'Plank Up-Downs',
    ],
    equipment: ['Resistance band'],
    focus: ['Shoulders', 'Dynamic Strength', 'Stability'],
    tips: [
      'Keep core tight during rotations',
      'Full extension on presses',
      'Control the movement',
    ],
  },
  {
    id: 'ub-w2-d2',
    week: 2,
    order: 2,
    title: 'Push Power',
    description: 'Develop pushing strength with progressive variations',
    exercises: [
      'Incline Push-ups',
      'Decline Push-ups',
      'Wide Push-ups',
      'Diamond Push-ups',
      'Push-up Hold Mid',
      'Pike Push-ups',
      'Push-up to Side Plank',
      'Chest Tap Push-ups',
    ],
    equipment: ['Elevated surface'],
    focus: ['Chest', 'Triceps', 'Pushing Strength'],
    tips: [
      'Modify on knees if needed',
      'Keep body in straight line',
      'Lower with control',
    ],
  },
  {
    id: 'ub-w2-d3',
    week: 2,
    order: 3,
    title: 'Pull & Row Strength',
    description: 'Strengthen back muscles with pulling movements',
    exercises: [
      'Band Rows',
      'Superman Holds',
      'Band Reverse Flyes',
      'Prone W Raises',
      'Band Face Pulls',
      'Reverse Snow Angels',
      'Single Arm Band Row L',
      'Single Arm Band Row R',
    ],
    equipment: ['Resistance band'],
    focus: ['Back', 'Rhomboids', 'Posture'],
    tips: [
      'Pull shoulder blades together',
      'Keep shoulders down and back',
      'Squeeze at the end range',
    ],
  },
  {
    id: 'ub-w2-d4',
    week: 2,
    order: 4,
    title: 'Arm Sculptor',
    description: 'Intensive arm training with band resistance',
    exercises: [
      'Band Bicep Curls',
      'Band Tricep Extensions',
      'Hammer Curls Band',
      'Overhead Tricep Band',
      'Concentration Curls',
      'Tricep Dips',
      'Zottman Curls Band',
      'Diamond Push-ups',
    ],
    equipment: ['Resistance band', 'Chair or bench'],
    focus: ['Biceps', 'Triceps', 'Arm Definition'],
    tips: [
      'Full range of motion',
      'Control both up and down',
      'Keep tension on the band',
    ],
  },
  {
    id: 'ub-w2-d5',
    week: 2,
    order: 5,
    title: 'Core Integration',
    description: 'Connect upper body movements with core stability',
    exercises: [
      'Plank to Push-up',
      'Renegade Rows',
      'Push-up to T-Rotation',
      'Plank Jacks',
      'Shoulder Tap Push-ups',
      'Plank Up-Downs',
      'Walkout to Push-up',
      'Plank Hold',
    ],
    equipment: ['None'],
    focus: ['Core', 'Shoulders', 'Integration'],
    tips: [
      'Keep hips stable',
      'No rocking side to side',
      'Breathe steadily',
    ],
  },

  // WEEK 3: Challenge
  {
    id: 'ub-w3-d1',
    week: 3,
    order: 1,
    title: 'Explosive Upper',
    description: 'Add power and explosiveness to upper body movements',
    exercises: [
      'Clap Push-ups (or fast)',
      'Plyo Push-ups',
      'Explosive Band Press',
      'Medicine Ball Slams (or band)',
      'Push-up Burpees',
      'Band Snatch',
      'Power Push-ups',
      'Mountain Climber Push-ups',
    ],
    equipment: ['Resistance band', 'Optional: light weights'],
    focus: ['Power', 'Explosiveness', 'Speed'],
    tips: [
      'Land softly on joints',
      'Modify if joints feel stressed',
      'Maximum effort each rep',
    ],
  },
  {
    id: 'ub-w3-d2',
    week: 3,
    order: 2,
    title: 'Endurance Push',
    description: 'Build muscular endurance with higher volume patterns',
    exercises: [
      'Fast Push-ups',
      'Band Press Burnout',
      'Dive Bombers',
      'Pike Push-ups',
      'Close Grip Push-ups',
      'Hindu Push-ups',
      'Archer Push-ups L',
      'Archer Push-ups R',
    ],
    equipment: ['Resistance band'],
    focus: ['Endurance', 'Pushing', 'Volume'],
    tips: [
      'Maintain form as you fatigue',
      'Take mini breaks if needed',
      'Focus on continuous movement',
    ],
  },
  {
    id: 'ub-w3-d3',
    week: 3,
    order: 3,
    title: 'Back & Core Blast',
    description: 'Intensive back workout with core integration',
    exercises: [
      'Pull-up Progression',
      'Band Rows Fast',
      'Superman to Plank',
      'Reverse Flyes Pulse',
      'Band High Rows',
      'Prone Cobras Hold',
      'Single Arm Rows Fast L',
      'Single Arm Rows Fast R',
    ],
    equipment: ['Resistance band', 'Pull-up bar optional'],
    focus: ['Back', 'Lats', 'Core Connection'],
    tips: [
      'Engage lats on every pull',
      'Keep movements explosive',
      'Mind-muscle connection',
    ],
  },
  {
    id: 'ub-w3-d4',
    week: 3,
    order: 4,
    title: 'Arm Intensity',
    description: 'High-intensity arm training with compound movements',
    exercises: [
      'Commando Curls',
      'Tricep Burnout Set',
      '21s Bicep Curls',
      'Close to Wide Push-ups',
      'Band Hammer Curls Fast',
      'Tricep Extension Burnout',
      'Slow Negative Curls',
      'Fast Tricep Dips',
    ],
    equipment: ['Resistance band', 'Chair'],
    focus: ['Arms', 'Intensity', 'Muscle Fatigue'],
    tips: [
      'Push through the burn',
      'Maintain form on fatigue',
      'Control the negatives',
    ],
  },
  {
    id: 'ub-w3-d5',
    week: 3,
    order: 5,
    title: 'Total Upper Challenge',
    description: 'Complete upper body challenge combining all elements',
    exercises: [
      'Burpee Push-ups',
      'Renegade Row Push-ups',
      'Plank to Down Dog',
      'Shoulder Complex',
      'T Push-ups',
      'Walkout Push-ups',
      'Plank Rotation Reach',
      'Final Push-up Burnout',
    ],
    equipment: ['Resistance band'],
    focus: ['Total Upper Body', 'Challenge', 'Integration'],
    tips: [
      'This is tough - pace yourself',
      'Modify push-ups on knees if needed',
      'Finish strong!',
    ],
  },

  // WEEK 4: Peak Performance
  {
    id: 'ub-w4-d1',
    week: 4,
    order: 1,
    title: 'Peak Power',
    description: 'Maximum intensity power and strength movements',
    exercises: [
      'Explosive Push-ups Max',
      'Band Clean & Press',
      'Power Rows',
      'Plyo Push-up Variations',
      'Snatch Band Power',
      'Clap Push-ups',
      'Thrusters Band',
      'Max Effort Push-ups',
    ],
    equipment: ['Resistance band'],
    focus: ['Peak Power', 'Max Effort', 'Strength'],
    tips: [
      'Give 100% every rep',
      'Full explosive range',
      'Recover between if needed',
    ],
  },
  {
    id: 'ub-w4-d2',
    week: 4,
    order: 2,
    title: 'Strength Peak',
    description: 'Maximum strength challenge with slow tempos',
    exercises: [
      'Slow Push-ups (5s down)',
      'Max Hold Plank Push',
      'Slow Rows (5s squeeze)',
      'Isometric Push-up Holds',
      'Eccentric-Only Push-ups',
      'Max Tension Band Rows',
      'Pike Push-up Holds',
      'Final Burnout Set',
    ],
    equipment: ['Resistance band'],
    focus: ['Max Strength', 'Time Under Tension', 'Control'],
    tips: [
      'Embrace the slow burn',
      'Maximum muscle engagement',
      'Quality over speed',
    ],
  },
  {
    id: 'ub-w4-d3',
    week: 4,
    order: 3,
    title: 'Endurance Elite',
    description: 'Elite-level endurance challenge - push your limits',
    exercises: [
      '100 Rep Challenge Style',
      'Continuous Push-ups',
      'Band Press Endurance',
      'Pyramid Push-ups',
      'Ladder Challenge',
      'Non-Stop Flow',
      'Max Rep Test',
      'Final Push',
    ],
    equipment: ['Resistance band'],
    focus: ['Elite Endurance', 'Mental Toughness', 'Stamina'],
    tips: [
      'This is the ultimate test',
      'Break through mental barriers',
      'You\'ve trained for this!',
    ],
  },
  {
    id: 'ub-w4-d4',
    week: 4,
    order: 4,
    title: 'Arm Mastery',
    description: 'Complete arm mastery with all techniques combined',
    exercises: [
      'Giant Set Curls',
      'Tricep Death Set',
      'Drop Set Simulation',
      'Rest-Pause Curls',
      'Burnout Extensions',
      '21s Method',
      'Max Tension Curls',
      'Final Arm Blast',
    ],
    equipment: ['Resistance band'],
    focus: ['Arm Mastery', 'Advanced Techniques', 'Complete Fatigue'],
    tips: [
      'Use every technique learned',
      'Push to true failure',
      'You\'ve earned this strength',
    ],
  },
  {
    id: 'ub-w4-d5',
    week: 4,
    order: 5,
    title: 'Upper Body Final Challenge',
    description: 'The ultimate upper body test - combine everything',
    exercises: [
      'Complex 1: Push-Pull-Push',
      'Complex 2: Row-Press-Row',
      'Complex 3: Curl-Extension-Curl',
      'Complex 4: Power Flow',
      'Complex 5: Endurance Burn',
      'Complex 6: Max Strength',
      'Complex 7: Speed & Power',
      'Victory Lap: Celebration Flow',
    ],
    equipment: ['Resistance band'],
    focus: ['Ultimate Challenge', 'Program Completion', 'Mastery'],
    tips: [
      'This is your victory lap',
      'Showcase your 4 weeks of progress',
      'Be proud of how far you\'ve come!',
    ],
  },
]

// ═══════════════════════════════════════════════════════════════════════════
// LOWER BODY PROGRAM
// ═══════════════════════════════════════════════════════════════════════════

const lowerBodyWorkouts: ProgramWorkoutInput[] = [
  // WEEK 1: Foundation
  {
    id: 'lb-w1-d1',
    week: 1,
    order: 1,
    title: 'Glute Activation',
    description: 'Wake up dormant glutes and establish hip stability',
    exercises: [
      'Glute Bridges',
      'Clamshells',
      'Donkey Kicks L',
      'Donkey Kicks R',
      'Fire Hydrants L',
      'Fire Hydrants R',
      'Glute Bridge Holds',
      'Banded Side Steps',
    ],
    equipment: ['Resistance band optional'],
    focus: ['Glutes', 'Hip Stability', 'Activation'],
    tips: [
      'Squeeze glutes at the top',
      'Focus on muscle contraction',
      'Quality over speed',
    ],
  },
  {
    id: 'lb-w1-d2',
    week: 1,
    order: 2,
    title: 'Squat Foundation',
    description: 'Master proper squat mechanics and knee tracking',
    exercises: [
      'Air Squats',
      'Wall Sits',
      'Box Squats',
      'Sit to Stand',
      'Goblet Squat Pattern',
      'Squat Holds',
      'Mini Squats',
      'Squat Mobility Flow',
    ],
    equipment: ['Chair or bench'],
    focus: ['Squat Pattern', 'Knee Health', 'Mobility'],
    tips: [
      'Knees track over toes',
      'Keep chest up',
      'Weight in heels',
    ],
  },
  {
    id: 'lb-w1-d3',
    week: 1,
    order: 3,
    title: 'Lunge Mechanics',
    description: 'Learn proper lunge form for knee-friendly movement',
    exercises: [
      'Reverse Lunges',
      'Static Lunges L',
      'Static Lunges R',
      'Side Lunges',
      'Curtsy Lunges',
      'Lunge Holds',
      'Step-ups Low',
      'Calf Raises',
    ],
    equipment: ['Step or low platform'],
    focus: ['Lunges', 'Single Leg', 'Knee Health'],
    tips: [
      'Step back to reduce knee stress',
      'Front knee stays over ankle',
      'Control the lowering',
    ],
  },
  {
    id: 'lb-w1-d4',
    week: 1,
    order: 4,
    title: 'Hip & Ankle Mobility',
    description: 'Improve mobility for better movement quality',
    exercises: [
      'Hip Circles L',
      'Hip Circles R',
      'Ankle Circles L',
      'Ankle Circles R',
      'Deep Squat Hold',
      'Cossack Squats Light',
      '90-90 Hip Switches',
      'World\'s Greatest Stretch',
    ],
    equipment: ['None'],
    focus: ['Mobility', 'Flexibility', 'Joint Health'],
    tips: [
      'Move through full range',
      'Gentle and controlled',
      'Focus on problem areas',
    ],
  },
  {
    id: 'lb-w1-d5',
    week: 1,
    order: 5,
    title: 'Leg Foundation Flow',
    description: 'Integrate all lower body movements with proper form',
    exercises: [
      'Bodyweight Squats',
      'Glute Bridges',
      'Reverse Lunges',
      'Calf Raises',
      'Lateral Steps',
      'Hip Hinge Practice',
      'Balance Work L',
      'Balance Work R',
    ],
    equipment: ['None'],
    focus: ['Integration', 'Balance', 'Coordination'],
    tips: [
      'Apply what you learned',
      'Focus on movement quality',
      'Celebrate your progress!',
    ],
  },

  // WEEK 2: Building
  {
    id: 'lb-w2-d1',
    week: 2,
    order: 1,
    title: 'Glute Builder',
    description: 'Strengthen glutes with progressive loading',
    exercises: [
      'Single Leg Glute Bridges L',
      'Single Leg Glute Bridges R',
      'Banded Hip Thrusts',
      'Banded Glute Bridges',
      'Fire Hydrant with Band',
      'Donkey Kicks with Band',
      'Glute Bridge March',
      'Side Plank Clamshells',
    ],
    equipment: ['Resistance band'],
    focus: ['Glutes', 'Hip Strength', 'Stability'],
    tips: [
      'Drive through the heel',
      'Squeeze at the top',
      'Keep hips level on single leg',
    ],
  },
  {
    id: 'lb-w2-d2',
    week: 2,
    order: 2,
    title: 'Squat Strength',
    description: 'Build squat strength with variations',
    exercises: [
      'Jump Squats',
      'Pause Squats',
      'Pulse Squats',
      'Sumo Squats',
      'Narrow Squats',
      'Squat Hold Challenge',
      'Prisoner Squats',
      'Frog Jumps',
    ],
    equipment: ['None'],
    focus: ['Squat Strength', 'Power', 'Endurance'],
    tips: [
      'Land softly on jumps',
      'Maintain form throughout',
      'Embrace the burn',
    ],
  },
  {
    id: 'lb-w2-d3',
    week: 2,
    order: 3,
    title: 'Lunge Power',
    description: 'Develop single-leg strength and stability',
    exercises: [
      'Walking Lunges',
      'Jumping Lunges',
      'Reverse to Forward Lunges',
      'Lateral Lunges Deep',
      'Curtsy Lunges with Hop',
      'Step-ups High',
      'Split Squats L',
      'Split Squats R',
    ],
    equipment: ['Higher step or bench'],
    focus: ['Lunge Power', 'Single Leg', 'Explosiveness'],
    tips: [
      'Stay controlled on jumps',
      'Full range on step-ups',
      'Keep front knee stable',
    ],
  },
  {
    id: 'lb-w2-d4',
    week: 2,
    order: 4,
    title: 'Calf & Ankle Strength',
    description: 'Build resilient calves and ankle stability',
    exercises: [
      'Double Leg Calf Raises',
      'Single Leg Calf Raises L',
      'Single Leg Calf Raises R',
      'Calf Raise Holds',
      'Eccentric Calf Lowers',
      'Jump Rope Simulation',
      'Tibialis Raises',
      'Ankle Stability Holds',
    ],
    equipment: ['Step edge optional'],
    focus: ['Calves', 'Ankles', 'Lower Leg'],
    tips: [
      'Full range of motion',
      'Pause at the top',
      'Control the lowering',
    ],
  },
  {
    id: 'lb-w2-d5',
    week: 2,
    order: 5,
    title: 'Leg Integration',
    description: 'Combine all lower body patterns',
    exercises: [
      'Squat to Lunge Combo',
      'Glute Bridge to March',
      'Lateral to Reverse Lunge',
      'Calf Raise Complex',
      'Single Leg Flow L',
      'Single Leg Flow R',
      'Plyo Base Moves',
      'Recovery Flow',
    ],
    equipment: ['Resistance band optional'],
    focus: ['Integration', 'Flow', 'Coordination'],
    tips: [
      'Smooth transitions',
      'Maintain form',
      'Breathe through the work',
    ],
  },

  // WEEK 3: Challenge
  {
    id: 'lb-w3-d1',
    week: 3,
    order: 1,
    title: 'Glute Challenge',
    description: 'Intensive glute-focused challenge workout',
    exercises: [
      'Hip Thrust Burnout',
      'Banded Glute Burnout',
      'Single Leg Hip Thrust L',
      'Single Leg Hip Thrust R',
      'Glute Bridge Walkouts',
      'Banded Lateral Walks',
      'Glute March Challenge',
      'Final Glute Squeeze',
    ],
    equipment: ['Resistance band'],
    focus: ['Glute Challenge', 'Burnout', 'Strength'],
    tips: [
      'Push through the burn',
      'Maximum glute contraction',
      'You\'re getting stronger!',
    ],
  },
  {
    id: 'lb-w3-d2',
    week: 3,
    order: 2,
    title: 'Plyo Legs',
    description: 'Explosive leg power with plyometric movements',
    exercises: [
      'Broad Jumps',
      'Box Jumps or Step-ups Fast',
      'Jump Squats Max Height',
      'Split Jump Lunges',
      'Tuck Jumps',
      'Lateral Bounds',
      'Depth Jumps Modified',
      'Plyo Finisher',
    ],
    equipment: ['Box or step'],
    focus: ['Plyometrics', 'Power', 'Explosiveness'],
    tips: [
      'Land soft and quiet',
      'Explode up with power',
      'Modify if joints hurt',
    ],
  },
  {
    id: 'lb-w3-d3',
    week: 3,
    order: 3,
    title: 'Lunge Intensity',
    description: 'High-intensity lunge variations',
    exercises: [
      'Jump Lunge Switch',
      'Lunge Complex L',
      'Lunge Complex R',
      'Walking Lunge Burnout',
      'Pulse Lunge Challenge',
      'Explosive Step-ups',
      'Lateral Lunge Jumps',
      'Lunge Ladder',
    ],
    equipment: ['Step or bench'],
    focus: ['Lunge Intensity', 'Endurance', 'Power'],
    tips: [
      'Maximum intensity',
      'Control on landings',
      'Push through fatigue',
    ],
  },
  {
    id: 'lb-w3-d4',
    week: 3,
    order: 4,
    title: 'Leg Endurance',
    description: 'Build leg endurance with continuous work',
    exercises: [
      '100 Rep Squat Challenge',
      'Continuous Lunges',
      'Squat Hold Endurance',
      'Wall Sit Challenge',
      'Calf Raise Marathon',
      'Balance Challenge L',
      'Balance Challenge R',
      'Final Burnout Set',
    ],
    equipment: ['Wall'],
    focus: ['Endurance', 'Mental Toughness', 'Stamina'],
    tips: [
      'Embrace the challenge',
      'Break mental barriers',
      'You can do this!',
    ],
  },
  {
    id: 'lb-w3-d5',
    week: 3,
    order: 5,
    title: 'Total Leg Challenge',
    description: 'Complete lower body challenge',
    exercises: [
      'Leg Complex 1',
      'Leg Complex 2',
      'Leg Complex 3',
      'Leg Complex 4',
      'Leg Complex 5',
      'Leg Complex 6',
      'Leg Complex 7',
      'Leg Complex 8',
    ],
    equipment: ['Resistance band', 'Step'],
    focus: ['Total Legs', 'Challenge', 'Integration'],
    tips: [
      'Maximum effort',
      'Form over speed',
      'You\'re in beast mode!',
    ],
  },

  // WEEK 4: Peak Performance
  {
    id: 'lb-w4-d1',
    week: 4,
    order: 1,
    title: 'Peak Glute Power',
    description: 'Maximum glute strength and power',
    exercises: [
      'Max Band Hip Thrusts',
      'Explosive Glute Bridges',
      'Single Leg Power L',
      'Single Leg Power R',
      'Glute Bridge Burnout',
      'Banded Walk Challenge',
      'Power Glute Squeeze',
      'Final Glute Push',
    ],
    equipment: ['Resistance band'],
    focus: ['Peak Power', 'Max Strength', 'Glutes'],
    tips: [
      'Give it everything',
      'Maximum contraction',
      'You\'ve built this strength!',
    ],
  },
  {
    id: 'lb-w4-d2',
    week: 4,
    order: 2,
    title: 'Ultimate Squat Challenge',
    description: 'The ultimate squat test',
    exercises: [
      'Max Rep Squats',
      'Explosive Squat Challenge',
      'Pause Squat Holds',
      'Jump Squat Max',
      'Squat Ladder',
      'Single Leg Squat Prep L',
      'Single Leg Squat Prep R',
      'Squat Victory Set',
    ],
    equipment: ['None'],
    focus: ['Ultimate Squat', 'Peak Performance', 'Mastery'],
    tips: [
      'Showcase your strength',
      'Perfect form throughout',
      'You\'re a squat master!',
    ],
  },
  {
    id: 'lb-w4-d3',
    week: 4,
    order: 3,
    title: 'Lunge Mastery',
    description: 'Complete lunge mastery challenge',
    exercises: [
      'Lunge Mastery L',
      'Lunge Mastery R',
      'Jump Lunge Challenge',
      'Complex Lunge Flow',
      'Endurance Lunge Test',
      'Power Lunge Sets',
      'Balance Lunge Challenge',
      'Victory Lunges',
    ],
    equipment: ['Step optional'],
    focus: ['Lunge Mastery', 'Complete Challenge', 'Perfection'],
    tips: [
      'Nail every rep',
      'Maximum control',
      'You\'ve mastered lunges!',
    ],
  },
    {
    id: 'lb-w4-d4',
    week: 4,
    order: 4,
    title: 'Leg Power Peak',
    description: 'Maximum leg power and explosiveness',
    exercises: [
      'Max Height Jumps',
      'Broad Jump Challenge',
      'Explosive Combo 1',
      'Explosive Combo 2',
      'Speed Squats',
      'Power Lunges',
      'Jump Challenge',
      'Power Finish',
    ],
    equipment: ['Box or step'],
    focus: ['Peak Power', 'Explosiveness', 'Athleticism'],
    tips: [
      'Maximum height on jumps',
      'Explode with power',
      'Show your athleticism!',
    ],
  },
  {
    id: 'lb-w4-d5',
    week: 4,
    order: 5,
    title: 'Lower Body Final Challenge',
    description: 'The ultimate lower body test and celebration',
    exercises: [
      'Victory Complex 1',
      'Victory Complex 2',
      'Victory Complex 3',
      'Victory Complex 4',
      'Victory Complex 5',
      'Victory Complex 6',
      'Victory Complex 7',
      'Victory Lap Celebration',
    ],
    equipment: ['Resistance band', 'Step'],
    focus: ['Ultimate Challenge', 'Program Complete', 'Celebration'],
    tips: [
      'This is YOUR moment',
      'Showcase 4 weeks of gains',
      'Be incredibly proud!',
    ],
  },
]

// ═══════════════════════════════════════════════════════════════════════════
// FULL BODY PROGRAM
// ═══════════════════════════════════════════════════════════════════════════

const fullBodyWorkouts: ProgramWorkoutInput[] = [
  // WEEK 1: Foundation
  {
    id: 'fb-w1-d1',
    week: 1,
    order: 1,
    title: 'Movement Basics',
    description: 'Learn fundamental movement patterns with proper form',
    exercises: [
      'Air Squats',
      'Incline Push-ups',
      'Glute Bridges',
      'Plank Hold',
      'Reverse Lunges',
      'Arm Circles',
      'High Knees March',
      'Cat-Cow Stretch',
    ],
    equipment: ['Wall or elevated surface'],
    focus: ['Movement Patterns', 'Form', 'Foundation'],
    tips: [
      'Focus on quality movement',
      'Learn each pattern well',
      'This is your foundation',
    ],
  },
  {
    id: 'fb-w1-d2',
    week: 1,
    order: 2,
    title: 'Push & Pull Basics',
    description: 'Master pushing and pulling fundamentals',
    exercises: [
      'Wall Push-ups',
      'Doorway Rows',
      'Knee Push-ups',
      'Superman Holds',
      'Incline Push-ups',
      'Band Pulls',
      'Push-up Plank',
      'Prone Cobra',
    ],
    equipment: ['Wall', 'Resistance band optional'],
    focus: ['Push', 'Pull', 'Upper Foundation'],
    tips: [
      'Feel the right muscles working',
      'Control both directions',
      'Build the mind-muscle connection',
    ],
  },
  {
    id: 'fb-w1-d3',
    week: 1,
    order: 3,
    title: 'Hinge & Squat',
    description: 'Learn hip hinge and squat patterns safely',
    exercises: [
      'Bodyweight Squats',
      'Good Mornings',
      'Glute Bridges',
      'Wall Sit',
      'Hip Hinge Practice',
      'Box Squats',
      'Bird Dog',
      'Dead Bug',
    ],
    equipment: ['Wall', 'Chair'],
    focus: ['Hinge', 'Squat', 'Posterior Chain'],
    tips: [
      'Feel your hips hinge',
      'Keep back neutral',
      'Knees track properly',
    ],
  },
  {
    id: 'fb-w1-d4',
    week: 1,
    order: 4,
    title: 'Core & Stability',
    description: 'Build core stability for all movements',
    exercises: [
      'Forearm Plank',
      'Side Plank L',
      'Side Plank R',
      'Glute Bridge March',
      'Dead Bug Slow',
      'Bird Dog Holds',
      'Plank Shoulder Taps',
      'Hollow Body Hold',
    ],
    equipment: ['None'],
    focus: ['Core', 'Stability', 'Control'],
    tips: [
      'Keep core engaged throughout',
      'No sagging or arching',
      'Breathe steadily',
    ],
  },
  {
    id: 'fb-w1-d5',
    week: 1,
    order: 5,
    title: 'Full Body Integration',
    description: 'Combine all movement patterns together',
    exercises: [
      'Squat to Push-up Flow',
      'Lunge to Rotation',
      'Plank Walkout',
      'Glute Bridge to Reach',
      'Inchworm',
      'Bear Crawl Hold',
      'Sun Salutation',
      'Recovery Flow',
    ],
    equipment: ['None'],
    focus: ['Integration', 'Flow', 'Coordination'],
    tips: [
      'Smooth transitions',
      'Apply what you learned',
      'You\'re building great habits!',
    ],
  },

  // WEEK 2: Building
  {
    id: 'fb-w2-d1',
    week: 2,
    order: 1,
    title: 'Dynamic Full Body',
    description: 'Add dynamic movement to your foundation',
    exercises: [
      'Jump Squats',
      'Push-up to T-Rotation',
      'Reverse Lunges with Twist',
      'Plank Jacks',
      'Glute Bridge Walkouts',
      'Mountain Climbers Slow',
      'Lateral Lunges',
      'Thread the Needle',
    ],
    equipment: ['None'],
    focus: ['Dynamic Movement', 'Coordination', 'Flow'],
    tips: [
      'Control the dynamic moves',
      'Land softly on jumps',
      'Rotate from the mid-back',
    ],
  },
  {
    id: 'fb-w2-d2',
    week: 2,
    order: 2,
    title: 'Strength Builder',
    description: 'Build strength with compound movements',
    exercises: [
      'Push-ups',
      'Air Squats Tempo',
      'Renegade Rows',
      'Reverse Lunges',
      'Plank to Push-up',
      'Glute Bridges Single Leg',
      'Tricep Dips',
      'Calf Raises',
    ],
    equipment: ['None'],
    focus: ['Strength', 'Compound Moves', 'Power'],
    tips: [
      'Full range of motion',
      'Control the tempo',
      'You\'re getting stronger!',
    ],
  },
  {
    id: 'fb-w2-d3',
    week: 2,
    order: 3,
    title: 'Cardio & Core',
    description: 'Elevate heart rate while building core strength',
    exercises: [
      'High Knees',
      'Plank Hold',
      'Jumping Jacks',
      'Side Plank L',
      'Butt Kicks',
      'Side Plank R',
      'Speed Skaters',
      'Dead Bug',
    ],
    equipment: ['None'],
    focus: ['Cardio', 'Core', 'Endurance'],
    tips: [
      'Keep core tight during cardio',
      'Find your rhythm',
      'Push the pace safely',
    ],
  },
  {
    id: 'fb-w2-d4',
    week: 2,
    order: 4,
    title: 'Power & Explosiveness',
    description: 'Develop power with explosive bodyweight movements',
    exercises: [
      'Broad Jumps',
      'Explosive Push-ups',
      'Jump Lunges',
      'Plyo Squats',
      'Tuck Jumps',
      'Push-up Burpees',
      'Lateral Bounds',
      'High Knee Sprint',
    ],
    equipment: ['None'],
    focus: ['Power', 'Explosiveness', 'Athleticism'],
    tips: [
      'Maximum explosive effort',
      'Land soft and controlled',
      'Modify if joints hurt',
    ],
  },
  {
    id: 'fb-w2-d5',
    week: 2,
    order: 5,
    title: 'Full Body Flow',
    description: 'Smooth flowing full body movements',
    exercises: [
      'Squat to Stand to Reach',
      'Plank to Down Dog',
      'Lunge Flow Complex',
      'Push-up Walkout',
      'Glute Bridge Complex',
      'Bear Crawl',
      'Inchworm Push-up',
      'Flow Finisher',
    ],
    equipment: ['None'],
    focus: ['Flow', 'Mobility', 'Integration'],
    tips: [
      'One smooth motion to next',
      'Connect your breath',
      'Enjoy the movement',
    ],
  },

  // WEEK 3: Challenge
  {
    id: 'fb-w3-d1',
    week: 3,
    order: 1,
    title: 'Challenge Complex 1',
    description: 'High-intensity complex combining strength and cardio',
    exercises: [
      'Burpees',
      'Jump Squats',
      'Push-ups',
      'Mountain Climbers',
      'Reverse Lunges',
      'High Knees Sprint',
      'Plank Hold',
      'Recovery Breathing',
    ],
    equipment: ['None'],
    focus: ['Complex Training', 'High Intensity', 'Challenge'],
    tips: [
      'This is challenging - pace yourself',
      'Maintain form as you fatigue',
      'Push through mentally!',
    ],
  },
  {
    id: 'fb-w3-d2',
    week: 3,
    order: 2,
    title: 'Challenge Complex 2',
    description: 'Second high-intensity challenge workout',
    exercises: [
      'Jump Lunges',
      'Push-up T-Rotation',
      'Tuck Jumps',
      'Renegade Rows',
      'Broad Jumps',
      'Plank Jacks',
      'Speed Skaters',
      'Glute Bridge Hold',
    ],
    equipment: ['None'],
    focus: ['Complex Training', 'Explosive Power', 'Endurance'],
    tips: [
      'Explosive and powerful',
      'Maximum effort each rep',
      'You\'re building serious fitness!',
    ],
  },
  {
    id: 'fb-w3-d3',
    week: 3,
    order: 3,
    title: 'Core Intensive',
    description: 'Intense core-focused full body workout',
    exercises: [
      'Plank Hold Challenge',
      'Bicycle Crunches',
      'Side Plank Rotations L',
      'Side Plank Rotations R',
      'V-ups',
      'Plank to Push-up Fast',
      'Russian Twists',
      'Hollow Body Rocks',
    ],
    equipment: ['None'],
    focus: ['Core Intensity', 'Abs', 'Stability'],
    tips: [
      'Feel the core burn',
      'Keep movements controlled',
      'This builds serious core strength',
    ],
  },
  {
    id: 'fb-w3-d4',
    week: 3,
    order: 4,
    title: 'Endurance Challenge',
    description: 'Test your endurance with continuous work',
    exercises: [
      'Continuous Squats',
      'Push-up Challenge Set',
      'Lunge Walk',
      'Plank Challenge Hold',
      'High Knees Endurance',
      'Glute Bridge Burnout',
      'Mountain Climber Endurance',
      'Final Push Set',
    ],
    equipment: ['None'],
    focus: ['Endurance', 'Mental Toughness', 'Stamina'],
    tips: [
      'Embrace the challenge',
      'Break mental barriers',
      'You\'re an endurance machine!',
    ],
  },
  {
    id: 'fb-w3-d5',
    week: 3,
    order: 5,
    title: 'Full Body Power Hour',
    description: 'Maximum intensity full body challenge',
    exercises: [
      'Burpee Variations',
      'Jump Squat Variations',
      'Push-up Variations',
      'Lunge Variations',
      'Plank Variations',
      'Plyo Combinations',
      'Power Combinations',
      'Max Effort Finisher',
    ],
    equipment: ['None'],
    focus: ['Maximum Intensity', 'Full Body Power', 'Challenge'],
    tips: [
      'Maximum effort everything',
      'Show your strength',
      'Beast mode activated!',
    ],
  },

  // WEEK 4: Peak Performance
  {
    id: 'fb-w4-d1',
    week: 4,
    order: 1,
    title: 'Peak Complex 1',
    description: 'Peak performance full body complex',
    exercises: [
      'Explosive Burpees',
      'Power Squats',
      'Max Push-ups',
      'Speed Mountain Climbers',
      'Jump Lunges Power',
      'Sprint High Knees',
      'Plank Power Hold',
      'Recovery Set',
    ],
    equipment: ['None'],
    focus: ['Peak Performance', 'Max Power', 'Elite Level'],
    tips: [
      'This is peak week!',
      'Maximum intensity always',
      'You\'ve earned this strength!',
    ],
  },
  {
    id: 'fb-w4-d2',
    week: 4,
    order: 2,
    title: 'Peak Complex 2',
    description: 'Second peak performance challenge',
    exercises: [
      'Max Height Tuck Jumps',
      'Explosive Push-ups',
      'Power Lunges',
      'Broad Jumps Max',
      'Plyo Push-ups',
      'Lateral Bounds Power',
      'Burpee Tuck Jumps',
      'Power Finish',
    ],
    equipment: ['None'],
    focus: ['Peak Power', 'Explosiveness', 'Athletic Peak'],
    tips: [
      'Maximum height and power',
      'Show your explosiveness',
      'You\'re an athlete!',
    ],
  },
  {
    id: 'fb-w4-d3',
    week: 4,
    order: 3,
    title: 'Peak Core Challenge',
    description: 'Ultimate core strength challenge',
    exercises: [
      'Extended Plank Hold',
      'V-up Challenge',
      'Plank Complex L',
      'Plank Complex R',
      'Bicycle Crunch Challenge',
      'Hollow Body Challenge',
      'Russian Twist Challenge',
      'Core Victory Set',
    ],
    equipment: ['None'],
    focus: ['Peak Core', 'Ultimate Challenge', 'Mastery'],
    tips: [
      'This is your core mastery test',
      'Show your stability',
      'You have a steel core!',
    ],
  },
  {
    id: 'fb-w4-d4',
    week: 4,
    order: 4,
    title: 'Peak Endurance',
    description: 'Ultimate endurance and stamina test',
    exercises: [
      'Endurance Squat Challenge',
      'Endurance Push Challenge',
      'Endurance Lunge Challenge',
      'Endurance Plank Challenge',
      'Endurance Cardio Challenge',
      'Endurance Core Challenge',
      'Endurance Flow Challenge',
      'Victory Endurance Set',
    ],
    equipment: ['None'],
    focus: ['Peak Endurance', 'Stamina Test', 'Mental Victory'],
    tips: [
      'This is the ultimate test',
      'Push beyond limits',
      'You\'re unstoppable!',
    ],
  },
  {
    id: 'fb-w4-d5',
    week: 4,
    order: 5,
    title: 'Full Body Final Challenge',
    description: 'The ultimate celebration of your 4-week journey',
    exercises: [
      'Victory Complex 1: Foundation',
      'Victory Complex 2: Strength',
      'Victory Complex 3: Power',
      'Victory Complex 4: Endurance',
      'Victory Complex 5: Flow',
      'Victory Complex 6: Integration',
      'Victory Complex 7: Mastery',
      'Victory Lap: Celebration',
    ],
    equipment: ['None'],
    focus: ['Ultimate Challenge', 'Journey Complete', 'Celebration'],
    tips: [
      'CELEBRATE YOUR JOURNEY!',
      'Showcase everything you learned',
      'You transformed in 4 weeks!',
    ],
  },
]

// ═══════════════════════════════════════════════════════════════════════════
// ASSESSMENT WORKOUT
// ═══════════════════════════════════════════════════════════════════════════

export const ASSESSMENT_WORKOUT: Assessment = {
  id: 'initial-assessment',
  title: 'Movement Assessment',
  description: 'A quick 4-minute check to understand your current movement patterns and recommend the best starting point.',
  duration: 4,
  exercises: [
    {
      name: 'Squat Test',
      duration: 20,
      purpose: 'Check squat depth and form',
    },
    {
      name: 'Push-up Test',
      duration: 20,
      purpose: 'Assess upper body strength',
    },
    {
      name: 'Plank Test',
      duration: 20,
      purpose: 'Check core stability',
    },
    {
      name: 'Single Leg Balance L',
      duration: 20,
      purpose: 'Test balance and hip stability',
    },
    {
      name: 'Single Leg Balance R',
      duration: 20,
      purpose: 'Test balance and hip stability',
    },
    {
      name: 'Hip Hinge Test',
      duration: 20,
      purpose: 'Check posterior chain mobility',
    },
    {
      name: 'Overhead Reach',
      duration: 20,
      purpose: 'Assess shoulder mobility',
    },
    {
      name: 'Lunge Test',
      duration: 20,
      purpose: 'Check single leg strength',
    },
  ],
  tips: [
    'Move at your own pace',
    'Focus on form, not speed',
    'This helps us recommend the best program',
    'No judgment - just a starting point!',
  ],
}

// ═══════════════════════════════════════════════════════════════════════════
// PROGRAM BUILDER
// ═══════════════════════════════════════════════════════════════════════════

function buildProgramWorkouts(inputs: ProgramWorkoutInput[], category: WorkoutCategory): any[] {
  return inputs.map((input) => ({
    ...input,
    exercises: input.exercises.map((name) =>
      createExercise(name)
    ),
    duration: 4 as const,
    // Workout-compatible fields so screens don't crash
    level: getLevelFromWeek(input.week),
    category,
    trainerId: '',
    calories: 50,
    rounds: input.exercises.length,
    prepTime: 10,
    workTime: 20,
    restTime: 10,
    musicVibe: 'electronic' as MusicVibe,
    isFeatured: false,
  }))
}

function buildWeeks(workouts: any[]): Week[] {
  const weeks: Week[] = []
  
  for (let weekNum = 1; weekNum <= 4; weekNum++) {
    const weekWorkouts = workouts.filter((w) => w.week === weekNum)
    
    weeks.push({
      weekNumber: weekNum as WeekNumber,
      title: getWeekTitle(weekNum),
      description: getWeekDescription(weekNum),
      focus: getWeekFocus(weekNum),
      workouts: weekWorkouts.sort((a, b) => a.order - b.order),
    })
  }
  
  return weeks
}

function getWeekTitle(week: number): string {
  switch (week) {
    case 1:
      return 'Foundation'
    case 2:
      return 'Building'
    case 3:
      return 'Challenge'
    case 4:
      return 'Peak Performance'
    default:
      return `Week ${week}`
  }
}

function getWeekDescription(week: number): string {
  switch (week) {
    case 1:
      return 'Master the fundamentals with perfect form'
    case 2:
      return 'Build strength and increase intensity'
    case 3:
      return 'Push your limits with challenging workouts'
    case 4:
      return 'Achieve peak performance and celebrate your progress'
    default:
      return `Week ${week} of your journey`
  }
}

function getWeekFocus(week: number): string {
  switch (week) {
    case 1:
      return 'Form & Foundation'
    case 2:
      return 'Strength Building'
    case 3:
      return 'Intensity & Challenge'
    case 4:
      return 'Peak Performance'
    default:
      return 'General Fitness'
  }
}

// ═══════════════════════════════════════════════════════════════════════════
// EXPORT PROGRAMS
// ═══════════════════════════════════════════════════════════════════════════

export const PROGRAMS: Record<ProgramId, Program> = {
  'upper-body': {
    id: 'upper-body',
    title: 'Upper Body',
    description: 'Build strong shoulders, chest, back, and arms with physiotherapist-designed progressions',
    durationWeeks: 4,
    workoutsPerWeek: 5,
    totalWorkouts: 20,
    equipment: {
      required: ['Resistance band'],
      optional: ['Wall', 'Elevated surface'],
    },
    focusAreas: ['Shoulders', 'Chest', 'Back', 'Arms', 'Posture'],
    weeks: buildWeeks(buildProgramWorkouts(upperBodyWorkouts, 'upper-body')),
  },
  'lower-body': {
    id: 'lower-body',
    title: 'Lower Body',
    description: 'Develop powerful legs, glutes, and hips with joint-friendly movements',
    durationWeeks: 4,
    workoutsPerWeek: 5,
    totalWorkouts: 20,
    equipment: {
      required: ['Resistance band'],
      optional: ['Step or bench', 'Wall'],
    },
    focusAreas: ['Legs', 'Glutes', 'Hips', 'Calves', 'Knee Health'],
    weeks: buildWeeks(buildProgramWorkouts(lowerBodyWorkouts, 'lower-body')),
  },
  'full-body': {
    id: 'full-body',
    title: 'Full Body',
    description: 'Complete total body transformation using only your bodyweight',
    durationWeeks: 4,
    workoutsPerWeek: 5,
    totalWorkouts: 20,
    equipment: {
      required: [],
      optional: ['Wall', 'Elevated surface'],
    },
    focusAreas: ['Total Body', 'Core', 'Cardio', 'Functional Fitness'],
    weeks: buildWeeks(buildProgramWorkouts(fullBodyWorkouts, 'full-body')),
  },
}

// Export individual arrays for convenience
export const UPPER_BODY_WORKOUTS = buildProgramWorkouts(upperBodyWorkouts, 'upper-body')
export const LOWER_BODY_WORKOUTS = buildProgramWorkouts(lowerBodyWorkouts, 'lower-body')
export const FULL_BODY_WORKOUTS = buildProgramWorkouts(fullBodyWorkouts, 'full-body')

// Export all workouts as flat array for player compatibility
export const ALL_PROGRAM_WORKOUTS = [
  ...UPPER_BODY_WORKOUTS,
  ...LOWER_BODY_WORKOUTS,
  ...FULL_BODY_WORKOUTS,
]

export { upperBodyWorkouts, lowerBodyWorkouts, fullBodyWorkouts }
