<div id="match-schedule"></div>

 <!-- events-->
  <!-- {
    event: 'Serie A',
        matchup: 'Juventus vs Roma',
        date: '2024-09-02',
        time: '01:45',
        team1Image: 'https://api.sofascore.app/api/v1/team/2687/image', // Image for Korea
        team2Image: 'https://api.sofascore.app/api/v1/team/2702/image', // Image for India
        buttons: [
            { text: 'Link', link: 'https://un1t3d3tr3m5x9ztv.blogspot.com/p/v30.html' },
        ]
    }, -->
    
     <!-- events-->

 <link rel="stylesheet" href="./style.css" />
<script>
   
// Data pertandingan disimpan dalam array
const schedules = [
   
   
   
   <!-- events-->
   
  
 
   
   
   
  
   
  
     <!-- events-->
   
   
  {
    event: 'EFL Cup',
        matchup: 'Arsenal vs Crystal Palace',
        date: '2024-12-19',
        time: '02:30',
        team1Image: 'https://img.sofascore.com/api/v1/team/42/image', // Image for Korea
        team2Image: 'https://img.sofascore.com/api/v1/team/7/image', // Image for India
        buttons: [
            { text: 'Link', link: 'https://realraketxn.blogspot.com/p/49.html' },
        ]
    }, 
    
     
   <!-- events-->    
   
   
   
      <!-- events-->
   
   
  {
    event: 'EFL Cup',
        matchup: 'Newcastle vs Brentford',
        date: '2024-12-19',
        time: '02:45',
        team1Image: 'https://img.sofascore.com/api/v1/team/39/image', // Image for Korea
        team2Image: 'https://img.sofascore.com/api/v1/team/50/image', // Image for India
        buttons: [
            { text: 'Link', link: 'https://realraketxn.blogspot.com/p/v27.html' },
        ]
    }, 
    
     
   <!-- events-->    
   
   
   
    
      <!-- events-->
   
   
  {
    event: 'Ligue 1',
        matchup: 'AS Monaco vs PSG',
        date: '2024-12-19',
        time: '03:00',
        team1Image: 'https://img.sofascore.com/api/v1/team/1653/image', // Image for Korea
        team2Image: 'https://img.sofascore.com/api/v1/team/1644/image', // Image for India
        buttons: [
            { text: 'Link', link: 'https://realraketxn.blogspot.com/p/v47.html' },
        ]
    }, 
    
     
   <!-- events-->    
   
   
   
    
   <!-- events-->
   
   
  {
    event: 'EFL Cup',
        matchup: 'Southampton vs Liverpool',
        date: '2024-12-19',
        time: '03:00',
        team1Image: 'https://img.sofascore.com/api/v1/team/45/image', // Image for Korea
        team2Image: 'https://img.sofascore.com/api/v1/team/44/image', // Image for India
        buttons: [
            { text: 'Link', link: 'https://realraketxn.blogspot.com/p/v30.html' },
        ]
    }, 
    
     
   <!-- events-->    
   
   
   
    
   
   
   
   
   
   
  
   
      
      
      
     
    
        
      
  
    // Add more events here
];

// Fungsi untuk mengonversi waktu dan tanggal ke zona waktu lokal
function convertToLocalTime(wibTime, wibDate) {
    var dateWIB = new Date(wibDate + 'T' + wibTime + ':00+07:00');
    var localTime = new Date(dateWIB.toLocaleString('en-US', { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }));
    
    var hours = localTime.getHours().toString().padStart(2, '0');
    var minutes = localTime.getMinutes().toString().padStart(2, '0');
    var formattedTime = hours + ':' + minutes;
    
    var options = { year: 'numeric', month: 'long', day: 'numeric' };
    var formattedDate = localTime.toLocaleDateString('id-ID', options);

    return {
        time: formattedTime,
        date: formattedDate
    };
}

// Fungsi untuk menampilkan jadwal pertandingan
function displaySchedules() {
    const container = document.getElementById('match-schedule');

    schedules.forEach(schedule => {
        const localDateTime = convertToLocalTime(schedule.time, schedule.date);

        // Create the anchor element to wrap the entire matchContainer
        const matchLink = document.createElement('a');
        matchLink.href = schedule.buttons[0].link;  // Use the first button's link
        matchLink.className = 'match-link';

        // Create matchContainer element
        const matchContainer = document.createElement('div');
        matchContainer.className = 'match-container';

        // Add click event to toggle active class
        matchContainer.addEventListener('click', function() {
            // Remove active class from all matchContainers
            document.querySelectorAll('.match-container').forEach(container => container.classList.remove('active'));
            // Add active class to the clicked matchContainer
            this.classList.add('active');
        });

        // Create event header
        const eventHeader = document.createElement('div');
        eventHeader.className = 'event-header';
        eventHeader.innerText = schedule.event;
        matchContainer.appendChild(eventHeader);

        // Create team images
        const teamImages = document.createElement('div');
        teamImages.className = 'team-images';

        const imgTeam1 = document.createElement('img');
        imgTeam1.src = schedule.team1Image;
        imgTeam1.alt = `Team 1 image`;
        imgTeam1.width = 40;  // Set image width to 40
        teamImages.appendChild(imgTeam1);

        const imgTeam2 = document.createElement('img');
        imgTeam2.src = schedule.team2Image;
        imgTeam2.alt = `Team 2 image`;
        imgTeam2.width = 40;  // Set image width to 40
        teamImages.appendChild(imgTeam2);

        matchContainer.appendChild(teamImages);

        // Create matchup element
        const matchup = document.createElement('div');
        matchup.className = 'matchup';
        matchup.innerText = schedule.matchup;
        matchContainer.appendChild(matchup);

        // Create details element
        const details = document.createElement('div');
        details.className = 'details';

        const dateDiv = document.createElement('div');
        dateDiv.className = 'date';
        dateDiv.innerText = localDateTime.date;
        details.appendChild(dateDiv);

        const timeDiv = document.createElement('div');
        timeDiv.className = 'time';
        timeDiv.innerText = localDateTime.time + ' (24 HOURS)';
        details.appendChild(timeDiv);

        matchContainer.appendChild(details);

        // Determine match status (live, upcoming, or expired)
        const now = new Date();
        const eventDateTime = new Date(schedule.date + 'T' + schedule.time + ':00+07:00');

        if (eventDateTime < now) {
            const expiredDiv = document.createElement('div');
            expiredDiv.className = 'status Online';
            expiredDiv.innerText = 'Live Now';
            matchContainer.appendChild(expiredDiv);
        } else if (eventDateTime > now && (eventDateTime - now) <= (60 * 60 * 1000)) {
            const liveIcon = document.createElement('div');
            liveIcon.className = 'live-icon';
            liveIcon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="12"/></svg> Upcoming`;
            matchContainer.appendChild(liveIcon);
        } else {
            const countdownDiv = document.createElement('div');
            countdownDiv.className = 'countdown';
            const hoursLeft = Math.floor((eventDateTime - now) / (1000 * 60 * 60));
            const minutesLeft = Math.floor(((eventDateTime - now) % (1000 * 60 * 60)) / (1000 * 60));
            countdownDiv.innerText = `Upcoming in ${hoursLeft}h ${minutesLeft}m`;
            matchContainer.appendChild(countdownDiv);
        }

        // Append matchContainer to the matchLink anchor
        matchLink.appendChild(matchContainer);

        // Append the matchLink to the container
        container.appendChild(matchLink);
    });
}

displaySchedules();
</script>
</div>
<div class='clear'></div>
</div>
<div style='clear: both;'></div>
