<?php $__env->startSection('title', __('messages.audit_logs')); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="fw-bold mb-0">System Audit Trail Logs</h5>
        <span class="text-muted fs-xs">Immutable Security Log Tracking User Actions, System Modifications, and Login Activity</span>
    </div>
</div>

<div class="card-erp p-3 mb-3">
    <form method="GET" action="<?php echo e(route('audit-logs.index')); ?>" class="row g-2">
        <div class="col-md-4">
            <input type="text" name="search" class="form-control form-control-sm" placeholder="Search by Action, User, or Record ID..." value="<?php echo e(request('search')); ?>">
        </div>
        <div class="col-md-3">
            <select name="module" class="form-select form-select-sm">
                <option value="">All Modules...</option>
                <?php $__currentLoopData = $modules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($mod); ?>" <?php echo e(request('module') === $mod ? 'selected' : ''); ?>><?php echo e($mod); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div class="col-md-2">
            <button type="submit" class="btn btn-sm btn-primary w-100"><i class="bi bi-filter me-1"></i> Filter</button>
        </div>
        <div class="col-md-2">
            <a href="<?php echo e(route('audit-logs.index')); ?>" class="btn btn-sm btn-outline-secondary w-100">Reset</a>
        </div>
    </form>
</div>

<div class="card-erp">
    <div class="table-responsive">
        <table class="table table-dense table-hover mb-0">
            <thead>
                <tr>
                    <th>Timestamp</th>
                    <th>User</th>
                    <th>Action</th>
                    <th>Module</th>
                    <th>Record ID</th>
                    <th>IP Address</th>
                    <th>User Agent</th>
                    <th class="text-end">Changes</th>
                </tr>
            </thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td class="font-monospace fs-xs"><?php echo e($log->created_at->format('Y-m-d H:i:s')); ?></td>
                        <td class="fw-bold text-dark"><?php echo e($log->user_name ?? ($log->user->name ?? 'System')); ?></td>
                        <td><span class="badge bg-secondary font-monospace"><?php echo e($log->action); ?></span></td>
                        <td><span class="badge bg-light text-dark border"><?php echo e($log->module); ?></span></td>
                        <td><?php echo e($log->record_id ?? '-'); ?></td>
                        <td class="font-monospace fs-xs"><?php echo e($log->ip_address ?? '-'); ?></td>
                        <td class="text-truncate fs-xs text-muted" style="max-width: 150px;" title="<?php echo e($log->user_agent); ?>">
                            <?php echo e($log->user_agent ?? '-'); ?>

                        </td>
                        <td class="text-end">
                            <?php if($log->old_values || $log->new_values): ?>
                                <button class="btn btn-dense btn-outline-info" data-bs-toggle="modal" data-bs-target="#logModal<?php echo e($log->id); ?>">
                                    <i class="bi bi-eye"></i> View JSON
                                </button>
                            <?php else: ?>
                                <span class="text-muted fs-xs">No Diff</span>
                            <?php endif; ?>
                        </td>
                    </tr>

                    <?php if($log->old_values || $log->new_values): ?>
                        <div class="modal fade" id="logModal<?php echo e($log->id); ?>" tabindex="-1">
                            <div class="modal-dialog modal-lg">
                                <div class="modal-content">
                                    <div class="modal-header py-2">
                                        <h6 class="modal-title fw-bold">Audit Log #<?php echo e($log->id); ?> - <?php echo e($log->action); ?></h6>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                    </div>
                                    <div class="modal-body fs-xs">
                                        <div class="row g-2">
                                            <div class="col-6">
                                                <h6 class="fw-bold text-danger">Old Values</h6>
                                                <pre class="bg-light p-2 border rounded" style="max-height: 250px;"><?php echo e(json_encode($log->old_values, JSON_PRETTY_PRINT)); ?></pre>
                                            </div>
                                            <div class="col-6">
                                                <h6 class="fw-bold text-success">New Values</h6>
                                                <pre class="bg-light p-2 border rounded" style="max-height: 250px;"><?php echo e(json_encode($log->new_values, JSON_PRETTY_PRINT)); ?></pre>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr><td colspan="8" class="text-center py-4 text-muted">No audit logs recorded yet.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
    <div class="p-2 border-top">
        <?php echo e($logs->links()); ?>

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

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\saudi\resources\views\audit_logs\index.blade.php ENDPATH**/ ?>