@extends('coach.layouts.app')

@section('title', 'تکمیل پروفایل')

@section('content')
    <h1 class="text-xl font-bold mb-6">پروفایل مربی</h1>

    {{-- عکس پروفایل --}}
    <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
        <h2 class="font-semibold mb-3">عکس پروفایل</h2>
        <div class="flex items-center gap-4">
            @if($coach->photo_path)
                <img src="{{ Storage::disk('public')->url($coach->photo_path) }}" class="w-20 h-20 rounded-full object-cover">
            @else
                <div class="w-20 h-20 rounded-full bg-gray-200 flex items-center justify-center text-gray-400">؟</div>
            @endif
            <form method="POST" action="{{ route('coach.profile.photo') }}" enctype="multipart/form-data" class="flex items-center gap-2">
                @csrf
                <input type="file" name="photo" accept="image/*" required class="text-sm">
                <button class="bg-gray-900 text-white text-sm px-4 py-2 rounded-lg">آپلود</button>
            </form>
        </div>
        @error('photo') <p class="text-red-600 text-xs mt-2">{{ $message }}</p> @enderror
    </div>

    {{-- اطلاعات پروفایل --}}
    <form method="POST" action="{{ route('coach.profile.update') }}" class="bg-white rounded-xl shadow-sm p-6 mb-6 space-y-4">
        @csrf
        @method('PUT')

        <div>
            <label class="block text-sm mb-1">رزومه / معرفی کوتاه</label>
            <textarea name="bio" rows="4" class="w-full border rounded-lg px-3 py-2">{{ old('bio', $coach->bio) }}</textarea>
        </div>

        <div>
            <label class="block text-sm mb-1">سابقه کاری</label>
            <textarea name="work_history" rows="4" class="w-full border rounded-lg px-3 py-2">{{ old('work_history', $coach->work_history) }}</textarea>
        </div>

        <div class="grid grid-cols-2 gap-4">
            <div>
                <label class="block text-sm mb-1">سابقه (سال)</label>
                <input type="number" name="experience_years" value="{{ old('experience_years', $coach->experience_years) }}"
                       class="w-full border rounded-lg px-3 py-2">
            </div>
            <div>
                <label class="block text-sm mb-1">قیمت پایه برنامه (تومان)</label>
                <input type="number" name="program_price" value="{{ old('program_price', $coach->program_price) }}"
                       class="w-full border rounded-lg px-3 py-2">
            </div>
        </div>

        <div>
            <label class="block text-sm mb-2">تخصص‌ها</label>
            <div class="flex flex-wrap gap-2">
                @foreach($goals as $goal)
                    <label class="flex items-center gap-1 text-sm border rounded-lg px-3 py-1.5">
                        <input type="checkbox" name="goal_ids[]" value="{{ $goal->id }}"
                               @checked($coach->goals->contains($goal->id))>
                        {{ $goal->title }}
                    </label>
                @endforeach
            </div>
        </div>

        <button class="bg-gray-900 text-white px-5 py-2 rounded-lg text-sm">ذخیره تغییرات</button>
    </form>

    {{-- مدارک --}}
    <div class="bg-white rounded-xl shadow-sm p-6">
        <h2 class="font-semibold mb-3">مدارک و رزومه (فایل)</h2>

        <form method="POST" action="{{ route('coach.documents.store') }}" enctype="multipart/form-data" class="flex flex-wrap items-center gap-2 mb-4">
            @csrf
            <select name="type" class="border rounded-lg px-3 py-2 text-sm" required>
                <option value="resume">فایل رزومه</option>
                <option value="certificate">مدرک مربیگری</option>
                <option value="other">سایر</option>
            </select>
            <input type="file" name="document" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx" required class="text-sm">
            <button class="bg-gray-900 text-white text-sm px-4 py-2 rounded-lg">آپلود مدرک</button>
        </form>
        @error('document') <p class="text-red-600 text-xs mb-3">{{ $message }}</p> @enderror

        <ul class="divide-y text-sm">
            @forelse($coach->documents as $doc)
                <li class="py-2 flex items-center justify-between">
                    <div>
                        <span class="font-medium">{{ $doc->type->label() }}</span>
                        <span class="text-gray-400">— {{ $doc->original_name }} ({{ $doc->humanSize() }})</span>
                    </div>
                    <div class="flex items-center gap-3">
                        <a href="{{ route('coach.documents.show', $doc) }}" class="text-blue-600 hover:underline">دانلود</a>
                        <form method="POST" action="{{ route('coach.documents.destroy', $doc) }}"
                              onsubmit="return confirm('این مدرک حذف شود؟');">
                            @csrf @method('DELETE')
                            <button class="text-red-600 hover:underline">حذف</button>
                        </form>
                    </div>
                </li>
            @empty
                <li class="py-2 text-gray-400">هنوز مدرکی آپلود نشده است.</li>
            @endforelse
        </ul>
    </div>
@endsection
