@extends('layouts.admin')

@section('title', 'Dashboard')
@section('page-title', 'Dashboard')

@section('content')

{{-- İstatistik Kartları --}}
<div class="grid grid-cols-1 sm:grid-cols-3 gap-5 mt-2 mb-6">
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-5">
        <div class="flex items-center justify-between">
            <div>
                <p class="text-sm text-gray-500 mb-1">Açık Pozisyonlar</p>
                <p class="text-3xl font-bold text-gray-800">{{ $openJobsCount }}</p>
            </div>
            <div class="w-12 h-12 bg-orange-50 rounded-xl flex items-center justify-center">
                <svg class="w-6 h-6 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2 2v2m4 6h.01M5 20h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
            </div>
        </div>
    </div>

    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-5">
        <div class="flex items-center justify-between">
            <div>
                <p class="text-sm text-gray-500 mb-1">Bu Hafta Başvuru</p>
                <p class="text-3xl font-bold text-gray-800">{{ $thisWeekApplications }}</p>
            </div>
            <div class="w-12 h-12 bg-blue-50 rounded-xl flex items-center justify-center">
                <svg class="w-6 h-6 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
            </div>
        </div>
    </div>

    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-5">
        <div class="flex items-center justify-between">
            <div>
                <p class="text-sm text-gray-500 mb-1">Toplam Başvuru</p>
                <p class="text-3xl font-bold text-gray-800">{{ $totalApplications }}</p>
            </div>
            <div class="w-12 h-12 bg-green-50 rounded-xl flex items-center justify-center">
                <svg class="w-6 h-6 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
            </div>
        </div>
    </div>
</div>

<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">

    {{-- Son Başvurular --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-100">
        <div class="px-5 py-4 border-b border-gray-100 flex items-center justify-between">
            <h2 class="font-bold text-gray-800">Son Başvurular</h2>
            <a href="{{ route('admin.basvurular.index') }}" class="text-xs text-primary hover:underline">Tümünü Gör</a>
        </div>
        <div class="divide-y divide-gray-50">
            @forelse($recentApplications as $app)
            <div class="px-5 py-3 flex items-center justify-between hover:bg-gray-50 transition-colors">
                <div class="flex-1 min-w-0">
                    <p class="text-sm font-medium text-gray-800 truncate">{{ $app->full_name }}</p>
                    <p class="text-xs text-gray-500 truncate">{{ $app->jobPosting->title ?? '—' }}</p>
                </div>
                <div class="flex items-center gap-3 ml-3">
                    @php
                        $colors = ['yeni' => 'blue', 'incelendi' => 'yellow', 'görüşmeye_çağrıldı' => 'purple', 'reddedildi' => 'red', 'işe_alındı' => 'green'];
                        $color = $colors[$app->status] ?? 'gray';
                    @endphp
                    <span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-{{ $color }}-100 text-{{ $color }}-700">
                        {{ $app->status_label }}
                    </span>
                    <span class="text-xs text-gray-400">{{ $app->created_at->diffForHumans() }}</span>
                    <a href="{{ route('admin.basvurular.show', $app) }}" class="text-gray-400 hover:text-primary">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
                    </a>
                </div>
            </div>
            @empty
            <div class="px-5 py-8 text-center text-gray-400 text-sm">Henüz başvuru yok.</div>
            @endforelse
        </div>
    </div>

    {{-- Departmana Göre Başvurular --}}
    <div class="bg-white rounded-xl shadow-sm border border-gray-100">
        <div class="px-5 py-4 border-b border-gray-100">
            <h2 class="font-bold text-gray-800">Departmana Göre Başvurular</h2>
        </div>
        <div class="p-5">
            @forelse($applicationsByDepartment as $dept)
            <div class="mb-4">
                <div class="flex items-center justify-between mb-1">
                    <span class="text-sm text-gray-700">{{ $dept->department }}</span>
                    <span class="text-sm font-semibold text-gray-800">{{ $dept->count }}</span>
                </div>
                <div class="w-full bg-gray-100 rounded-full h-2">
                    @php $maxCount = $applicationsByDepartment->max('count'); @endphp
                    <div class="bg-primary h-2 rounded-full" style="width: {{ $maxCount > 0 ? ($dept->count / $maxCount * 100) : 0 }}%"></div>
                </div>
            </div>
            @empty
            <p class="text-gray-400 text-sm text-center py-4">Veri yok.</p>
            @endforelse
        </div>

        {{-- Durum Özeti --}}
        @if($applicationsByStatus->isNotEmpty())
        <div class="px-5 pb-5 border-t border-gray-50 pt-4">
            <h3 class="text-sm font-semibold text-gray-700 mb-3">Durum Özeti</h3>
            <div class="grid grid-cols-2 gap-2">
                @foreach(['yeni' => ['Yeni', 'blue'], 'incelendi' => ['İncelendi', 'yellow'], 'görüşmeye_çağrıldı' => ['Görüşme', 'purple'], 'reddedildi' => ['Reddedildi', 'red'], 'işe_alındı' => ['İşe Alındı', 'green']] as $key => [$label, $color])
                <div class="flex items-center justify-between bg-{{ $color }}-50 rounded-lg px-3 py-2">
                    <span class="text-xs text-{{ $color }}-700">{{ $label }}</span>
                    <span class="text-sm font-bold text-{{ $color }}-700">{{ $applicationsByStatus[$key] ?? 0 }}</span>
                </div>
                @endforeach
            </div>
        </div>
        @endif
    </div>

</div>

@endsection