<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log de Cambios</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f9f9f9;
            color: #333;
        }
        .log-container {
            width: 100%;
            max-width: 900px;
            margin: auto;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            padding: 15px;
        }
        .log-header {
            text-align: center;
            font-size: 1.5rem;
            margin-bottom: 20px;
        }
        .log-entry {
            margin-bottom: 20px;
            border-bottom: 1px solid #ddd;
            padding-bottom: 10px;
        }
        .log-meta {
            font-size: 0.9rem;
            color: #666;
            margin-bottom: 10px;
        }
        .log-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        .log-table th, .log-table td {
            text-align: left;
            padding: 10px;
            border: 1px solid #ddd;
        }
        .log-table th {
            background-color: #f5f5f5;
        }
        .log-table .highlight {
            background-color: #e6f7ff;
            font-weight: bold;
        }
        .log-no-changes {
            text-align: center;
            color: #999;
        }
    </style>
</head>
<body>
	<?php
	//pr($almacenes);
	?>
    <div class="log-container">
        <div class="log-header">Historial de Cambios</div>
        
	<?php
		foreach($log as $l) {
		?>
        <div class="log-entry">
            <div class="log-meta">
                <strong>ID Usuario:</strong> <?php echo $usuarios[$l['id_usuario']]; ?> <br>
                <strong>Fecha:</strong> <?php echo fechaHora($l['created'], 1, '-'); ?>
            </div>
            <table class="log-table">
                <thead>
                    <tr>
                        <th>Campo</th>
                        <th>Anterior</th>
                        <th>Actual</th>
                    </tr>
                </thead>
                <tbody>
					<?php
					foreach($l['cambios'] as $k => $v) {
						if ($k == 'almacenes'){
							foreach($v as $ka => $s) {
								if (!empty($s['stock'])) {
									?>
									<tr><td>Stock <?php echo $almacenes[$ka]; ?></td><td><?php echo $s['stock']['anterior']; ?></td><td class="highlight"><?php echo $s['stock']['actual']; ?></td></tr>
									<?php 
								}
								if (!empty($s['ubicacion'])) {
									?>
									<tr><td>Ubicación <?php echo $almacenes[$ka]; ?></td><td><?php echo $s['ubicacion']['anterior']; ?></td><td class="highlight"><?php echo $s['ubicacion']['actual']; ?></td></tr>
									<?php 
								}
								if (!empty($s['deseados'])) {
									?>
									<tr><td>Deseados Min <?php echo $almacenes[$ka]; ?></td><td><?php echo $s['deseados']['anterior']; ?></td><td class="highlight"><?php echo $s['deseados']['actual']; ?></td></tr>
									<?php 
								}
								if (!empty($s['deseados_max'])) {
									?>
									<tr><td>Deseados Max <?php echo $almacenes[$ka]; ?></td><td><?php echo $s['deseados_max']['anterior']; ?></td><td class="highlight"><?php echo $s['deseados_max']['actual']; ?></td></tr>
									<?php 
								}
							}
						}
						else {
							?>
								<tr><td><?php echo $k; ?></td><td><?php echo $v['anterior']; ?></td><td class="highlight"><?php echo $v['actual']; ?></td></tr>
							<?php
						}
						?>
					<?php	
					}
					?>
                </tbody>
            </table>
        </div>


		<?php
		}
		?>
    </div>
</body>
</html>