@extends('admin.layouts.app')

@section('title', 'Уулзалтууд')
@section('page_title', 'Уулзалтууд')

@section('content')

<div class="flex flex-wrap items-center gap-2 mb-6">
    @php $tabs = ['' => ['Бүгд','all'], 'pending' => ['Хүлээгдэж буй','pending'], 'confirmed' => ['Баталгаажсан','confirmed'], 'completed' => ['Дууссан','completed'], 'cancelled' => ['Цуцлагдсан','cancelled']]; @endphp
    @foreach($tabs as $key => [$label, $cKey])
        <a href="{{ route('admin.meetings.index', array_filter(['status' => $key])) }}"
           class="px-4 py-2 rounded-lg text-sm font-semibold transition {{ request('status', '') === $key ? 'bg-nsma-red text-white' : 'bg-white border border-gray-200' }}">
            {{ $label }} ({{ $statusCounts[$cKey] ?? 0 }})
        </a>
    @endforeach
</div>

<form method="GET" class="flex items-center gap-2 mb-6">
    <input type="hidden" name="status" value="{{ request('status') }}">
    <input type="text" name="search" value="{{ request('search') }}" placeholder="Хайх..." class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
    <input type="date" name="date_from" value="{{ request('date_from') }}" class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
    <input type="date" name="date_to" value="{{ request('date_to') }}" class="px-4 py-2 border border-gray-200 rounded-lg outline-none">
    <button class="px-4 py-2 bg-nsma-dark text-white rounded-lg">Шүүх</button>
</form>

<div class="bg-white rounded-2xl border border-gray-100 overflow-hidden">
    <table class="w-full">
        <thead class="bg-gray-50 border-b">
            <tr>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Огноо/Цаг</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Хүн</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Сэдэв</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Төрөл</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Хариуцагч</th>
                <th class="text-left px-4 py-3 text-xs font-semibold uppercase">Төлөв</th>
                <th class="text-right px-4 py-3 text-xs font-semibold uppercase"></th>
            </tr>
        </thead>
        <tbody>
            @forelse($meetings as $m)
                <tr class="border-b border-gray-100">
                    <td class="px-4 py-3 text-sm">{{ $m->preferred_date->format('Y-m-d') }} {{ substr($m->preferred_time, 0, 5) }}</td>
                    <td class="px-4 py-3">
                        <div class="font-semibold">{{ $m->full_name }}</div>
                        <div class="text-xs text-gray-500">{{ $m->company_name ?? $m->email }}</div>
                    </td>
                    <td class="px-4 py-3 text-sm">{{ $m->subject }}</td>
                    <td class="px-4 py-3 text-sm">{{ $m->meetingTypeLabel() }}</td>
                    <td class="px-4 py-3 text-sm">{{ $m->assignedUser->name ?? '-' }}</td>
                    <td class="px-4 py-3"><span class="text-xs px-2 py-1 rounded-full bg-{{ $m->statusColor() }}-100 text-{{ $m->statusColor() }}-700">{{ $m->statusLabel() }}</span></td>
                    <td class="px-4 py-3 text-right">
                        <a href="{{ route('admin.meetings.show', $m) }}" class="px-3 py-1 text-xs bg-nsma-red text-white rounded">Үзэх</a>
                    </td>
                </tr>
            @empty
                <tr><td colspan="7" class="text-center py-12 text-gray-500">Уулзалт байхгүй байна.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>

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

@endsection
