<?php
$matchesPath = __DIR__ . '/matches.json';
$apiPath = __DIR__ . '/api.json';

$matchesData = json_decode(file_get_contents($matchesPath), true);
$apiData = json_decode(file_get_contents($apiPath), true);

$matchList = $matchesData['matches'] ?? [];
$featuredList = $apiData['matches'] ?? [];
$featuredMatch = $featuredList[0] ?? [
    'title' => 'Manchester City vs Arsenal',
    'subtitle' => 'Live Streaming - Multi Server',
    'image' => 'https://images.unsplash.com/photo-1547347298-4074fc3086f0?auto=format&fit=crop&w=1200&q=80',
    'streams' => []
];
$streamList = $featuredMatch['streams'] ?? [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SOHO TV | Live Sports & Entertainment</title>
    <meta name="description" content="SOHO TV — live football, streaming channels, and premium entertainment.">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/style.css">
</head>
<body>
    <div class="page-shell">
        <header class="topbar">
            <div class="container nav-wrap">
                <div class="brand">
                    <div class="brand-mark">S</div>
                    <div>
                        <div class="brand-name">SOHO TV</div>
                        <small>Live & Premium</small>
                    </div>
                </div>

                <nav class="main-nav">
                    <a href="#home">Home</a>
                    <a href="#live">Live</a>
                    <a href="#matches">Matches</a>
                    <a href="#channels">Channels</a>
                    <a href="#news">News</a>
                </nav>

                <div class="nav-actions">
                    <button class="ghost-btn">Log in</button>
                    <button class="primary-btn">Watch Live</button>
                </div>
            </div>
        </header>

        <main id="home">
            <section class="hero">
                <div class="container hero-grid">
                    <div class="hero-copy">
                        <span class="eyebrow">LIVE NOW</span>
                        <h1>Watch the biggest football action in crystal clear HD.</h1>
                        <p>
                            Stream live matches, explore premium channels, and enjoy a sleek entertainment experience built for fans.
                        </p>

                        <div class="hero-actions">
                            <a href="#live" class="primary-btn">Start Watching</a>
                            <a href="#matches" class="ghost-btn light">Browse Matches</a>
                        </div>

                        <div class="stats-row">
                            <div>
                                <strong>250K+</strong>
                                <span>Daily viewers</span>
                            </div>
                            <div>
                                <strong>18</strong>
                                <span>Live channels</span>
                            </div>
                            <div>
                                <strong>4K</strong>
                                <span>Streaming quality</span>
                            </div>
                        </div>
                    </div>

                    <div class="hero-feature" id="live">
                        <div class="feature-image" style="background-image: url('<?php echo htmlspecialchars($featuredMatch['image'] ?? 'https://images.unsplash.com/photo-1547347298-4074fc3086f0?auto=format&fit=crop&w=1200&q=80'); ?>');"></div>
                        <div class="feature-content">
                            <div class="live-pill">LIVE</div>
                            <h2><?php echo htmlspecialchars($featuredMatch['title'] ?? 'Manchester City vs Arsenal'); ?></h2>
                            <p><?php echo htmlspecialchars($featuredMatch['subtitle'] ?? 'Live Streaming - Multi Server'); ?></p>

                            <div class="player-links">
                                <?php if (!empty($streamList)): ?>
                                    <?php foreach (array_slice($streamList, 0, 3) as $stream): ?>
                                        <a href="player.php?token=demo" class="stream-link">
                                            <?php echo htmlspecialchars($stream['name'] ?? 'Stream'); ?>
                                        </a>
                                    <?php endforeach; ?>
                                <?php else: ?>
                                    <a href="player.php?token=demo" class="stream-link">Server 1</a>
                                    <a href="player.php?token=demo" class="stream-link">Server 2</a>
                                    <a href="player.php?token=demo" class="stream-link">Server 3</a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <section class="showcase container" id="matches">
                <div class="section-head">
                    <div>
                        <span class="eyebrow light">Top fixtures</span>
                        <h3>Live and upcoming matches</h3>
                    </div>
                    <a href="#" class="inline-link">View all</a>
                </div>

                <div class="match-grid">
                    <?php foreach (array_slice($matchList, 0, 6) as $match): ?>
                        <article class="match-card">
                            <div class="match-topline">
                                <span class="league"><?php echo htmlspecialchars($match['league'] ?? 'Football'); ?></span>
                                <span class="status"><?php echo htmlspecialchars($match['status'] ?? 'Live'); ?></span>
                            </div>
                            <div class="teams">
                                <div class="team"><span class="dot red"></span> <?php echo htmlspecialchars($match['team1'] ?? 'Team A'); ?></div>
                                <strong>VS</strong>
                                <div class="team"><span class="dot blue"></span> <?php echo htmlspecialchars($match['team2'] ?? 'Team B'); ?></div>
                            </div>
                            <div class="match-meta">
                                <span><?php echo htmlspecialchars($match['time'] ?? 'LIVE'); ?></span>
                                <span><?php echo htmlspecialchars($match['sport'] ?? 'football'); ?></span>
                            </div>
                            <button class="watch-btn">Watch now</button>
                        </article>
                    <?php endforeach; ?>
                </div>
            </section>

            <section class="channel-section container" id="channels">
                <div class="section-head">
                    <div>
                        <span class="eyebrow light">Channels</span>
                        <h3>Most watched networks</h3>
                    </div>
                </div>

                <div class="channel-grid">
                    <article class="channel-card">
                        <div class="channel-badge premium">Premium</div>
                        <h4>Sky Sports HD</h4>
                        <p>Premier League, Champions League, and live football coverage.</p>
                        <a href="player.php?token=demo">Watch channel</a>
                    </article>

                    <article class="channel-card">
                        <div class="channel-badge hot">Live</div>
                        <h4>ESPN</h4>
                        <p>Top leagues, highlights, and international sports coverage.</p>
                        <a href="player.php?token=demo">Watch channel</a>
                    </article>

                    <article class="channel-card">
                        <div class="channel-badge blue">4K</div>
                        <h4>BeIN Sports</h4>
                        <p>World football, analysis, and premium sports entertainment.</p>
                        <a href="player.php?token=demo">Watch channel</a>
                    </article>
                </div>
            </section>

            <section class="feature-banner container">
                <div class="feature-banner-inner">
                    <div>
                        <span class="eyebrow light">SOHO SPORTS</span>
                        <h3>Stream your favorite teams with no buffering and no hassle.</h3>
                    </div>
                    <a href="#live" class="primary-btn">Go live</a>
                </div>
            </section>

            <section class="news-section container" id="news">
                <div class="section-head">
                    <div>
                        <span class="eyebrow light">Latest</span>
                        <h3>Trending in football</h3>
                    </div>
                </div>

                <div class="news-grid">
                    <article class="news-card">
                        <div class="news-thumb t1"></div>
                        <div class="news-body">
                            <span>Matchday</span>
                            <h4>Barcelona and Real Madrid set up another El Clásico showdown.</h4>
                        </div>
                    </article>

                    <article class="news-card">
                        <div class="news-thumb t2"></div>
                        <div class="news-body">
                            <span>Analysis</span>
                            <h4>Manager tactics and key players to watch this weekend.</h4>
                        </div>
                    </article>

                    <article class="news-card">
                        <div class="news-thumb t3"></div>
                        <div class="news-body">
                            <span>Transfer</span>
                            <h4>Top clubs intensify late-window moves before deadline day.</h4>
                        </div>
                    </article>
                </div>
            </section>
        </main>

        <footer class="site-footer">
            <div class="container footer-wrap">
                <div>
                    <div class="brand footer-brand">
                        <div class="brand-mark">S</div>
                        <div>
                            <div class="brand-name">SOHO TV</div>
                            <small>Live & Premium</small>
                        </div>
                    </div>
                </div>

                <div class="footer-links">
                    <a href="#">About</a>
                    <a href="#">Support</a>
                    <a href="#">Privacy</a>
                    <a href="#">Contact</a>
                </div>

                <p>© <span id="year"></span> SOHO TV. All rights reserved.</p>
            </div>
        </footer>
    </div>

    <script src="assets/app.js"></script>
</body>
</html>
