@extends('admin.layouts.app')

@section('title', 'اهداف ورزشی')

@section('content')
    <div class="flex items-center justify-between mb-6">
        <h1 class="text-xl font-bold">اهداف ورزشی</h1>
        <a href="{{ route('admin.goals.create') }}" class="bg-gray-900 text-white text-sm px-4 py-2 rounded-lg">
            + هدف جدید
        </a>
    </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-[180px]">
        <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">عنوان</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($goals as $goal)
                    <tr>
                        <td class="p-3 font-medium">{{ $goal->title }}</td>
                        <td class="p-3 text-gray-500">{{ \Illuminate\Support\Str::limit($goal->short_description, 60) }}</td>
                        <td class="p-3">
                            @if($goal->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">{{ $goal->sort_order }}</td>
                        <td class="p-3 flex gap-3">
                            <a href="{{ route('admin.goals.edit', $goal) }}" class="text-blue-600 hover:underline">ویرایش</a>
                            <form method="POST" action="{{ route('admin.goals.destroy', $goal) }}"
                                  onsubmit="return confirm('حذف/غیرفعال‌سازی این هدف انجام شود؟');">
                                @csrf
                                @method('DELETE')
                                <button class="text-red-600 hover:underline">حذف</button>
                            </form>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="5" class="p-6 text-center text-gray-400">هیچ هدفی ثبت نشده است.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

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