<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>{{ device_name }} Logları - iAccess Mobile</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #667eea;
            --secondary-color: #764ba2;
            --success-color: #28a745;
            --danger-color: #dc3545;
            --warning-color: #ffc107;
            --info-color: #17a2b8;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            overflow-x: hidden;
        }

        .mobile-header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            padding: 15px 20px;
            box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .device-info h5 {
            color: var(--primary-color);
            font-weight: 700;
            margin: 0;
            font-size: 1.1rem;
        }

        .device-info small {
            color: #666;
            font-size: 0.8rem;
        }

        .back-btn {
            background: linear-gradient(135deg, var(--info-color), #138496);
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 10px;
            font-size: 0.9rem;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-flex;
            align-items: center;
            gap: 5px;
        }

        .back-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(23, 162, 184, 0.4);
            color: white;
            text-decoration: none;
        }

        .logs-container {
            padding: 20px;
            min-height: calc(100vh - 80px);
        }

        .logs-list {
            max-width: 500px;
            margin: 0 auto;
        }

        .log-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            transition: all 0.3s ease;
        }

        .log-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
        }

        .log-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .log-id {
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            color: white;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 600;
        }

        .log-time {
            color: #666;
            font-size: 0.85rem;
            font-family: monospace;
        }

        .log-details {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-bottom: 15px;
        }

        .log-detail {
            background: rgba(108, 117, 125, 0.1);
            border-radius: 8px;
            padding: 10px;
        }

        .detail-label {
            color: #666;
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
            margin-bottom: 5px;
        }

        .detail-value {
            color: #333;
            font-size: 0.9rem;
            font-weight: 500;
        }

        .access-status {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 12px;
            border-radius: 10px;
            font-size: 0.85rem;
            font-weight: 600;
        }

        .status-granted {
            background: rgba(40, 167, 69, 0.1);
            color: var(--success-color);
        }

        .status-denied {
            background: rgba(220, 53, 69, 0.1);
            color: var(--danger-color);
        }

        .access-type-badge {
            background: linear-gradient(135deg, var(--info-color), #138496);
            color: white;
            padding: 4px 8px;
            border-radius: 6px;
            font-size: 0.75rem;
            font-weight: 600;
            text-transform: uppercase;
        }

        .no-logs {
            text-align: center;
            color: rgba(255, 255, 255, 0.8);
            padding: 60px 20px;
        }

        .no-logs i {
            font-size: 4rem;
            margin-bottom: 20px;
            opacity: 0.5;
        }

        .refresh-btn {
            position: fixed;
            bottom: 30px;
            right: 30px;
            background: linear-gradient(135deg, var(--success-color), #20c997);
            color: white;
            border: none;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            font-size: 1.5rem;
            box-shadow: 0 5px 20px rgba(40, 167, 69, 0.4);
            transition: all 0.3s ease;
            z-index: 50;
        }

        .refresh-btn:hover {
            transform: scale(1.1);
            box-shadow: 0 8px 25px rgba(40, 167, 69, 0.6);
        }

        .refresh-btn.spinning {
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* Touch feedback */
        .log-card.touching {
            transform: scale(0.98);
        }

        @media (min-width: 768px) {
            .logs-list {
                max-width: 700px;
            }
            
            .log-details {
                grid-template-columns: repeat(3, 1fr);
            }
        }

        @media (min-width: 1200px) {
            .logs-list {
                max-width: 900px;
            }
            
            .log-details {
                grid-template-columns: repeat(4, 1fr);
            }
        }
    </style>
</head>
<body>
    <!-- Header -->
    <div class="mobile-header">
        <div class="header-content">
            <div class="device-info">
                <h5>{{ device_name }}</h5>
                <small><i class="fas fa-history me-1"></i>Erişim Logları</small>
            </div>
            <a href="{{ url_for('mobile_dashboard') }}" class="back-btn">
                <i class="fas fa-arrow-left"></i>Geri
            </a>
        </div>
    </div>

    <!-- Logs Container -->
    <div class="logs-container">
        {% if logs and logs|length > 0 %}
            <div class="logs-list">
                {% for log in logs %}
                <div class="log-card">
                    <div class="log-header">
                        <div class="log-id">#{{ log.id }}</div>
                        <div class="log-time">{{ log.timestamp }}</div>
                    </div>

                    <div class="log-details">
                        <div class="log-detail">
                            <div class="detail-label">Kullanıcı</div>
                            <div class="detail-value">{{ log.user_name or 'Bilinmeyen' }}</div>
                        </div>
                        
                        <div class="log-detail">
                            <div class="detail-label">Kart UUID</div>
                            <div class="detail-value">{{ log.card_uuid or 'N/A' }}</div>
                        </div>
                        
                        <div class="log-detail">
                            <div class="detail-label">Erişim Türü</div>
                            <div class="detail-value">
                                <span class="access-type-badge">
                                    {% if log.access_type == 1 %}NFC
                                    {% elif log.access_type == 2 %}BUTTON
                                    {% elif log.access_type == 3 %}TCP SERVER
                                    {% elif log.access_type == 4 %}TCP CLIENT
                                    {% elif log.access_type == 5 %}BLE
                                    {% else %}UNKNOWN
                                    {% endif %}
                                </span>
                            </div>
                        </div>
                        
                        <div class="log-detail">
                            <div class="detail-label">Terminal</div>
                            <div class="detail-value">{{ log.terminal_mode or '0' }}</div>
                        </div>
                    </div>

                    <div class="access-status {{ 'status-granted' if log.is_granted else 'status-denied' }}">
                        <i class="fas {{ 'fa-check-circle' if log.is_granted else 'fa-times-circle' }}"></i>
                        {{ 'Erişim Verildi' if log.is_granted else 'Erişim Reddedildi' }}
                    </div>
                </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="no-logs">
                <i class="fas fa-clipboard-list"></i>
                <h5>Henüz Log Yok</h5>
                <p>Bu cihaz için henüz erişim logu bulunmuyor.</p>
            </div>
        {% endif %}
    </div>

    <!-- Refresh Button -->
    <button class="refresh-btn" onclick="refreshLogs()" id="refreshBtn">
        <i class="fas fa-sync-alt"></i>
    </button>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // Touch feedback for log cards
        document.querySelectorAll('.log-card').forEach(card => {
            card.addEventListener('touchstart', function() {
                this.classList.add('touching');
            });
            
            card.addEventListener('touchend', function() {
                this.classList.remove('touching');
            });
        });

        // Refresh logs function
        function refreshLogs() {
            const refreshBtn = document.getElementById('refreshBtn');
            refreshBtn.classList.add('spinning');
            
            // Reload the page to get fresh logs
            setTimeout(() => {
                location.reload();
            }, 500);
        }

        // Auto refresh every 60 seconds
        setInterval(refreshLogs, 60000);

        // Prevent zoom on double tap
        let lastTouchEnd = 0;
        document.addEventListener('touchend', function (event) {
            const now = (new Date()).getTime();
            if (now - lastTouchEnd <= 300) {
                event.preventDefault();
            }
            lastTouchEnd = now;
        }, false);

        // Show toast notification if page was refreshed
        if (performance.navigation.type === performance.navigation.TYPE_RELOAD) {
            const toast = document.createElement('div');
            toast.className = 'position-fixed top-0 start-50 translate-middle-x mt-3 alert alert-info';
            toast.style.zIndex = '10000';
            toast.innerHTML = '<i class="fas fa-sync-alt me-2"></i>Loglar yenilendi';
            
            document.body.appendChild(toast);
            
            setTimeout(() => {
                toast.remove();
            }, 2000);
        }
    </script>
</body>
</html> 