@extends('admin.layouts.app')

@section('title', 'جزئیات مربی')

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

    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">

        <div class="md:col-span-1 bg-white rounded-xl shadow-sm p-6 text-center">
            @if($coach->photo_path)
                <img src="{{ Storage::disk('public')->url($coach->photo_path) }}" class="w-24 h-24 rounded-full object-cover mx-auto mb-3">
            @else
                <div class="w-24 h-24 rounded-full bg-gray-200 mx-auto mb-3"></div>
            @endif
            <h1 class="font-bold">{{ $coach->user->fullName() }}</h1>
            <p class="text-gray-400 text-sm" dir="ltr">{{ $coach->user->mobile }}</p>
            <p class="mt-2 text-sm">
                وضعیت فعلی: <span class="font-medium">{{ $coach->status->label() }}</span>
            </p>
            @if($coach->status_reason)
                <p class="text-xs text-red-500 mt-1">دلیل: {{ $coach->status_reason }}</p>
            @endif

            <div class="mt-4 space-y-2">
                @if(in_array($coach->status->value, ['pending', 'rejected']))
                    <form method="POST" action="{{ route('admin.coaches.approve', $coach) }}">
                        @csrf
                        <button class="w-full bg-green-600 text-white text-sm px-4 py-2 rounded-lg">تأیید مربی</button>
                    </form>
                @endif

                @if($coach->status->value !== 'rejected')
                    <button type="button" onclick="document.getElementById('reject-form').classList.toggle('hidden')"
                            class="w-full bg-red-50 text-red-600 text-sm px-4 py-2 rounded-lg">رد درخواست</button>
                    <form id="reject-form" method="POST" action="{{ route('admin.coaches.reject', $coach) }}" class="hidden text-right">
                        @csrf
                        <textarea name="reason" rows="2" placeholder="دلیل رد..." class="w-full border rounded-lg px-3 py-2 text-sm mt-2" required></textarea>
                        @error('reason') <p class="text-red-600 text-xs mt-1">{{ $message }}</p> @enderror
                        <button class="w-full bg-red-600 text-white text-sm px-4 py-2 rounded-lg mt-2">ثبت رد درخواست</button>
                    </form>
                @endif

                @if($coach->status->value === 'approved')
                    <form method="POST" action="{{ route('admin.coaches.disable', $coach) }}">
                        @csrf
                        <button class="w-full bg-gray-100 text-gray-700 text-sm px-4 py-2 rounded-lg">غیرفعال‌سازی</button>
                    </form>
                @endif

                @if($coach->status->value === 'disabled')
                    <form method="POST" action="{{ route('admin.coaches.enable', $coach) }}">
                        @csrf
                        <button class="w-full bg-green-50 text-green-700 text-sm px-4 py-2 rounded-lg">فعال‌سازی مجدد</button>
                    </form>
                @endif
            </div>
        </div>

        <div class="md:col-span-2 space-y-6">
            <div class="bg-white rounded-xl shadow-sm p-6">
                <h2 class="font-semibold mb-2">رزومه</h2>
                <p class="text-sm text-gray-600 whitespace-pre-line">{{ $coach->bio ?: '—' }}</p>

                <h2 class="font-semibold mt-4 mb-2">سابقه کاری</h2>
                <p class="text-sm text-gray-600 whitespace-pre-line">{{ $coach->work_history ?: '—' }}</p>

                <div class="mt-4 flex flex-wrap gap-2">
                    @forelse($coach->goals as $goal)
                        <span class="text-xs bg-gray-100 px-2 py-1 rounded-full">{{ $goal->title }}</span>
                    @empty
                        <span class="text-xs text-gray-400">تخصصی ثبت نشده</span>
                    @endforelse
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-sm p-6">
                <h2 class="font-semibold mb-3">مدارک ({{ $coach->documents->count() }})</h2>
                <ul class="divide-y text-sm">
                    @forelse($coach->documents as $doc)
                        <li class="py-2 flex items-center justify-between">
                            <span>{{ $doc->type->label() }} — {{ $doc->original_name }} ({{ $doc->humanSize() }})</span>
                            <a href="{{ route('coach.documents.show', $doc) }}" class="text-blue-600 hover:underline">مشاهده/دانلود</a>
                        </li>
                    @empty
                        <li class="py-2 text-gray-400">مدرکی ثبت نشده است.</li>
                    @endforelse
                </ul>
            </div>
        </div>
    </div>
@endsection
