@extends('athlete.layouts.app')

@section('title', $plan->name)

@section('content')
    <a href="{{ route('athlete.workout-plans.index') }}" class="text-sm text-blue-600 hover:underline mb-4 inline-block">← بازگشت</a>

    <h1 class="text-xl font-bold mb-1">{{ $plan->name }}</h1>
    <p class="text-sm text-gray-500 mb-6">
        مربی: {{ $plan->coach->user->fullName() }}
        @if($plan->goal) · هدف: {{ $plan->goal->title }} @endif
        @if($plan->duration_weeks) · {{ $plan->duration_weeks }} هفته @endif
    </p>

    @if($plan->description)
        <p class="text-sm text-gray-600 bg-white rounded-xl shadow-sm p-4 mb-6">{{ $plan->description }}</p>
    @endif

    <div class="space-y-6">
        @foreach($plan->sessions as $session)
            <div class="bg-white rounded-xl shadow-sm p-4">
                <h2 class="font-semibold mb-3">{{ $session->title }}</h2>

                <div class="space-y-2">
                    @foreach($session->exercises as $ex)
                        <div class="border rounded-lg p-3 flex items-center gap-3">
                            @if($ex->exercise->gif_path)
                                <img src="{{ Storage::disk('public')->url($ex->exercise->gif_path) }}" class="w-14 h-14 rounded object-cover shrink-0">
                            @else
                                <div class="w-14 h-14 rounded bg-gray-100 shrink-0"></div>
                            @endif
                            <div class="flex-1">
                                <div class="font-medium text-sm">{{ $ex->exercise->name }}</div>
                                <div class="text-xs text-gray-400">{{ $ex->exercise->mainMuscle?->name }}</div>
                                <div class="text-xs text-gray-500 mt-1 flex flex-wrap gap-x-3">
                                    <span>ست: {{ $ex->sets ?? '—' }}</span>
                                    <span>تکرار: {{ $ex->reps ?? '—' }}</span>
                                    <span>وزن: {{ $ex->weight_kg ?? '—' }}</span>
                                    <span>استراحت: {{ $ex->rest_seconds ?? '—' }}ث</span>
                                    @if($ex->tempo)<span>Tempo: {{ $ex->tempo }}</span>@endif
                                </div>
                                @if($ex->coach_notes)
                                    <p class="text-xs text-gray-500 mt-1">توضیح مربی: {{ $ex->coach_notes }}</p>
                                @endif
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        @endforeach
    </div>
@endsection
