<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>JDB Games</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            overflow-x: hidden;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
        header {
            background-color: #333;
            color: #fff;
            padding: 10px;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
        }
        .categories {
            background-color: #fff;
            display: flex;
            justify-content: space-around;
            padding: 10px 0;
            position: sticky;
            top: 0;
            z-index: 1000;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            overflow-x: auto;
            white-space: nowrap;
        }
        .category-button {
            padding: 10px 20px;
            border-radius: 20px;
            background-color: #f5f5f5;
            font-size: 14px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.3s ease, transform 0.3s ease;
            flex-shrink: 0;
        }
        .category-button:hover {
            background-color: #ddd;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }
        .category-button.active {
            background-color: #333;
            color: #fff;
        }
        .game-container {
            display: flex;
            flex-wrap: wrap;
            gap: 15px;
            padding: 15px;
            justify-content: center;
        }
        .game-item {
            flex: 1 1 calc(33.333% - 15px); /* 3 items per row with gap */
            box-sizing: border-box;
            text-align: center;
            max-width: calc(33.333% - 15px);
        }
        .game-link {
            display: block;
            text-decoration: none;
            color: #000;
        }
        .game-image {
            width: 100px;
            height: 100px;
            object-fit: cover;
        }
    </style>
</head>
<body>
    <header>
        JDB Games
    </header>
    <div class="categories">
        <div class="category-button active" data-category="all">All</div>
        <div class="category-button" data-category="slots">Slots</div>
        <div class="category-button" data-category="spribe">Spribe</div>
        <div class="category-button" onclick="window.location.href='/table'">Casino</div>
    </div> 
    <div class="category-button fishing" onclick="window.location.href='/fishing'">
    Fishing
</div>
<div class="category-button slots" onclick="window.location.href='/slots'">
    Slots
</div>
    <div class="game-container" id="game-container">
        <!-- Game items will be dynamically inserted here -->
    </div>
    <script>
        const userInfoTypes = {
            phoneNumber: "phone_user",
        };

        const mTypes = {
            slots: {
                gType0: [
                    '14092', '14091', '14090', '14089', '14088', '14087', '14086', '14085', '14084', '14083', 
                    '14082', '14081', '14080', '14079', '14077', '14075', '14070', '14068', '14067', '14065', 
                    '14064', '14063', '14061', '14060', '14059', '14058', '14055', '14054', '14053', '14052', 
                    '14051', '14050', '14048', '14047', '14046', '14045', '14044', '14043', '14042', '14041', 
                    '14040', '14039', '14038', '14036', '14035', '14034', '14033', '14030', '14029', '14027', 
                    '14025', '14022', '14021', '14018', '14016', '14012', '14010', '14008', '14007', '14006', 
                    '14005', '14003', '8001', '15012', '15010', '15005', '15002', '15001', '8051', '8050', '8049', '8048', '8047', '8046', '8044', '8035', '8028', '8023', '8022', '8021', '8020', '8019', '8018', '8017', '8015', '8014', '8007', '8006', '8005', '8004', '8003', '8002'
                ],
                gType32: [
                    '32059', '32058', '32057', '32056', '32055', '32054', '32053', '32051', '32050', '32049',
                    '32047', '32048', '32045', '32043', '32042', '32041', '32040', '32039', '32038', '32037',
                    '32036', '32034', '32032', '32031', '32030', '32029', '32028', '32027', '32026', '32024',
                    '32023', '32022', '32021', '32020', '32019', '32018', '32017', '32016'
                ]
            },
            spribe: {
                gType22: [
                    '22009', '22008', '22007', '22006', '22005', '22004', '22003', '22002', '22001'
                ]
            },
            casino: [
                '18030', '18029', '18028', '18027', '18026', '18025', '18024', '18023', '18022', '18021',
                '18020', '18013', '18005', '18004', '18002', '18001'
            ]
        };

        let phoneNumber = '';

        const fetchUser = async () => {
            try {
                const response = await fetch('/api/webapi/GetUserInfo');
                const data = await response.json();
                if (!data || !data.data) throw new Error("User data not found!");

                phoneNumber = encodeURIComponent(data.data[userInfoTypes.phoneNumber]);

                displayGames('all'); // Initially display all games
            } catch (error) {
                console.error('Error fetching user data:', error);
            }
        };

        const displayGames = (category) => {
            const container = document.getElementById('game-container');
            container.innerHTML = '';
            let gamesToDisplay = [];

            if (category === 'all') {
                gamesToDisplay = [
                    ...mTypes.slots.gType0.map(mType => ({ mType, gType: 0 })),
                    ...mTypes.slots.gType32.map(mType => ({ mType, gType: 32 })),
                    ...mTypes.spribe.gType22.map(mType => ({ mType, gType: 22 })),
                    ...mTypes.casino.map(mType => ({ mType, gType: 18 })),
                ];
            } else if (category === 'slots') {
                gamesToDisplay = [
                    ...mTypes.slots.gType0.map(mType => ({ mType, gType: 0 })),
                    ...mTypes.slots.gType32.map(mType => ({ mType, gType: 32 }))
                ];
            } else if (category === 'spribe') {
                gamesToDisplay = mTypes.spribe.gType22.map(mType => ({ mType, gType: 22 }));
            } else if (category === 'casino') {
                gamesToDisplay = mTypes.casino.map(mType => ({ mType, gType: 18 }));
            }

            gamesToDisplay.forEach(game => {
                const gameUrl = `https://jdbmain.imitator-host.site/jdb/post?iv=05bae19880a21dd1&key=3467d9770b6bdd41&uid=${phoneNumber}&serverUrl=https://jdb.86lottery.xyz&parent=imitator&gType=${game.gType}&mType=${game.mType}`;
                const imageUrl = `https://fluxapis.live/jdbimages/${game.mType}.png`;

                const gameItem = document.createElement('div');
                gameItem.className = 'game-item';

                const img = new Image();
                img.src = imageUrl;
                img.className = 'game-image';
                img.onerror = () => {
                    img.src = 'https://via.placeholder.com/100x100';
                };

                const gameLink = document.createElement('a');
                gameLink.href = gameUrl;
                gameLink.className = 'game-link';
                gameLink.appendChild(img);

                gameItem.appendChild(gameLink);
                container.appendChild(gameItem);
            });
            
            
        };


        document.querySelectorAll('.category-button').forEach(button => {
            button.addEventListener('click', function() {
                document.querySelectorAll('.category-button').forEach(btn => btn.classList.remove('active'));
                this.classList.add('active');
                const category = this.getAttribute('data-category');
                displayGames(category);
            });
        });

        fetchUser();
    </script>
</body>
</html>