<?php $__env->startSection('title', 'Session Logs'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0">Session Logs</h4>
</div>

<!-- Filters -->
<div class="card mb-4">
    <div class="card-body">
        <form action="<?php echo e(route('dashboard.session-logs')); ?>" method="GET" class="row g-3">
            <div class="col-md-3">
                <label class="form-label">User</label>
                <select class="form-select" name="user_id">
                    <option value="">All Users</option>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($user->id); ?>" <?php echo e(request('user_id') == $user->id ? 'selected' : ''); ?>>
                        <?php echo e($user->name); ?>

                    </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="col-md-2">
                <label class="form-label">Action</label>
                <select class="form-select" name="action">
                    <option value="">All</option>
                    <option value="login" <?php echo e(request('action') == 'login' ? 'selected' : ''); ?>>Login</option>
                    <option value="logout" <?php echo e(request('action') == 'logout' ? 'selected' : ''); ?>>Logout</option>
                    <option value="force_logout" <?php echo e(request('action') == 'force_logout' ? 'selected' : ''); ?>>Force Logout</option>
                    <option value="device_change" <?php echo e(request('action') == 'device_change' ? 'selected' : ''); ?>>Device Change</option>
                </select>
            </div>

            <div class="col-md-3">
                <label class="form-label">From Date</label>
                <input type="date" class="form-control" name="from_date" value="<?php echo e(request('from_date')); ?>">
            </div>

            <div class="col-md-3">
                <label class="form-label">To Date</label>
                <input type="date" class="form-control" name="to_date" value="<?php echo e(request('to_date')); ?>">
            </div>

            <div class="col-md-1 d-flex align-items-end">
                <button type="submit" class="btn btn-primary w-100">
                    <i class="bi bi-search"></i>
                </button>
            </div>
        </form>
    </div>
</div>

<!-- Logs Table -->
<div class="card">
    <div class="card-body">
        <?php if($sessionLogs->isEmpty()): ?>
        <div class="text-center py-5 text-muted">
            <i class="bi bi-clock-history display-4"></i>
            <p class="mt-3">No session logs found</p>
        </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>User</th>
                        <th>Action</th>
                        <th>Device ID</th>
                        <th>Device Name</th>
                        <th>App Version</th>
                        <th>IP Address</th>
                        <th>Details</th>
                        <th>Time</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $sessionLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e($log->id); ?></td>
                        <td>
                            <?php if($log->user): ?>
                            <a href="<?php echo e(route('dashboard.user-details', $log->user_id)); ?>">
                                <?php echo e($log->user->name); ?>

                            </a>
                            <?php else: ?>
                            <span class="text-muted">Deleted User</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php
                            $actionColors = [
                            'login' => 'success',
                            'logout' => 'secondary',
                            'force_logout' => 'danger',
                            'device_change' => 'warning',
                            ];
                            $color = $actionColors[$log->action] ?? 'info';
                            ?>
                            <span class="badge bg-<?php echo e($color); ?>">
                                <?php echo e(ucwords(str_replace('_', ' ', $log->action))); ?>

                            </span>
                        </td>
                        <td>
                            <span class="text-truncate d-inline-block" style="max-width: 120px;"
                                title="<?php echo e($log->device_id); ?>">
                                <?php echo e($log->device_id ?? '-'); ?>

                            </span>
                        </td>
                        <td><?php echo e($log->device_name ?? '-'); ?></td>
                        <td><?php echo e($log->app_version ?? '-'); ?></td>
                        <td><?php echo e($log->ip_address ?? '-'); ?></td>
                        <td>
                            <?php if($log->details): ?>
                            <button type="button" class="btn btn-sm btn-outline-info"
                                data-bs-toggle="popover"
                                data-bs-trigger="hover"
                                data-bs-content="<?php echo e(json_encode($log->details)); ?>">
                                <i class="bi bi-info-circle"></i>
                            </button>
                            <?php else: ?>
                            -
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($log->created_at->format('M d, Y H:i:s')); ?></td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>

        <div class="d-flex justify-content-center mt-4">
            <?php echo e($sessionLogs->appends(request()->query())->links()); ?>

        </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
    // Initialize popovers
    document.addEventListener('DOMContentLoaded', function() {
        var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
        var popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
            return new bootstrap.Popover(popoverTriggerEl);
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/zwfgftjb/autopromix.byteengine.in/resources/views/dashboard/session-logs.blade.php ENDPATH**/ ?>