@extends('admin.layouts.app')

@section('title', 'گزارش فعالیت‌ها')

@section('content')
    <h1 class="text-xl font-bold mb-6">گزارش فعالیت‌ها (Audit Log)</h1>

    <form method="GET" class="flex flex-wrap gap-2 mb-4">
        <input type="text" name="action" value="{{ request('action') }}" placeholder="نوع عملیات (مثل user.login)..."
               class="border rounded-lg px-3 py-2 text-sm flex-1 min-w-[180px]" dir="ltr">
        <input type="date" name="from" value="{{ request('from') }}" class="border rounded-lg px-3 py-2 text-sm">
        <input type="date" name="to" value="{{ request('to') }}" class="border rounded-lg px-3 py-2 text-sm">
        <button class="bg-gray-100 px-4 py-2 rounded-lg text-sm">اعمال فیلتر</button>
    </form>

    <div class="bg-white rounded-xl shadow-sm overflow-x-auto">
        <table class="w-full text-sm">
            <thead class="bg-gray-50 text-gray-500">
                <tr>
                    <th class="p-3 text-right">عملیات</th>
                    <th class="p-3 text-right">کاربر</th>
                    <th class="p-3 text-right">IP</th>
                    <th class="p-3 text-right">تاریخ و زمان</th>
                </tr>
            </thead>
            <tbody class="divide-y">
                @forelse($logs as $log)
                    <tr>
                        <td class="p-3 font-mono text-xs">{{ $log->action }}</td>
                        <td class="p-3">{{ $log->user?->fullName() ?? '—' }}</td>
                        <td class="p-3 text-gray-400" dir="ltr">{{ $log->ip_address ?? '—' }}</td>
                        <td class="p-3">{{ verta($log->created_at)->format('Y/m/d H:i') }}</td>
                    </tr>
                @empty
                    <tr><td colspan="4" class="p-6 text-center text-gray-400">لاگی یافت نشد.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="mt-4">{{ $logs->links() }}</div>
@endsection
