<?php
session_start();
require_once '/home/akgbilis/fi_sf/config.php';
if (!isset($_SESSION['logged_in'])) {
    header("Location: login.php");
    exit;
}



$matchId = $_GET['id'] ?? '';

if (!$matchId) {
    header("Location: dashboard.php");
    exit;
}

// Maç var mı kontrolü
$stmt = $pdo->prepare("SELECT * FROM matches WHERE id = ?");
$stmt->execute([$matchId]);
$match = $stmt->fetch();

if (!$match) {
    die("Maç bulunamadı.");
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Önce ilgili combine_matches kayıtlarını sil
    $stmt = $pdo->prepare("DELETE FROM combine_matches WHERE match_id = ?");
    $stmt->execute([$matchId]);

    // Sonra maçı sil
    $stmt = $pdo->prepare("DELETE FROM matches WHERE id = ?");
    $stmt->execute([$matchId]);

    header("Location: dashboard.php");
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Delete Match</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container" style="max-width: 600px; margin: 40px auto;">
    <h2 style="text-align: center;">Delete Match</h2>
    <p style="text-align: center;">Are you sure you want to delete the match <strong><?= htmlspecialchars($match['home']) ?> - <?= htmlspecialchars($match['away']) ?></strong> (<?= $match['date'] ?>)?</p>

    <form method="POST" style="display: flex; flex-direction: column; gap: 12px; align-items: center;">
        <button type="submit" class="button red">Yes, Delete</button>
        <a href="dashboard.php" class="button gray">Cancel</a>
    </form>
</div>
</body>
</html>