@extends('layouts.app')

@section('title', 'Hasil Pencarian')
@section('subtitle', 'Menampilkan hasil untuk "' . $query . '"')

@section('breadcrumb')
    <li class="flex items-center">
        <i class="fas fa-chevron-right text-xs text-secondary-400 mx-2"></i>
        <span class="text-sm font-medium text-secondary-700">Pencarian</span>
    </li>
@endsection

@section('content')
<div class="space-y-8">
    
    <!-- Reports Matches -->
    @if(count($reports) > 0)
    <section>
        <h3 class="text-lg font-bold text-secondary-800 mb-4 flex items-center">
            <i class="fas fa-file-alt text-primary-500 mr-2"></i>
            Laporan Terkait
        </h3>
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
            @foreach($reports as $report)
            <a href="{{ route($report['route']) }}" class="glass-card rounded-2xl p-4 hover:border-primary-300 transition-all group">
                <div class="flex items-center">
                    <div class="w-10 h-10 rounded-xl bg-primary-50 text-primary-600 flex items-center justify-center group-hover:bg-primary-500 group-hover:text-white transition-all">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <div class="ml-3">
                        <p class="font-medium text-secondary-800">{{ $report['name'] }}</p>
                        <p class="text-xs text-secondary-500">Klik untuk melihat laporan</p>
                    </div>
                </div>
            </a>
            @endforeach
        </div>
    </section>
    @endif

    <!-- Employee Results -->
    <section>
        <h3 class="text-lg font-bold text-secondary-800 mb-4 flex items-center">
            <i class="fas fa-users text-primary-500 mr-2"></i>
            Pegawai ({{ count($employees) }})
        </h3>
        @if(count($employees) > 0)
        <div class="glass-card rounded-2xl overflow-hidden">
            <table class="w-full">
                <thead class="bg-secondary-50/50">
                    <tr>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-secondary-500 uppercase">Pegawai</th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-secondary-500 uppercase">NIP</th>
                        <th class="px-6 py-4 text-left text-xs font-semibold text-secondary-500 uppercase">Departemen</th>
                        <th class="px-6 py-4 text-right text-xs font-semibold text-secondary-500 uppercase">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-secondary-100">
                    @foreach($employees as $employee)
                    <tr class="hover:bg-white/60 transition-colors">
                        <td class="px-6 py-4">
                            <div class="flex items-center">
                                <div class="w-8 h-8 rounded-full bg-primary-100 text-primary-700 flex items-center justify-center text-xs font-bold">
                                    {{ substr($employee->name, 0, 2) }}
                                </div>
                                <div class="ml-3">
                                    <p class="text-sm font-medium text-secondary-800">{{ $employee->name }}</p>
                                    <p class="text-xs text-secondary-500">{{ $employee->position }}</p>
                                </div>
                            </div>
                        </td>
                        <td class="px-6 py-4 text-sm text-secondary-600">{{ $employee->nip }}</td>
                        <td class="px-6 py-4 text-sm text-secondary-600">{{ $employee->department->name ?? '-' }}</td>
                        <td class="px-6 py-4 text-right">
                            <a href="{{ route('employees.show', $employee) }}" class="text-primary-600 hover:text-primary-700 font-medium text-sm">Detail</a>
                        </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        @else
        <div class="glass-card rounded-2xl p-8 text-center text-secondary-400 border-dashed border-2">
            <p>Tidak ada pegawai yang cocok dengan pencarian.</p>
        </div>
        @endif
    </section>

    <!-- Catalog Results -->
    <section>
        <h3 class="text-lg font-bold text-secondary-800 mb-4 flex items-center">
            <i class="fas fa-key text-primary-500 mr-2"></i>
            Katalog Akses ({{ count($catalogs) }})
        </h3>
        @if(count($catalogs) > 0)
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
            @foreach($catalogs as $catalog)
            <div class="glass-card rounded-2xl p-4">
                <div class="flex justify-between items-start mb-2">
                    <span class="px-2 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider
                        {{ $catalog->criticality_level == 'critical' ? 'bg-rose-100 text-rose-700' : 
                           ($catalog->criticality_level == 'high' ? 'bg-orange-100 text-orange-700' : 'bg-primary-100 text-primary-700') }}">
                        {{ $catalog->criticality_level }}
                    </span>
                    <span class="text-xs font-mono text-secondary-400">{{ $catalog->code }}</span>
                </div>
                <h4 class="font-bold text-secondary-800">{{ $catalog->name }}</h4>
                <p class="text-xs text-secondary-500 mt-1">{{ Str::limit($catalog->description, 100) }}</p>
                <div class="mt-4 pt-3 border-t border-secondary-100 flex justify-between items-center">
                    <span class="text-xs text-secondary-400">{{ $catalog->ownerDepartment->name ?? 'No Owner' }}</span>
                    <a href="{{ route('access-catalogs.edit', $catalog) }}" class="text-primary-600 hover:text-primary-700 text-xs font-medium">Edit</a>
                </div>
            </div>
            @endforeach
        </div>
        @else
        <div class="glass-card rounded-2xl p-8 text-center text-secondary-400 border-dashed border-2">
            <p>Tidak ada katalog akses yang cocok dengan pencarian.</p>
        </div>
        @endif
    </section>

    @if(count($employees) == 0 && count($catalogs) == 0 && count($reports) == 0)
    <div class="flex flex-col items-center justify-center py-20">
        <div class="w-20 h-20 rounded-full bg-secondary-100 flex items-center justify-center mb-4">
            <i class="fas fa-search text-3xl text-secondary-300"></i>
        </div>
        <h2 class="text-xl font-bold text-secondary-800">Tidak ada hasil ditemukan</h2>
        <p class="text-secondary-500 mt-2">Coba kata kunci lain atau periksa ejaan Anda.</p>
        <a href="{{ route('dashboard') }}" class="mt-6 px-6 py-2 bg-primary-500 text-white rounded-xl hover:bg-primary-600 transition-all">Kembali ke Dashboard</a>
    </div>
    @endif

</div>
@endsection
