@extends('coach.layouts.app')

@section('title', 'ارزیابی ورزشکار')

@section('content')
    <a href="{{ route('coach.athletes.index') }}" class="text-sm text-blue-600 hover:underline mb-4 inline-block">← بازگشت به ورزشکاران من</a>

    <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
        <h1 class="text-lg font-bold mb-1">
            {{ $assessment->athlete->user->fullName() }} —
            {{ $assessment->is_initial ? 'ارزیابی اولیه' : 'ارزیابی' }}
            ({{ verta($assessment->assessment_date)->format('Y/m/d') }})
        </h1>

        <div class="grid grid-cols-2 md:grid-cols-4 gap-3 mt-4">
            <div class="bg-gray-50 rounded-lg p-3 text-center">
                <div class="font-bold">{{ $assessment->weight_kg }}</div>
                <div class="text-xs text-gray-400">وزن (kg)</div>
            </div>
            <div class="bg-gray-50 rounded-lg p-3 text-center">
                <div class="font-bold">{{ $assessment->bmi }}</div>
                <div class="text-xs text-gray-400">BMI</div>
            </div>
            <div class="bg-gray-50 rounded-lg p-3 text-center">
                <div class="font-bold">{{ $assessment->body_fat_percentage ?? '—' }}</div>
                <div class="text-xs text-gray-400">درصد چربی</div>
            </div>
            <div class="bg-gray-50 rounded-lg p-3 text-center">
                <div class="font-bold">{{ $assessment->goal?->title ?? '—' }}</div>
                <div class="text-xs text-gray-400">هدف</div>
            </div>
        </div>

        <form method="POST" action="{{ route('coach.assessments.body-fat', $assessment) }}" class="flex items-center gap-2 mt-4">
            @csrf
            @method('PUT')
            <input type="number" step="0.1" name="body_fat_percentage" value="{{ $assessment->body_fat_percentage }}"
                   placeholder="درصد چربی بدن" class="border rounded-lg px-3 py-2 text-sm w-40">
            <button class="bg-gray-900 text-white text-sm px-4 py-2 rounded-lg">ثبت درصد چربی</button>
        </form>
        @error('body_fat_percentage') <p class="text-red-600 text-xs mt-1">{{ $message }}</p> @enderror
    </div>

    @if($assessment->measurements)
        <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
            <h2 class="font-semibold mb-3">اندازه‌گیری‌ها</h2>
            <div class="grid grid-cols-2 md:grid-cols-4 gap-3 text-sm">
                <div>دور کمر: {{ $assessment->measurements->waist_cm ?? '—' }}</div>
                <div>دور بازو: {{ $assessment->measurements->arm_cm ?? '—' }}</div>
                <div>دور ران: {{ $assessment->measurements->thigh_cm ?? '—' }}</div>
                <div>دور سینه: {{ $assessment->measurements->chest_cm ?? '—' }}</div>
            </div>
        </div>
    @endif

    @if($assessment->medical)
        <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
            <h2 class="font-semibold mb-3">🔒 اطلاعات پزشکی</h2>
            <p class="text-sm text-gray-600">مشکلات جسمی: {{ $assessment->medical->physical_problems ?? '—' }}</p>
            <p class="text-sm text-gray-600">داروهای مصرفی: {{ $assessment->medical->current_medications ?? '—' }}</p>
        </div>
    @endif

    <div class="bg-white rounded-xl shadow-sm p-6">
        <h2 class="font-semibold mb-3">تصاویر ارزیابی</h2>
        <div class="grid grid-cols-2 md:grid-cols-3 gap-3">
            @forelse($assessment->photos as $photo)
                <a href="{{ route('photos.show', $photo) }}" target="_blank" class="block border rounded-lg p-2 text-center text-xs hover:shadow-md">
                    <div class="bg-gray-100 rounded h-24 flex items-center justify-center mb-1">📷</div>
                    {{ $photo->angle->label() }}
                </a>
            @empty
                <p class="text-gray-400 text-sm col-span-full">تصویری ثبت نشده است.</p>
            @endforelse
        </div>
    </div>
@endsection
