@extends('layouts.app')

@section('title', 'Platform Security Activity')

@section('content')
<div class="space-y-6">
    <div>
        <h1 class="text-xl font-bold text-slate-900 dark:text-white">Security & Impersonation Audit Center</h1>
        <p class="text-xs text-slate-500">Monitor tenant impersonation logs, failed login attempts, and suspicious platform activity.</p>
    </div>

    <!-- Impersonation Activity Trail Table (Requirement 42, 53) -->
    <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700/60 shadow-sm overflow-hidden text-xs">
        <div class="p-4 border-b border-slate-200 dark:border-slate-700 font-bold flex justify-between items-center">
            <span>Tenant Impersonation Audit Logs</span>
            <a href="{{ route('platform.security.audit') }}" class="text-sky-600 font-bold hover:underline">Full System Audit ➔</a>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full text-left rtl:text-right">
                <thead class="bg-slate-50 dark:bg-slate-900/60 border-b border-slate-200 dark:border-slate-700 text-slate-500 uppercase tracking-wider font-bold">
                    <tr>
                        <th class="px-6 py-4">Admin Staff User</th>
                        <th class="px-6 py-4">Tenant Impersonated</th>
                        <th class="px-6 py-4">Mandatory Reason</th>
                        <th class="px-6 py-4">Started At</th>
                        <th class="px-6 py-4">Ended At</th>
                        <th class="px-6 py-4">IP Address</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200 dark:divide-slate-700/60 font-medium">
                    @foreach($impersonationLogs as $log)
                        <tr class="hover:bg-slate-50 dark:hover:bg-slate-700/30">
                            <td class="px-6 py-4 font-bold text-slate-900 dark:text-white">{{ $log->staff ? $log->staff->name : 'Admin' }}</td>
                            <td class="px-6 py-4 font-bold text-sky-600 dark:text-sky-400">{{ $log->tenant ? $log->tenant->company_name : 'N/A' }}</td>
                            <td class="px-6 py-4 text-slate-600 dark:text-slate-300 font-normal">{{ $log->reason }}</td>
                            <td class="px-6 py-4 text-slate-500 font-mono">{{ $log->started_at->format('d M Y, h:i A') }}</td>
                            <td class="px-6 py-4 text-slate-500 font-mono">{{ $log->ended_at ? $log->ended_at->format('h:i A') : 'Active' }}</td>
                            <td class="px-6 py-4 font-mono text-slate-400">{{ $log->ip_address ?? '127.0.0.1' }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
