<?php
/**
 * NEPHRO ERP - SYSTEM AUDIT LOGS (v1.0)
 */
global $pdo;
$loglar = $pdo->query("SELECT sl.*, k.ad_soyad FROM sistem_loglari sl 
                       LEFT JOIN kullanicilar k ON sl.kullanici_id = k.id 
                       ORDER BY sl.islem_tarihi DESC LIMIT 100")->fetchAll(PDO::FETCH_ASSOC);
?>

<div style="max-width:1200px; margin:20px auto; padding:20px;">
    <h2 style="font-weight:900; color:#0f172a; margin-bottom:25px;"><i class="fas fa-fingerprint" style="color:#4361ee"></i> Sistem Denetim İzleri</h2>
    
    <div style="background:white; border-radius:25px; border:1px solid #e2e8f0; overflow:hidden; box-shadow:0 10px 15px -3px rgba(0,0,0,0.05);">
        <table style="width:100%; border-collapse:collapse; text-align:left;">
            <thead style="background:#f8fafc; border-bottom:1px solid #e2e8f0;">
                <tr>
                    <th style="padding:20px; font-size:12px; font-weight:800; color:#64748b;">TARİH</th>
                    <th style="padding:20px; font-size:12px; font-weight:800; color:#64748b;">PERSONEL</th>
                    <th style="padding:20px; font-size:12px; font-weight:800; color:#64748b;">İŞLEM</th>
                    <th style="padding:20px; font-size:12px; font-weight:800; color:#64748b;">DETAY</th>
                    <th style="padding:20px; font-size:12px; font-weight:800; color:#64748b;">IP ADRESİ</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach($loglar as $l): 
                    $renk = match($l['islem_tipi']) {
                        'Silme' => '#ef4444',
                        'Ekleme' => '#10b981',
                        'Güncelleme' => '#f59e0b',
                        'Giriş' => '#4361ee',
                        default => '#64748b'
                    };
                ?>
                <tr style="border-bottom:1px solid #f1f5f9;">
                    <td style="padding:15px 20px; font-size:13px; color:#0f172a; font-weight:600;"><?= date('d.m.Y H:i', strtotime($l['islem_tarihi'])) ?></td>
                    <td style="padding:15px 20px; font-size:13px; font-weight:700;"><?= h($l['ad_soyad'] ?: 'Sistem') ?></td>
                    <td style="padding:15px 20px;"><span style="background:<?= $renk ?>20; color:<?= $renk ?>; padding:5px 12px; border-radius:10px; font-size:11px; font-weight:800;"><?= $l['islem_tipi'] ?></span></td>
                    <td style="padding:15px 20px; font-size:13px; color:#475569;"><?= h($l['islem_detay']) ?></td>
                    <td style="padding:15px 20px; font-family:monospace; font-size:12px; color:#94a3b8;"><?= $l['ip_adresi'] ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>