@extends('admin.layouts.app')

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

@section('content')
    <div class="flex items-center justify-between mb-6">
        <h1 class="text-xl font-bold">بانک حرکات ورزشی</h1>
        <div class="flex gap-2">
            <a href="{{ route('admin.muscles.index') }}" class="bg-gray-100 text-sm px-4 py-2 rounded-lg">مدیریت عضلات</a>
            <a href="{{ route('admin.equipment.index') }}" class="bg-gray-100 text-sm px-4 py-2 rounded-lg">مدیریت تجهیزات</a>
            <a href="{{ route('admin.exercises.create') }}" class="bg-gray-900 text-white text-sm px-4 py-2 rounded-lg">+ حرکت جدید</a>
        </div>
    </div>

    <form method="GET" class="flex flex-wrap gap-2 mb-4">
        <input type="text" name="q" value="{{ request('q') }}" placeholder="جستجوی نام حرکت..."
               class="border rounded-lg px-3 py-2 text-sm flex-1 min-w-[160px]">
        <select name="muscle" class="border rounded-lg px-3 py-2 text-sm">
            <option value="">همه عضلات</option>
            @foreach($muscles as $muscle)
                <option value="{{ $muscle->id }}" @selected(request('muscle') == $muscle->id)>{{ $muscle->name }}</option>
            @endforeach
        </select>
        <select name="difficulty" class="border rounded-lg px-3 py-2 text-sm">
            <option value="">همه سطوح</option>
            <option value="beginner" @selected(request('difficulty') === 'beginner')>مبتدی</option>
            <option value="intermediate" @selected(request('difficulty') === 'intermediate')>متوسط</option>
            <option value="advanced" @selected(request('difficulty') === 'advanced')>پیشرفته</option>
        </select>
        <select name="status" class="border rounded-lg px-3 py-2 text-sm">
            <option value="">همه وضعیت‌ها</option>
            <option value="active" @selected(request('status') === 'active')>فعال</option>
            <option value="inactive" @selected(request('status') === 'inactive')>غیرفعال</option>
        </select>
        <button class="bg-gray-100 px-4 py-2 rounded-lg text-sm">فیلتر</button>
    </form>

    <div class="bg-white rounded-xl shadow-sm overflow-x-auto">
        <table class="w-full text-sm">
            <thead class="bg-gray-50 text-gray-500">
                <tr>
                    <th class="p-3 text-right">GIF</th>
                    <th class="p-3 text-right">نام</th>
                    <th class="p-3 text-right">عضله اصلی</th>
                    <th class="p-3 text-right">سطح سختی</th>
                    <th class="p-3 text-right">وضعیت</th>
                    <th class="p-3 text-right">عملیات</th>
                </tr>
            </thead>
            <tbody class="divide-y">
                @forelse($exercises as $exercise)
                    <tr>
                        <td class="p-3">
                            @if($exercise->gif_path)
                                <img src="{{ Storage::disk('public')->url($exercise->gif_path) }}" class="w-12 h-12 rounded object-cover">
                            @else
                                <div class="w-12 h-12 rounded bg-gray-100"></div>
                            @endif
                        </td>
                        <td class="p-3 font-medium">{{ $exercise->name }}</td>
                        <td class="p-3">{{ $exercise->mainMuscle?->name ?? '—' }}</td>
                        <td class="p-3">{{ $exercise->difficulty->label() }}</td>
                        <td class="p-3">
                            @if($exercise->is_active)
                                <span class="text-green-600 bg-green-50 px-2 py-1 rounded-full text-xs">فعال</span>
                            @else
                                <span class="text-gray-500 bg-gray-100 px-2 py-1 rounded-full text-xs">غیرفعال</span>
                            @endif
                        </td>
                        <td class="p-3 flex gap-3">
                            <a href="{{ route('admin.exercises.edit', $exercise) }}" class="text-blue-600 hover:underline">ویرایش</a>
                            <form method="POST" action="{{ route('admin.exercises.destroy', $exercise) }}" onsubmit="return confirm('حذف شود؟');">
                                @csrf @method('DELETE')
                                <button class="text-red-600 hover:underline">حذف</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="6" class="p-6 text-center text-gray-400">حرکتی ثبت نشده است.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="mt-4">{{ $exercises->links() }}</div>
@endsection
