@extends('admin.layout')
@section('title', 'Crawl Logs')
@section('page-title', 'Crawl Logs')

@section('content')
<div class="bg-gray-900 rounded-2xl border border-white/10 overflow-hidden">
  <table class="w-full text-sm">
    <thead>
      <tr class="border-b border-white/10 text-xs text-gray-500 uppercase tracking-wider">
        <th class="text-left px-5 py-3">Source</th>
        <th class="text-left px-4 py-3">Status</th>
        <th class="text-left px-4 py-3 hidden md:table-cell">Found</th>
        <th class="text-left px-4 py-3 hidden md:table-cell">Saved</th>
        <th class="text-left px-4 py-3 hidden md:table-cell">Skipped</th>
        <th class="text-left px-4 py-3 hidden lg:table-cell">Duration</th>
        <th class="text-left px-4 py-3">Started</th>
        <th class="text-left px-4 py-3 hidden lg:table-cell">Error</th>
      </tr>
    </thead>
    <tbody class="divide-y divide-white/5">
      @forelse($logs as $log)
      @php $sc = ['ok'=>'text-green-400','success'=>'text-green-400','error'=>'text-red-400','blocked'=>'text-orange-400','empty'=>'text-gray-500']; @endphp
      <tr class="hover:bg-white/3 transition-colors">
        <td class="px-5 py-3 text-white">{{ $log->source?->name ?? 'Unknown' }}</td>
        <td class="px-4 py-3"><span class="text-xs font-medium {{ $sc[$log->status] ?? 'text-gray-400' }}">{{ $log->status }}</span></td>
        <td class="px-4 py-3 text-gray-400 hidden md:table-cell">{{ $log->articles_found ?? 0 }}</td>
        <td class="px-4 py-3 text-gray-400 hidden md:table-cell">{{ $log->articles_saved ?? 0 }}</td>
        <td class="px-4 py-3 text-gray-400 hidden md:table-cell">{{ $log->articles_skipped ?? 0 }}</td>
        <td class="px-4 py-3 text-gray-500 text-xs hidden lg:table-cell">{{ $log->duration_seconds ?? 0 }}s</td>
        <td class="px-4 py-3 text-gray-500 text-xs">{{ \Carbon\Carbon::parse($log->started_at)->diffForHumans() }}</td>
        <td class="px-4 py-3 hidden lg:table-cell">
          @if($log->error_message)
            <span class="text-xs text-red-400 line-clamp-1">{{ Str::limit($log->error_message, 60) }}</span>
          @endif
        </td>
      </tr>
      @empty
      <tr>
        <td colspan="8" class="px-5 py-12 text-center text-gray-500">No logs yet.</td>
      </tr>
      @endforelse
    </tbody>
  </table>
</div>
<div class="mt-4">{{ $logs->links() }}</div>
@endsection
