@extends('layouts.admin')
@section('title','Professional Applications')
@section('subtitle','Review professional credentials, documents, and application decisions.')
@section('content')
<form class="filter-panel application-filters" method="get">
    <div class="tabs">
        <a class="{{!request('status')?'active':''}}" href="{{route('applications')}}">All</a>@foreach(['pending','approved','declined'] as $status) <a class="{{request('status')===$status?'active':''}}" href="{{route('applications',['status'=>$status])}}">{{ucfirst($status)}}</a>@endforeach
    </div>
    <div class="filter-controls">
        <input name="q" value="{{request('q')}}" placeholder="Search applicant or email">
        <input type="hidden" name="status" value="{{request('status')}}">
        <button>Search</button>
    </div>
</form>
<div class="application-stats">
    <article>
        <span>
            <i data-lucide="files"></i>
        </span>
        <div>
            <p>Total Applications</p>
            <strong>{{number_format($stats['total'])}}</strong>
        </div>
    </article>
    <article>
        <span class="pending">
            <i data-lucide="clock-3"></i>
        </span>
        <div>
            <p>Pending Review</p>
            <strong>{{number_format($stats['pending'])}}</strong>
        </div>
    </article>
    <article>
        <span>
            <i data-lucide="badge-check"></i>
        </span>
        <div>
            <p>Approved</p>
            <strong>{{number_format($stats['approved'])}}</strong>
        </div>
    </article>
    <article>
        <span class="declined">
            <i data-lucide="circle-x"></i>
        </span>
        <div>
            <p>Declined</p>
            <strong>{{number_format($stats['declined'])}}</strong>
        </div>
    </article>
</div>
<div class="application-table">
    <div class="table-scroll">
        <table>
            <thead>
                <tr>
                    <th>Applicant</th>
                    <th>Profession</th>
                    <th>Submitted</th>
                    <th>Default Rate</th>
                    <th>Status</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>@forelse($applications as $application) <tr>
                    <td>
                        <div class="user-cell">
                            <div class="avatar application-avatar" style="--avatar-border:{{$application->profession?->color_hex??'#d8ddd4'}}">{{strtoupper(substr($application->user?->profile?->full_name??'P',0,1))}}</div>
                            <div>
                                <b>{{$application->user?->profile?->full_name??'Professional'}}</b>
                                <span>{{$application->user?->email}}</span>
                            </div>
                        </div>
                    </td>
                    <td>
                        <b>{{$application->profession?->name??'—'}}</b>
                        <small>{{$application->profession?->salutation}}</small>
                    </td>
                    <td>{{$application->updated_at?->format('M d, Y')}}
                        <small>{{$application->updated_at?->diffForHumans()}}</small>
                    </td>
                    <td>
                        <b>₱{{number_format($application->default_rate,2)}}</b>
                    </td>
                    <td>
                        <span class="application-status {{$application->status}}">{{ucfirst($application->status)}}</span>
                    </td>
                    <td>
                        <a class="review-link" href="{{route('applications.show',$application)}}">Review <i data-lucide="arrow-right"></i>
                        </a>
                    </td>
                </tr>@empty <tr>
                    <td colspan="6" class="empty">No professional applications match this filter.</td>
                </tr>@endforelse </tbody>
        </table>
    </div>
    <div class="table-footer">
        <span>Showing {{$applications->firstItem()??0}} to {{$applications->lastItem()??0}} of {{number_format($applications->total())}} applications</span>{{$applications->onEachSide(1)->links('vendor.pagination.default')}}
    </div>
</div>
@endsection
