<?php
require_once '/home/akgbilis/fi_sf/config.php';
session_start();

if (!isset($_SESSION['logged_in'])) {
    header("Location: login.php");
    exit;
}

$stmt = $pdo->query("SELECT * FROM daily_matches ORDER BY date DESC, time ASC");
$matches = $stmt->fetchAll();

function getOptions($pdo, $matchId) {
    $stmt = $pdo->prepare("SELECT * FROM daily_match_options WHERE match_id = ?");
    $stmt->execute([$matchId]);
    return $stmt->fetchAll();
}
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>Günün Maçları</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        body { font-family: Arial, sans-serif; padding: 30px; background-color: #f8f8f8; }
        h2 { margin-bottom: 20px; }
        .match-card {
            background: white;
            padding: 16px;
            margin-bottom: 20px;
            border-left: 4px solid #198754;
            border-radius: 6px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.05);
        }
        .options { margin-top: 10px; }
        .option { background: #eee; padding: 6px 10px; margin: 4px 0; border-radius: 4px; }
    </style>
</head>
<body>
    <h2>📅 Günün Maçları</h2>
    <a href="add_daily_match.php" style="background:#198754;color:white;padding:10px 16px;border-radius:6px;text-decoration:none;">➕ Yeni Maç Ekle</a>
    <br><br>

    <?php foreach ($matches as $match): ?>
        <div class="match-card">
            <strong><?= htmlspecialchars($match['home_team']) ?> - <?= htmlspecialchars($match['away_team']) ?></strong><br>
            <small><?= htmlspecialchars($match['country']) ?> • <?= htmlspecialchars($match['league']) ?> • <?= $match['date'] ?> <?= $match['time'] ?></small>

            <div class="options">
                <strong>Seçenekler:</strong>
                <?php foreach (getOptions($pdo, $match['id']) as $opt): ?>
                    <div class="option"><?= htmlspecialchars($opt['option_text']) ?></div>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endforeach; ?>
</body>
</html>
