<article class="post" style="text-align: center;">
    <div id="loading-container">
        <div class="loading-text" style="font-size: 15px; font-weight: bold; line-height: 1.3;">
            Loading, please wait<span id="loading-dots">....</span>
        </div>
    </div>
    <div id="matches-container" style="display: none;" class="matches-grid"></div>

    <style>
        /* Grid styles */
        .matches-grid {
            display: grid;
            gap: 30px;
        }

        /* Mobile: 1 column */
        @media (max-width: 768px) {
            .matches-grid {
                grid-template-columns: 1fr;
                gap: 10px;
            }
        }

        /* Desktop: 2 columns */
        @media (min-width: 769px) {
            .matches-grid {
                grid-template-columns: 1fr 1fr;
            }
        }

        .match-event {
            border: 1px solid #ccc;
            border-radius: 8px;
            padding: 10px;
            text-align: center;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

           .live-icon {
            position: absolute;
            top: 8px;
            left: 8px;
            max-width: 8%;
            height: auto;
        }
    </style>

    <script>
        // Loading animation: add dots after the word 'Loading'
        let loadingDots = document.getElementById("loading-dots");
        let dotCount = 0;
        const loadingInterval = setInterval(() => {
            dotCount = (dotCount + 1) % 4; // Cycle between 0, 1, 2, 3 dots
            loadingDots.textContent = '.'.repeat(dotCount);
        }, 500);

        // Fetch the JSON data and display the matches
        fetch('https://1452proxy.nfsfree.workers.dev/?quest=https://hd.la2zo.eu.org/agenda.json')
            .then(response => response.json())
            .then(matches => {
                clearInterval(loadingInterval); // Stop the loading animation
                document.getElementById("loading-container").style.display = 'none'; // Hide the loading text
                const container = document.getElementById('matches-container');
                container.style.display = 'grid'; // Show the match container

                matches.forEach(match => {
                    const matchElement = `
                    <div class="match-event">
                    <img class="live-icon" src="${match.live}" />
                        <a href='https://gn.nobar.eu.org/CLICK' onclick='javascript:window.open(&quot;${match.link}&quot;)' target='_self'>
                            <div id="overlay-match">
                                <div id="watch-match"></div>
                            </div>
                        </a>
                        <div class="left-team">
                            <div class="team-logo">
                                <img height="60" src="${match.left_team_logo}" width="60" />
                            </div>
                        </div>
                        <div class="match-time">
                            <div class="match-timing">
                                <div id="result-now" style="font-size: 12px; font-weight: bold; line-height: 1.3;">
                                    ${match.league}
                                </div>
                                ${match.teams}
                                <div id="result-now" style="font-size: 12px; font-weight: bold; line-height: 1.3;">
                                    ${match.time}
                                </div>
                            </div>
                        </div>
                        <div class="first-team">
                            <div class="team-logo">
                                <img height="60" src="${match.right_team_logo}" width="60" />
                            </div>
                        </div>
                    </div>`;
                    container.innerHTML += matchElement;
                });
            })
            .catch(error => {
                clearInterval(loadingInterval); // Stop the loading animation
                document.getElementById("loading-container").innerHTML = `<div style="font-size: 15px; color: red;">Error data. Please reload site.</div>`;
                console.error('Error fetching match data:', error);
            });
    </script>
</article>