<?php
require_once __DIR__ . '/config.php';

// ----------------------
// PAGE META
// ----------------------
$pageTitle = "Universal UK: Everything We Know So Far | ThrillSense";
$metaDescription = "Everything we know so far about Universal UK's proposed Bedford theme park resort, including latest updates, confirmed details, rumours and related ThrillSense coverage.";
$extra_head = '
<link rel="stylesheet" href="/styles/park.css">
<link rel="stylesheet" href="/styles/universal-uk.css">
';

// ----------------------
// TAG COLOURS
// ----------------------
try {
    $stmtTags = $pdo->query("SELECT name, color FROM tags");
    $tagColors = [];

    while ($row = $stmtTags->fetch(PDO::FETCH_ASSOC)) {
        $tagColors[strtolower(trim($row['name']))] = $row['color'];
    }
} catch (PDOException $e) {
    $tagColors = [];
}

// ----------------------
// LATEST UNIVERSAL UK POSTS
// Pulls anything tagged exactly "Universal UK"
// Handles both "Universal UK,Disney" and "Universal UK, Disney"
// ----------------------
try {
    $stmt = $pdo->prepare("
        SELECT *
        FROM posts
        WHERE FIND_IN_SET(:tag, REPLACE(tags, ', ', ','))
        ORDER BY created_at DESC
        LIMIT 9
    ");

    $stmt->execute([
        ':tag' => 'Universal UK'
    ]);

    $universalPosts = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $universalPosts = [];
}

// ----------------------
// HELPERS
// ----------------------
function getTagColorStyle($tag, $tagColors) {
    $key = strtolower(trim($tag));

    if (isset($tagColors[$key]) && preg_match('/^#?[0-9A-Fa-f]{6}$/', $tagColors[$key])) {
        $color = $tagColors[$key];

        if ($color[0] !== '#') {
            $color = '#' . $color;
        }

        return "background-color: $color;";
    }

    return "background-color: #262541;";
}

function formatDate($date) {
    return date('F j, Y', strtotime($date));
}

function getPostUrl($post) {
    return '/' . htmlspecialchars($post['post_location']) . '/' . urlencode($post['slug']);
}

require_once __DIR__ . '/includes/header.php';
?>

<main>

    <section class="hero position-relative">
        <img src="/assets/universal-uk-hero.jpg" class="hero-bg" alt="Universal UK Bedford theme park resort">
        <div class="gradient-overlay"></div>

        <div class="hero-content position-absolute top-50 start-50 translate-middle text-center text-white">
            <h1 class="display-4 fw-bold">Universal UK</h1>
            <p class="lead text-white">
                Everything we know so far about Universal’s proposed Bedford theme park resort.
            </p>
            <span class="development-badge">In Development</span>
        </div>
    </section>

    <section class="py-4">
        <div class="container">
            <h2 class="mb-4">Universal UK Quick Facts</h2>

            <div class="row text-center g-4">
                <div class="col-md-3">
                    <div class="development-fact-card">
                        <p>
                            <strong>
                                <span class="material-icons" style="vertical-align: middle;">construction</span>
                                Status:
                            </strong><br>
                            In development
                        </p>
                    </div>
                </div>

                <div class="col-md-3">
                    <div class="development-fact-card">
                        <p>
                            <strong>
                                <span class="material-icons" style="vertical-align: middle;">place</span>
                                Location:
                            </strong><br>
                            Bedford, England
                        </p>
                    </div>
                </div>

                <div class="col-md-3">
                    <div class="development-fact-card">
                        <p>
                            <strong>
                                <span class="material-icons" style="vertical-align: middle;">event</span>
                                Opening:
                            </strong><br>
                            Not officially confirmed
                        </p>
                    </div>
                </div>

                <div class="col-md-3">
                    <div class="development-fact-card">
                        <p>
                            <strong>
                                <span class="material-icons" style="vertical-align: middle;">attractions</span>
                                Rides:
                            </strong><br>
                            Not yet announced
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="container py-5">
        <div class="development-intro-card">
            <h2>Universal UK Development Hub</h2>

            <p>
                Universal UK is one of the most exciting theme park projects currently being discussed in the UK.
                The proposed resort in Bedford could become a major new destination for theme park fans, families and tourists,
                but many details are still to be officially confirmed.
            </p>

            <p>
                This page brings together the latest Universal UK updates, confirmed details, rumours and ThrillSense coverage
                in one place. As more information becomes available, this hub can be updated with the latest developments.
            </p>

            <p>
                Articles and news stories tagged <strong>Universal UK</strong> will appear automatically below.
            </p>
        </div>
    </section>

    <section class="bg-light py-5">
        <div class="container">
            <h2 class="mb-4">Latest Universal UK Updates</h2>

            <?php if (empty($universalPosts)): ?>
                <p>No Universal UK updates found yet.</p>
            <?php else: ?>
                <div class="row g-4">
                    <?php foreach ($universalPosts as $post): ?>
                        <div class="col-md-4">
                            <a href="<?= getPostUrl($post) ?>" class="text-decoration-none text-dark">
                                <div class="card h-100 shadow-sm">
                                    <img
                                        src="/<?= htmlspecialchars($post['image_path'] ?? '/assets/default.jpg') ?>"
                                        class="card-img-top"
                                        alt="<?= htmlspecialchars($post['title']) ?>"
                                    >

                                    <div class="card-body">
                                        <p class="text-muted">
                                            <?= formatDate($post['created_at']) ?>
                                        </p>

                                        <h5 class="card-title text-alt">
                                            <?= htmlspecialchars($post['title']) ?>
                                        </h5>

                                        <?php if (!empty($post['tagline'])): ?>
                                            <p><?= htmlspecialchars($post['tagline']) ?></p>
                                        <?php endif; ?>

                                        <?php if (!empty($post['tags'])): ?>
                                            <div class="mt-2">
                                                <?php foreach (explode(',', $post['tags']) as $tag): ?>
                                                    <span class="badge rounded-pill text-white" style="<?= getTagColorStyle($tag, $tagColors) ?>">
                                                        <?= htmlspecialchars(trim($tag)) ?>
                                                    </span>
                                                <?php endforeach; ?>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </a>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
    </section>

    <section class="container py-5">
        <div class="row g-4">

            <div class="col-lg-7">
                <div class="development-card h-100">
                    <h2>What has been confirmed?</h2>

                    <p>
                        Universal has confirmed plans for a major UK resort project in Bedford. The project has attracted huge attention
                        because it could become one of the most significant theme park developments in the UK.
                    </p>

                    <p>
                        However, specific rides, lands, opening dates and attraction line-ups have not yet been officially announced.
                        Until Universal shares those details, the safest way to follow the project is to separate confirmed information
                        from speculation.
                    </p>

                    <p>
                        ThrillSense will continue to follow official updates, planning developments and major announcements connected
                        to the proposed resort.
                    </p>
                </div>
            </div>

            <div class="col-lg-5">
                <div class="development-card h-100">
                    <h2>Rumours and speculation</h2>

                    <p>
                        Fans have already speculated about possible Universal franchises, lands and attractions that could appear
                        at the Bedford resort, including ideas linked to Back to the Future, Jurassic World, Minions and other major Universal properties.
                    </p>

                    <p>
                        Nothing has been officially confirmed, so any ride or land discussion should be treated as rumour until Universal announces further details.
                    </p>
                </div>
            </div>

        </div>
    </section>

    <section class="bg-light py-5">
        <div class="container">
            <h2 class="mb-4">Universal UK Timeline</h2>

            <div class="development-timeline">

                <div class="timeline-item">
                    <span>Land acquisition and early interest</span>
                    <p>
                        Universal’s interest in land near Bedford became one of the biggest UK theme park stories in years,
                        sparking huge discussion about what a British Universal resort could look like.
                    </p>
                </div>

                <div class="timeline-item">
                    <span>Project confirmation</span>
                    <p>
                        Universal confirmed plans for a major UK resort project, bringing the possibility of a Universal theme park
                        in the UK closer than ever before.
                    </p>
                </div>

                <div class="timeline-item">
                    <span>Ongoing updates</span>
                    <p>
                        Details around planning, transport, design, infrastructure and possible attractions continue to be closely watched
                        by theme park fans and the wider attractions industry.
                    </p>
                </div>

                <div class="timeline-item">
                    <span>What comes next?</span>
                    <p>
                        The next major step will be further official detail from Universal about the resort, including confirmed lands,
                        rides, dates and visitor experience.
                    </p>
                </div>

            </div>
        </div>
    </section>

    <section class="container py-5">
        <div class="development-card">
            <h2>Follow the latest Universal UK news</h2>

            <p>
                This page is designed as a living hub for Universal UK coverage on ThrillSense. New articles, news stories and features
                tagged <strong>Universal UK</strong> will appear in the latest updates section automatically.
            </p>

            <p>
                To keep this hub up to date, make sure any relevant post in the admin panel includes the tag:
                <strong>Universal UK</strong>.
            </p>
        </div>
    </section>

</main>

<?php require_once __DIR__ . '/includes/footer.php'; ?>