@extends('layouts.admin')

@section('title', 'Candidaturas')

@section('content')
<div class="relative z-10 w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-12">
    <header class="mb-8 flex flex-col md:flex-row md:items-end justify-between gap-6 pt-6">
        <div>
            <div class="flex items-center gap-3 mb-2">
                <span class="w-8 h-[2px] bg-brand"></span>
                <span class="font-bold text-[10px] uppercase tracking-[0.4em] text-brand">Fornecedores</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold italic tracking-tighter uppercase text-brand">CANDIDATURAS</h1>
            <p class="text-slate-500 font-medium mt-1">Empresas que se candidataram a fornecedor</p>
        </div>
    </header>

    <div class="bg-white border border-slate-100 rounded-2xl shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="border-b border-slate-100 bg-slate-50/80 text-left">
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Estado</th>
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Empresa</th>
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Contacto</th>
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Tipo</th>
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Data</th>
                        <th class="px-4 py-3.5 font-bold text-[10px] uppercase tracking-widest text-slate-400">Acções</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-50">
                    @forelse($applications as $app)
                    <tr class="hover:bg-slate-50/50 transition-colors {{ $app->status?->value === 'submitted' ? 'bg-brand/[0.02]' : '' }}">
                        <td class="px-4 py-4">
                            @php
                                $colors = [
                                    'submitted' => 'bg-accent text-brand-900',
                                    'under_review' => 'bg-blue-50 text-blue-600',
                                    'contacted' => 'bg-green-50 text-green-600',
                                    'approved' => 'bg-emerald-50 text-emerald-700',
                                    'rejected' => 'bg-red-50 text-red-600',
                                    'archived' => 'bg-slate-50 text-slate-400',
                                ];
                            @endphp
                            <span class="inline-block px-2.5 py-1 rounded-full text-[9px] font-bold uppercase tracking-wider {{ $colors[$app->status?->value ?? 'submitted'] ?? 'bg-slate-100 text-slate-500' }}">
                                {{ $app->status?->label() ?? 'Submetida' }}
                            </span>
                        </td>
                        <td class="px-4 py-4 font-semibold text-slate-800">{{ $app->company_name }}</td>
                        <td class="px-4 py-4 text-slate-500">{{ $app->contact_name }}<br><span class="text-[10px]">{{ $app->email }}</span></td>
                        <td class="px-4 py-4">
                            <span class="text-[10px] font-bold uppercase tracking-wider text-slate-400">{{ $app->supplier_type->value }}</span>
                        </td>
                        <td class="px-4 py-4 text-slate-400 text-[11px] font-medium whitespace-nowrap">{{ $app->created_at->format('d/m/Y') }}</td>
                        <td class="px-4 py-4">
                            <a href="{{ route('admin.supplier-applications.show', $app) }}" class="inline-flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-widest text-brand hover:text-brand-700 transition">
                                <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 010-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                                Analisar
                            </a>
                        </td>
                    </tr>
                    @empty
                    <tr>
                        <td colspan="6" class="px-4 py-12 text-center text-slate-400 text-sm">Nenhuma candidatura recebida.</td>
                    </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        @if($applications->hasPages())
        <div class="px-4 py-4 border-t border-slate-100">
            {{ $applications->links() }}
        </div>
        @endif
    </div>
</div>
@endsection