@extends('admin.layouts.app')

@section('title', 'Хийсэн ажлууд')
@section('page_title', 'Хийсэн ажлууд')

@section('content')

<div class="flex items-center justify-between mb-6">
    <form method="GET" class="flex items-center gap-2">
        <input type="text" name="search" value="{{ request('search') }}" placeholder="Хайх..." class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
        <select name="category_id" class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
            <option value="">Бүх ангилал</option>
            @foreach($categories as $c)
                <option value="{{ $c->id }}" @selected(request('category_id') == $c->id)>{{ $c->name }}</option>
            @endforeach
        </select>
        <button class="px-4 py-2 bg-nsma-dark text-white rounded-lg">Шүүх</button>
    </form>
    <a href="{{ route('admin.portfolios.create') }}" class="bg-nsma-red text-white font-semibold px-4 py-2 rounded-lg">+ Шинэ ажил</a>
</div>

<div class="grid md:grid-cols-2 lg:grid-cols-3 gap-4">
    @forelse($portfolios as $p)
        <div class="bg-white rounded-2xl border border-gray-100 overflow-hidden">
            <img src="{{ $p->coverImageUrl() }}" class="w-full aspect-video object-cover" onerror="this.style.background='#0F1729'">
            <div class="p-4">
                <div class="flex items-center justify-between mb-2">
                    <span class="text-xs text-gray-500">{{ $p->category->name ?? '' }}</span>
                    @if($p->is_featured) <span class="text-xs px-2 py-0.5 rounded bg-yellow-100 text-yellow-700">⭐ Featured</span> @endif
                </div>
                <h4 class="font-semibold mb-1">{{ $p->title }}</h4>
                <p class="text-xs text-gray-500 mb-3">{{ $p->client_name }}</p>
                <div class="flex items-center justify-between">
                    <span class="text-xs px-2 py-1 rounded {{ $p->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">{{ $p->is_active ? 'Идэвхтэй' : 'Идэвхгүй' }}</span>
                    <div class="flex gap-1">
                        <a href="{{ route('admin.portfolios.edit', $p) }}" class="px-2 py-1 text-xs bg-nsma-dark text-white rounded">Засах</a>
                        <form action="{{ route('admin.portfolios.destroy', $p) }}" method="POST" class="inline" onsubmit="return confirm('Устгах уу?')">
                            @csrf @method('DELETE')
                            <button class="px-2 py-1 text-xs bg-red-500 text-white rounded">×</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    @empty
        <p class="col-span-full text-center text-gray-500 py-12">Ажил нэмээгүй байна.</p>
    @endforelse
</div>

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

@endsection
