@extends('layouts.admin')

@section('title', 'Aktivite Logları')
@section('page-title', 'Aktivite Logları')

@section('content')

<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-4 mb-5 mt-2">
    <form method="GET" class="flex flex-wrap gap-3 items-end">
        <div>
            <label class="block text-xs font-medium text-gray-500 mb-1">Kullanıcı</label>
            <select name="causer_id" class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400">
                <option value="">Tüm Kullanıcılar</option>
                @foreach($users as $user)
                <option value="{{ $user->id }}" {{ request('causer_id') == $user->id ? 'selected' : '' }}>{{ $user->name }}</option>
                @endforeach
            </select>
        </div>
        <div>
            <label class="block text-xs font-medium text-gray-500 mb-1">Başlangıç</label>
            <input type="date" name="date_from" value="{{ request('date_from') }}"
                   class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400">
        </div>
        <div>
            <label class="block text-xs font-medium text-gray-500 mb-1">Bitiş</label>
            <input type="date" name="date_to" value="{{ request('date_to') }}"
                   class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-orange-400">
        </div>
        <button type="submit" class="bg-primary text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-orange-600 transition-colors">
            Filtrele
        </button>
    </form>
</div>

<div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
    <table class="w-full text-sm">
        <thead class="bg-gray-50 border-b border-gray-100">
            <tr>
                <th class="text-left px-5 py-3 font-semibold text-gray-600">Kullanıcı</th>
                <th class="text-left px-4 py-3 font-semibold text-gray-600">İşlem</th>
                <th class="text-left px-4 py-3 font-semibold text-gray-600">Nesne</th>
                <th class="text-left px-4 py-3 font-semibold text-gray-600">Tarih</th>
            </tr>
        </thead>
        <tbody class="divide-y divide-gray-50">
            @forelse($logs as $log)
            <tr class="hover:bg-gray-50 transition-colors">
                <td class="px-5 py-3">
                    <p class="font-medium text-gray-800">{{ $log->causer?->name ?? 'Sistem' }}</p>
                    <p class="text-xs text-gray-400">{{ $log->causer?->email }}</p>
                </td>
                <td class="px-4 py-3 text-gray-700">{{ $log->description }}</td>
                <td class="px-4 py-3 text-gray-500 text-xs">
                    {{ class_basename($log->subject_type ?? '') }}
                    @if($log->subject_id) #{{ $log->subject_id }} @endif
                </td>
                <td class="px-4 py-3 text-gray-500 text-xs">{{ $log->created_at->format('d.m.Y H:i') }}</td>
            </tr>
            @empty
            <tr>
                <td colspan="4" class="px-5 py-10 text-center text-gray-400">Log kaydı bulunamadı.</td>
            </tr>
            @endforelse
        </tbody>
    </table>
    @if($logs->hasPages())
    <div class="px-5 py-4 border-t border-gray-100">
        {{ $logs->appends(request()->query())->links() }}
    </div>
    @endif
</div>

@endsection