<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Платежи - Админ Панель</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        body {
            background-color: #000;
            color: #00ff00;
            font-family: 'Courier New', monospace;
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }

        .header {
            text-align: center;
            padding: 20px 0;
            margin-bottom: 30px;
            border-bottom: 2px solid #00ff00;
            animation: neonText 3s ease-in-out infinite alternate;
        }

        h1 {
            font-size: 2.5em;
            margin: 0;
            text-shadow: 0 0 10px #00ff00;
        }

        .subtitle {
            color: #00ff88;
            font-size: 1.2em;
            margin-top: 10px;
        }

        .controls {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding: 15px;
            background: rgba(0, 255, 0, 0.05);
            border: 1px solid #00ff00;
            border-radius: 5px;
        }

        .search-box {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        .search-input {
            background: #000;
            border: 1px solid #00ff00;
            color: #00ff00;
            padding: 8px 15px;
            font-family: 'Courier New', monospace;
            border-radius: 3px;
            width: 300px;
        }

        .search-input:focus {
            outline: none;
            box-shadow: 0 0 10px #00ff00;
        }

        .stats {
            display: flex;
            gap: 20px;
            color: #00ff88;
            font-size: 0.9em;
        }

        .stat-item {
            background: rgba(0, 255, 0, 0.1);
            padding: 5px 10px;
            border-radius: 3px;
            border: 1px solid #00ff00;
        }

        .table-container {
            overflow-x: auto;
            margin-bottom: 30px;
            border: 2px solid #00ff00;
            border-radius: 5px;
            background: rgba(0, 255, 0, 0.02);
        }

        .payment-table {
            width: 100%;
            border-collapse: collapse;
            min-width: 1200px;
        }

        .payment-table thead {
            background: rgba(0, 255, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 10;
        }

        .payment-table th {
            padding: 15px;
            text-align: left;
            border: 1px solid #00ff00;
            color: #00ff88;
            font-weight: bold;
            text-transform: uppercase;
            font-size: 0.9em;
            letter-spacing: 1px;
        }

        .payment-table td {
            padding: 12px 15px;
            border: 1px solid #00ff00;
            vertical-align: top;
            transition: all 0.3s ease;
        }

        .payment-table tr:hover td {
            background: rgba(0, 255, 0, 0.1);
            transform: scale(1.01);
        }

        .payment-table tr:nth-child(even) {
            background: rgba(0, 255, 0, 0.03);
        }

        .cell-content {
            min-height: 40px;
            display: flex;
            align-items: center;
            word-break: break-word;
        }

        .id-cell {
            color: #00ffff;
            font-weight: bold;
            text-align: center;
            width: 80px;
        }

        .username-cell {
            color: #ffffff;
            width: 200px;
        }

        .skin-cell {
            color: #ff00ff;
            max-width: 250px;
        }

        .price-cell {
            color: #ffff00;
            text-align: right;
            width: 120px;
            font-weight: bold;
        }

        .merch-cell {
            color: #00ff88;
            width: 150px;
        }

        .address-cell {
            color: #ff8800;
            max-width: 300px;
            font-family: monospace;
            font-size: 0.9em;
        }

        .comment-cell {
            color: #88ff00;
            max-width: 300px;
            background: rgba(0, 255, 0, 0.05);
        }

        .actions-cell {
            width: 100px;
            text-align: center;
        }

        .action-btn {
            background: transparent;
            border: 1px solid #00ff00;
            color: #00ff00;
            padding: 5px 10px;
            margin: 2px;
            cursor: pointer;
            border-radius: 3px;
            transition: all 0.3s ease;
            font-size: 0.8em;
        }

        .action-btn:hover {
            background: #00ff00;
            color: #000;
            transform: scale(1.1);
        }

        .action-btn.delete {
            border-color: #ff0000;
            color: #ff0000;
        }

        .action-btn.delete:hover {
            background: #ff0000;
            color: #000;
        }

        .copy-btn {
            background: transparent;
            border: 1px solid #00ffff;
            color: #00ffff;
            padding: 3px 8px;
            margin-left: 5px;
            cursor: pointer;
            border-radius: 3px;
            font-size: 0.8em;
            transition: all 0.3s ease;
        }

        .copy-btn:hover {
            background: #00ffff;
            color: #000;
        }

        .no-data {
            text-align: center;
            padding: 50px;
            color: #ff5555;
            font-size: 1.2em;
        }

        .pagination {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-top: 20px;
        }

        .page-btn {
            background: rgba(0, 255, 0, 0.1);
            border: 1px solid #00ff00;
            color: #00ff00;
            padding: 8px 15px;
            cursor: pointer;
            border-radius: 3px;
            transition: all 0.3s ease;
        }

        .page-btn:hover {
            background: #00ff00;
            color: #000;
        }

        .page-btn.active {
            background: #00ff00;
            color: #000;
            font-weight: bold;
        }

        .footer {
            text-align: center;
            padding: 20px;
            margin-top: 30px;
            border-top: 1px solid #00ff00;
            color: #00ff88;
            font-size: 0.9em;
        }

        .back-link {
            display: inline-block;
            background: #000;
            border: 2px solid #00ff00;
            color: #00ff00;
            padding: 10px 20px;
            text-decoration: none;
            margin: 20px;
            border-radius: 5px;
            transition: all 0.3s ease;
        }

        .back-link:hover {
            background: #00ff00;
            color: #000;
            transform: scale(1.05);
        }

        @keyframes neonText {
            0% {
                text-shadow: 0 0 5px #00ffff, 0 0 10px #00ffff, 0 0 15px #00ffff, 0 0 20px #00ff7f;
            }
            50% {
                text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff, 0 0 30px #00ffff, 0 0 40px #00ff7f;
            }
            100% {
                text-shadow: 0 0 5px #00ffff, 0 0 10px #00ffff, 0 0 15px #00ffff, 0 0 20px #00ff7f;
            }
        }

        @keyframes glow {
            0% {
                box-shadow: 0 0 5px #00ff00;
            }
            100% {
                box-shadow: 0 0 20px #00ff00;
            }
        }

        .highlight {
            background: rgba(255, 255, 0, 0.3) !important;
            animation: glow 0.5s ease-in-out;
        }

        .total-amount {
            background: rgba(0, 255, 0, 0.1);
            padding: 15px;
            border: 1px solid #00ff00;
            border-radius: 5px;
            margin-bottom: 20px;
            text-align: center;
            font-size: 1.2em;
        }

        .total-amount strong {
            color: #ffff00;
            font-size: 1.5em;
        }

        @media (max-width: 768px) {
            .controls {
                flex-direction: column;
                gap: 15px;
            }

            .search-input {
                width: 100%;
            }

            .stats {
                width: 100%;
                justify-content: space-between;
            }
        }
    </style>
</head>
<body>
<div class="header">
    <h1><i class="fas fa-database"></i> ПЛАТЕЖИ - БАЗА ДАННЫХ</h1>
</div>

<a href="/admin/token/dkjjsdkjfhsdkcDKHnfcsiuyHWydhjdfhsouUyqe/glav" class="back-link">
    <i class="fas fa-arrow-left"></i> Назад в админ-панель
</a>



<!-- Таблица -->
<div class="table-container">
    <table class="payment-table" id="paymentsTable">
        <thead>
        <tr>
            <th>ID</th>
            <th>Пользователь</th>
            <th>Скин</th>
            <th>Сумма ($)</th>
            <th>Товар</th>
            <th>Адрес платежа</th>
            <th>Комментарий</th>
        </tr>
        </thead>
        <tbody>
        <tr th:if="${posts == null or #lists.isEmpty(posts)}">
            <td colspan="8" class="no-data">
                <i class="fas fa-exclamation-triangle"></i> Нет данных для отображения
            </td>
        </tr>

        <tr th:each="payment, stat : ${posts}" th:data-index="${stat.index}"
            th:id="'row-' + ${payment.id}">
            <td class="id-cell">
                <div class="cell-content">
                    <span th:text="${payment.id}">1</span>
                    <button onclick="copyToClipboard(this)" class="copy-btn"
                            th:data-text="${payment.id}" title="Копировать ID">
                        <i class="far fa-copy"></i>
                    </button>
                </div>
            </td>

            <td class="username-cell">
                <div class="cell-content">
                    <i class="fas fa-user" style="margin-right: 8px; color: #00ffff;"></i>
                    <span th:text="${payment.username}">Username</span>
                </div>
            </td>

            <td class="skin-cell">
                <div class="cell-content">
                    <i class="fas fa-image" style="margin-right: 8px; color: #ff00ff;"></i>
                    <span th:text="${payment.userskin}"
                          th:title="${payment.userskin}">
                                Skin name
                            </span>
                </div>
            </td>

            <td class="price-cell">
                <div class="cell-content">
                    <span th:text="${payment.cena} + '$'">0$</span>
                </div>
            </td>

            <td class="merch-cell">
                <div class="cell-content">
                    <i class="fas fa-shopping-cart" style="margin-right: 8px; color: #00ff88;"></i>
                    <span th:text="${payment.merch}">Merch</span>
                </div>
            </td>

            <td class="address-cell">
                <div class="cell-content">
                    <i class="fas fa-wallet" style="margin-right: 8px; color: #ff8800;"></i>
                    <span th:text="${payment.adressmoney}"
                          th:title="${payment.adressmoney}"
                          style="font-family: monospace; font-size: 0.9em;">
                                Address
                            </span>
                    <button onclick="copyToClipboard(this)" class="copy-btn"
                            th:data-text="${payment.adressmoney}" title="Копировать адрес">
                        <i class="far fa-copy"></i>
                    </button>
                </div>
            </td>

            <td class="comment-cell">
                <div class="cell-content">
                    <i class="fas fa-comment" style="margin-right: 8px; color: #88ff00;"></i>
                    <span th:text="${payment.comment}"
                          th:title="${payment.comment}"
                          style="max-width: 250px;">
                                Comment
                            </span>
                    <button onclick="copyToClipboard(this)" class="copy-btn"
                            th:data-text="${payment.comment}" title="Копировать комментарий">
                        <i class="far fa-copy"></i>
                    </button>
                </div>
            </td>

        </tr>
        </tbody>
    </table>
</div>

<!-- Пагинация -->
<div class="pagination" id="pagination">
    <!-- Пагинация будет генерироваться JavaScript -->
</div>


<script>
    // Поиск в таблице
    function searchTable() {
        const searchText = document.getElementById('searchInput').value.toLowerCase();
        const rows = document.querySelectorAll('#paymentsTable tbody tr');
        let visibleCount = 0;

        rows.forEach(row => {
            if (row.cells.length > 1) { // Пропускаем строку "нет данных"
                const rowText = row.textContent.toLowerCase();
                if (rowText.includes(searchText)) {
                    row.style.display = '';
                    visibleCount++;
                    // Подсветка найденного текста
                    if (searchText) {
                        highlightText(row, searchText);
                    }
                } else {
                    row.style.display = 'none';
                }
            }
        });

        document.getElementById('visibleCount').innerHTML =
            `<i class="fas fa-eye"></i> Показано: ${visibleCount}`;
    }

    function highlightText(element, searchText) {
        const walker = document.createTreeWalker(
            element,
            NodeFilter.SHOW_TEXT,
            null,
            false
        );

        let node;
        while (node = walker.nextNode()) {
            if (node.textContent.toLowerCase().includes(searchText)) {
                const span = document.createElement('span');
                span.className = 'highlight';
                span.textContent = node.textContent;
                node.parentNode.replaceChild(span, node);
            }
        }
    }

    function clearSearch() {
        document.getElementById('searchInput').value = '';
        searchTable();
    }

    // Копирование в буфер обмена
    function copyToClipboard(button) {
        const text = button.getAttribute('data-text');
        navigator.clipboard.writeText(text).then(() => {
            const originalHTML = button.innerHTML;
            button.innerHTML = '<i class="fas fa-check"></i>';
            button.style.background = '#00ff00';
            button.style.color = '#000';

            setTimeout(() => {
                button.innerHTML = originalHTML;
                button.style.background = '';
                button.style.color = '';
            }, 1000);
        }).catch(err => {
            console.error('Ошибка копирования:', err);
            alert('Не удалось скопировать');
        });
    }

    // Действия с платежами
    function editPayment(button) {
        const paymentId = button.getAttribute('data-id');
        alert('Редактирование платежа ID: ' + paymentId);
        // Здесь должен быть AJAX запрос или переход на страницу редактирования
    }

    function deletePayment(button) {
        const paymentId = button.getAttribute('data-id');
        if (confirm('Вы уверены, что хотите удалить платеж ID: ' + paymentId + '?')) {
            // Здесь должен быть AJAX запрос на удаление
            const row = document.getElementById('row-' + paymentId);
            if (row) {
                row.style.animation = 'glow 0.5s';
                setTimeout(() => row.remove(), 500);
                updateStats();
            }
        }
    }

    function viewDetails(button) {
        const paymentId = button.getAttribute('data-id');
        const row = document.getElementById('row-' + paymentId);
        if (row) {
            alert('Детали платежа ID: ' + paymentId +
                  '\nПользователь: ' + row.cells[1].textContent +
                  '\nСумма: ' + row.cells[3].textContent +
                  '\nТовар: ' + row.cells[4].textContent);
        }
    }

    function updateStats() {
        const visibleRows = document.querySelectorAll('#paymentsTable tbody tr[style!="display: none;"]');
        const totalRows = document.querySelectorAll('#paymentsTable tbody tr').length - 1; // Минус строка "нет данных"

        document.getElementById('visibleCount').innerHTML =
            `<i class="fas fa-eye"></i> Показано: ${visibleRows.length}`;
        document.getElementById('totalCount').textContent = totalRows;

        // Пересчитываем общую сумму
        let totalAmount = 0;
        visibleRows.forEach(row => {
            if (row.cells.length > 1) {
                const amountText = row.cells[3].textContent;
                const amount = parseFloat(amountText.replace('$', '')) || 0;
                totalAmount += amount;
            }
        });

        const totalElement = document.querySelector('.total-amount strong');
        if (totalElement) {
            totalElement.textContent = totalAmount.toFixed(2) + '$';
        }
    }

    // Инициализация пагинации
    function initPagination() {
        const rowsPerPage = 20;
        const rows = document.querySelectorAll('#paymentsTable tbody tr');
        const totalPages = Math.ceil(rows.length / rowsPerPage);

        if (totalPages > 1) {
            const paginationDiv = document.getElementById('pagination');
            paginationDiv.innerHTML = '';

            for (let i = 1; i <= totalPages; i++) {
                const btn = document.createElement('button');
                btn.className = 'page-btn';
                btn.textContent = i;
                btn.onclick = () => showPage(i, rowsPerPage);
                paginationDiv.appendChild(btn);
            }

            showPage(1, rowsPerPage);
        }
    }

    function showPage(pageNum, rowsPerPage) {
        const rows = document.querySelectorAll('#paymentsTable tbody tr');
        const start = (pageNum - 1) * rowsPerPage;
        const end = start + rowsPerPage;

        rows.forEach((row, index) => {
            if (index >= start && index < end) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        });

        // Обновляем активную кнопку
        document.querySelectorAll('.page-btn').forEach(btn => {
            btn.classList.remove('active');
        });
        document.querySelectorAll('.page-btn')[pageNum - 1]?.classList.add('active');

        updateStats();
    }

    // Автоматическое обновление каждые 30 секунд
    function autoRefresh() {
        setTimeout(() => {
            if (confirm('Обновить данные?')) {
                location.reload();
            } else {
                autoRefresh();
            }
        }, 30000);
    }

    // Инициализация при загрузке
    document.addEventListener('DOMContentLoaded', function() {
        initPagination();
        updateStats();
        autoRefresh();

        // Поиск при нажатии Enter
        document.getElementById('searchInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                searchTable();
            }
        });
    });
</script>
</body>
</html>