{{-- admin/pages/applications/index.blade.php --}}
@extends('admin.layouts.app')
@section('title','CV Applications')
@section('page-title','CV Applications')
@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <div style="font-size:.82rem;color:#64748b">{{ $applications->total() }} total applications</div>
    <select class="form-select form-select-sm" onchange="location='?status='+this.value" style="width:auto">
        <option value="">All Status</option>
        <option value="new" {{ request('status')=='new'?'selected':'' }}>New</option>
        <option value="reviewed" {{ request('status')=='reviewed'?'selected':'' }}>Reviewed</option>
        <option value="shortlisted" {{ request('status')=='shortlisted'?'selected':'' }}>Shortlisted</option>
        <option value="rejected" {{ request('status')=='rejected'?'selected':'' }}>Rejected</option>
    </select>
</div>
<div class="card-admin">
    <table class="table table-hover mb-0">
        <thead><tr><th>#</th><th>Applicant</th><th>Position</th><th>CV</th><th>Date</th><th>Status</th><th style="width:100px">Actions</th></tr></thead>
        <tbody>
            @forelse($applications as $app)
            <tr class="{{ $app->status=='new' ? 'fw-600' : '' }}">
                <td class="text-muted">{{ $app->id }}</td>
                <td>
                    <div style="color:#0f172a">{{ $app->name }}</div>
                    <div style="font-size:.74rem;color:#94a3b8">{{ $app->email }}</div>
                </td>
                <td style="font-size:.82rem;color:#64748b">{{ $app->position_applied ?? '—' }}</td>
                <td>
                    @if($app->cv_file)
                    <a href="{{ asset('uploads/'.$app->cv_file) }}" target="_blank" class="btn btn-sm" style="background:#dbeafe;color:#1e40af;border:none;font-size:.72rem"><i class="bi bi-download me-1"></i>CV</a>
                    @else <span class="text-muted" style="font-size:.78rem">No file</span> @endif
                </td>
                <td style="font-size:.78rem;color:#64748b">{{ $app->created_at->format('d M Y') }}</td>
                <td>
                    @php $sc=['new'=>['#fef9c3','#854d0e'],'reviewed'=>['#eff6ff','#1d4ed8'],'shortlisted'=>['#f0fdf4','#166534'],'rejected'=>['#fee2e2','#991b1b']]; $c=$sc[$app->status]??['#f1f5f9','#374151']; @endphp
                    <span class="badge" style="background:{{ $c[0] }};color:{{ $c[1] }};font-size:.7rem">{{ ucfirst($app->status) }}</span>
                </td>
                <td>
                    <div class="d-flex gap-1">
                        <a href="{{ route('admin.applications.show', $app->id) }}" class="btn btn-sm" style="background:#eff6ff;color:#1d4ed8;border:none"><i class="bi bi-eye"></i></a>
                        <form method="POST" action="{{ route('admin.applications.destroy', $app->id) }}" onsubmit="return confirm('Delete?')">@csrf @method('DELETE')
                            <button class="btn btn-sm" style="background:#fee2e2;color:#991b1b;border:none"><i class="bi bi-trash"></i></button>
                        </form>
                    </div>
                </td>
            </tr>
            @empty
            <tr><td colspan="7" class="text-center py-4 text-muted">No applications yet.</td></tr>
            @endforelse
        </tbody>
    </table>
    @if($applications->hasPages())<div class="p-3 border-top">{{ $applications->links() }}</div>@endif
</div>
@endsection
