@extends('client.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">
        <select name="status" class="px-4 py-2 border border-gray-200 rounded-lg outline-none" onchange="this.form.submit()">
            <option value="">Бүх төлөв</option>
            <option value="submitted" @selected(request('status') === 'submitted')>Илгээгдсэн</option>
            <option value="reviewing" @selected(request('status') === 'reviewing')>Хянагдаж буй</option>
            <option value="in_progress" @selected(request('status') === 'in_progress')>Хийгдэж буй</option>
            <option value="completed" @selected(request('status') === 'completed')>Дууссан</option>
            <option value="cancelled" @selected(request('status') === 'cancelled')>Цуцлагдсан</option>
        </select>
    </form>
    <a href="{{ route('client.orders.create') }}" class="bg-nsma-red text-white font-semibold px-4 py-2 rounded-lg hover:bg-red-600">+ Шинэ захиалга</a>
</div>

<div class="space-y-3">
    @forelse($orders as $o)
        <a href="{{ route('client.orders.show', $o) }}" class="block bg-white rounded-2xl border border-gray-100 p-5 hover:border-nsma-red transition">
            <div class="flex items-start justify-between mb-2">
                <div class="flex-1 min-w-0">
                    <h3 class="font-bold text-lg mb-1">{{ $o->title }}</h3>
                    <div class="text-xs text-gray-500">{{ $o->order_number }} · {{ $o->service->title ?? '-' }}</div>
                </div>
                <span class="text-xs px-3 py-1 rounded-full bg-{{ $o->statusColor() }}-100 text-{{ $o->statusColor() }}-700">{{ $o->statusLabel() }}</span>
            </div>
            <p class="text-sm text-gray-600 line-clamp-2">{{ $o->description }}</p>
            <div class="flex items-center justify-between mt-3 pt-3 border-t border-gray-100 text-xs text-gray-500">
                <span>📅 Илгээсэн: {{ $o->created_at->format('Y-m-d') }}</span>
                @if($o->deadline) <span>⏰ Эцсийн өдөр: {{ $o->deadline->format('Y-m-d') }}</span> @endif
            </div>
        </a>
    @empty
        <div class="bg-white rounded-2xl border border-gray-100 p-12 text-center">
            <p class="text-gray-500 mb-4">Та одоохондоо захиалга хийгээгүй байна.</p>
            <a href="{{ route('client.orders.create') }}" class="inline-block bg-nsma-red text-white font-semibold px-5 py-2.5 rounded-lg hover:bg-red-600">+ Эхний захиалгаа өгөх</a>
        </div>
    @endforelse
</div>

<div class="mt-6">{{ $orders->links() }}</div>

@endsection
