
<?php $__env->startSection('content'); ?>
<style>
    table {
      width: 100%;
      height: 50px; /* set a height so vertical centering is visible */
      border-collapse: collapse;
    }
    td {
      text-align: center;
      vertical-align: middle;
      border: 1px solid #ccc;
    }
  </style>
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
					<div class="d-flex justify-content-between align-items-center">
						<div>
							<?php echo e(__('Recent Audit Logs')); ?>

						</div>
						
					</div>
				</div>

                <div class="card-body">
					<input class="pull-right mb-3" type="text" id="searchInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">
                   <div class="table table-responsive">
						
						<table class="table table-bordered table-striped" id="dataTable" >
							<thead>
								<tr>
									<th>#</th>
									<th>Event</th>
									<th>User</th>
									<th>Model</th>
									<th>Old Values</th>
									<th>New Values</th>
									<th>Date</th>
								</tr>
							</thead>
							<tbody>
								<?php $__empty_1 = true; $__currentLoopData = $audits; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
									<tr>
										<td><?php echo e($index + 1); ?></td>
										<td><?php echo e(ucfirst($log->event)); ?></td>
										<td><?php echo e(optional($log->user)->name ?? 'System'); ?></td>
										<td><?php echo e(class_basename($log->auditable_type)); ?> (ID: <?php echo e($log->auditable_id); ?>)</td>
										<td>
											<?php if($log->old_values): ?>
												
													<?php if($log->old_values): ?>
														<ul style="list-style-type:none;">
															<?php $__currentLoopData = $log->old_values; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $field => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
																<?php if(in_array(pathinfo($value, PATHINFO_EXTENSION),['jpg','jpeg','png','pdf']) && !file_exists($value)): ?> 
																<li><b><?php echo e($field); ?>:</b> <img src="<?php echo e(asset('storage/'.$value)); ?>" style="width:40px;height:40px;" > </li>
																<?php else: ?>
																<li><b><?php echo e($field); ?>:</b> <?php echo e($value); ?></li>	
																<?php endif; ?>
															<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
														</ul>
													<?php else: ?>
														<em>—</em>
													<?php endif; ?>
													<!--
												<pre><?php echo e(json_encode($log->old_values, JSON_PRETTY_PRINT)); ?></pre>
													-->
											<?php else: ?>
												<em>—</em>
											<?php endif; ?>
										</td>
										<td>
											<?php if($log->new_values): ?>
											
													<?php if($log->new_values): ?>
														<ul style="list-style-type:none;">
															<?php $__currentLoopData = $log->new_values; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $field => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
																<?php if(in_array(pathinfo($value, PATHINFO_EXTENSION),['jpg','jpeg','png','pdf']) && !file_exists($value)): ?> 
																<li><b><?php echo e($field); ?>:</b> <img src="<?php echo e(asset('storage/'.$value)); ?>" style="width:40px;height:40px;" > </li>
																<?php else: ?>
																<li><b><?php echo e($field); ?>:</b> <?php echo e($value); ?></li>	
																<?php endif; ?>
															<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
														</ul>
													<?php else: ?>
														<em>—</em>
													<?php endif; ?>
											<!--
												<pre><?php echo e(json_encode($log->new_values, JSON_PRETTY_PRINT)); ?></pre>
											-->
											<?php else: ?>
												<em>—</em>
											<?php endif; ?>
										</td>
										<td><?php echo e($log->created_at->format('d M Y, H:i:s')); ?></td>
									</tr>
								<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
									<tr>
										<td colspan="7" class="text-center">No audit logs found.</td>
									</tr>
								<?php endif; ?>
							</tbody>
						</table>
					</div>					
                </div>
            </div>
        </div>
    </div>
</div>
<script>
document.getElementById('searchInput').addEventListener('keyup', function () {
  const searchTerm = this.value.toLowerCase();
  const rows = document.querySelectorAll('#dataTable tbody tr');

  rows.forEach(row => {
    const rowText = row.textContent.toLowerCase();
    row.style.display = rowText.includes(searchTerm) ? '' : 'none';
  });
});

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\nmc-elections\resources\views/audits/index.blade.php ENDPATH**/ ?>