<?php

/**
 * Theme-specific seed: Nexus (Gaming / Cyberpunk)
 *
 * Creates gaming-oriented demo content with esports tournaments,
 * team pages, community galleries, and cyberpunk-themed blog posts.
 * Used during installation when the Nexus theme is selected.
 */
function seedNexusTheme(\App\Core\Database $db, string $language = 'de'): void
{
    $isDE = $language === 'de';

    // ── Pages ──

    $pages = [
        [
            'title'      => $isDE ? 'Turniere' : 'Tournaments',
            'slug'       => $isDE ? 'turniere' : 'tournaments',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Aktuelle und kommende E-Sport-Turniere unserer Community. Melde dich an und kaempfe um den Titel.</p>'
                : '<p>Current and upcoming esports tournaments from our community. Sign up and fight for the title.</p>',
            'sort_order' => 3,
        ],
        [
            'title'      => 'Team',
            'slug'       => 'team',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Lerne unsere Spieler, Coaches und Content Creator kennen – das Nexus Roster im Ueberblick.</p>'
                : '<p>Meet our players, coaches, and content creators – the Nexus roster at a glance.</p>',
            'sort_order' => 4,
        ],
        [
            'title'      => 'Community',
            'slug'       => 'community',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Werde Teil der Nexus Community – Discord, Turniere, Game Nights und mehr. Hier findest du Gleichgesinnte.</p>'
                : '<p>Become part of the Nexus community – Discord, tournaments, game nights, and more. Find like-minded gamers here.</p>',
            'sort_order' => 5,
        ],
    ];

    foreach ($pages as $page) {
        $exists = $db->fetch("SELECT id FROM iw_pages WHERE slug = :slug LIMIT 1", ['slug' => $page['slug']]);
        if (!$exists) {
            $page['status']     = 'published';
            $page['page_type']  = 'page';
            $page['created_at'] = date('Y-m-d H:i:s');
            $page['updated_at'] = date('Y-m-d H:i:s');
            $db->insert('iw_pages', $page);
        }
    }

    // ── Blog Posts ──

    $adminUser = $db->fetch("SELECT id FROM iw_users LIMIT 1");
    $authorId  = $adminUser['id'] ?? 1;
    $newsCat   = $db->fetch("SELECT id FROM iw_blog_categories WHERE slug IN ('news', 'neuigkeiten') LIMIT 1");
    $catId     = $newsCat['id'] ?? null;

    $posts = [
        [
            'title'        => $isDE ? 'Season 8 Meta Guide: Die staerksten Strategien' : 'Season 8 Meta Guide: The Strongest Strategies',
            'slug'         => $isDE ? 'season-8-meta-guide' : 'season-8-meta-guide-en',
            'excerpt'      => $isDE
                ? 'Alles was du ueber die aktuelle Meta wissen musst – Top-Picks, Bans und Teamcomps fuer Season 8.'
                : 'Everything you need to know about the current meta – top picks, bans, and team comps for Season 8.',
            'content'      => $isDE
                ? '<p>Die achte Season bringt massive Veraenderungen am Balancing. Neue Champions dominieren die Rift, waehrend altbewaehrte Picks ueberarbeitet wurden. In diesem Guide analysieren wir die staerksten Strategien, optimale Teamkompositionen und die wichtigsten Draft-Prioritaeten.</p><p>Besonders im Midlane hat sich das Meta komplett verschoben. Aggressive Roaming-Picks ersetzen die bisherigen Waveclear-Mages, und im Jungle dominieren Bruiser mit hohem Early-Game-Pressure.</p>'
                : '<p>Season eight brings massive balancing changes. New champions dominate the Rift while tried-and-true picks have been reworked. In this guide we analyze the strongest strategies, optimal team compositions, and the most important draft priorities.</p><p>The midlane meta has shifted completely. Aggressive roaming picks replace the previous waveclear mages, and bruisers with high early-game pressure dominate the jungle.</p>',
            'status'       => 'published',
            'is_featured'  => 1,
            'category_id'  => $catId,
            'author_id'    => $authorId,
            'published_at' => date('Y-m-d H:i:s'),
            'created_at'   => date('Y-m-d H:i:s'),
            'updated_at'   => date('Y-m-d H:i:s'),
        ],
        [
            'title'        => $isDE ? 'Nexus gewinnt Regional Finals 2026' : 'Nexus Wins Regional Finals 2026',
            'slug'         => $isDE ? 'nexus-regional-finals-2026' : 'nexus-regional-finals-2026-en',
            'excerpt'      => $isDE
                ? 'Unser Team holt den Titel bei den Regional Finals – Recap und Highlights des Turniers.'
                : 'Our team takes the title at the Regional Finals – recap and highlights of the tournament.',
            'content'      => $isDE
                ? '<p>Nach einem intensiven Turnierwochenende hat sich Team Nexus in einem spannenden Best-of-5-Finale gegen die Konkurrenz durchgesetzt. Der Sieg sichert uns den Platz bei den internationalen Playoffs.</p><p>Im entscheidenden fuenften Spiel zeigte unser Roster eine beeindruckende Leistung mit einem aggressiven Early-Game-Ansatz, der den Gegner von Anfang an unter Druck setzte. MVP des Turniers: NexusFlash mit einer dominanten Performance im Jungle.</p>'
                : '<p>After an intense tournament weekend, Team Nexus prevailed in a thrilling best-of-5 final against the competition. The victory secures our spot at the international playoffs.</p><p>In the decisive fifth game, our roster delivered an impressive performance with an aggressive early-game approach that put pressure on the opponents from the start. Tournament MVP: NexusFlash with a dominant jungle performance.</p>',
            'status'       => 'published',
            'is_featured'  => 0,
            'category_id'  => $catId,
            'author_id'    => $authorId,
            'published_at' => date('Y-m-d H:i:s', strtotime('-3 days')),
            'created_at'   => date('Y-m-d H:i:s', strtotime('-3 days')),
            'updated_at'   => date('Y-m-d H:i:s', strtotime('-3 days')),
        ],
    ];

    foreach ($posts as $post) {
        $exists = $db->fetch("SELECT id FROM iw_blog_posts WHERE slug = :slug LIMIT 1", ['slug' => $post['slug']]);
        if (!$exists) {
            $db->insert('iw_blog_posts', $post);
        }
    }

    // ── Events (Tournaments) ──

    $events = [
        [
            'title'          => $isDE ? 'Nexus Championship 2026' : 'Nexus Championship 2026',
            'slug'           => 'nexus-championship-2026',
            'excerpt'        => $isDE
                ? 'Das grosse Jahresturnier mit 10.000 EUR Preispool und Live-Stream auf Twitch.'
                : 'The big annual tournament with EUR 10,000 prize pool and live stream on Twitch.',
            'content'        => $isDE
                ? '<p>Die Nexus Championship 2026 ist unser Flaggschiff-Event des Jahres. Teams aus der gesamten Region kaempfen in mehreren Disziplinen um den Titel und einen Preispool von 10.000 EUR. Das Event wird live auf Twitch und YouTube uebertragen.</p><p>Format: Double Elimination, Best-of-3 bis zum Finale (Best-of-5). Anmeldung ueber unser Discord oder die Turnierseite.</p>'
                : '<p>The Nexus Championship 2026 is our flagship event of the year. Teams from across the region compete in multiple disciplines for the title and a EUR 10,000 prize pool. The event will be broadcast live on Twitch and YouTube.</p><p>Format: Double Elimination, Best-of-3 until the finals (Best-of-5). Registration via our Discord or the tournament page.</p>',
            'location'       => 'Online / Twitch',
            'start_date'     => date('Y-m-d', strtotime('+21 days')),
            'start_time'     => '14:00:00',
            'end_time'       => '22:00:00',
            'publish_status' => 'published',
            'event_status'   => 'scheduled',
            'created_at'     => date('Y-m-d H:i:s'),
        ],
        [
            'title'          => $isDE ? 'Community Game Night: Freitag Edition' : 'Community Game Night: Friday Edition',
            'slug'           => 'community-game-night-friday',
            'excerpt'        => $isDE
                ? 'Entspanntes Zocken mit der Community – jeder ist willkommen, egal welches Skill-Level.'
                : 'Casual gaming with the community – everyone is welcome, regardless of skill level.',
            'content'        => $isDE
                ? '<p>Jeden Freitag treffen wir uns auf Discord zum gemeinsamen Zocken. Ob Ranked, Casual oder Custom Games – hier steht der Spass im Vordergrund. Neue Mitglieder sind immer willkommen!</p><p>Spiele wechseln woechentlich: Valorant, League of Legends, CS2, Rocket League und mehr. Abstimmung im #game-night Channel.</p>'
                : '<p>Every Friday we meet on Discord for gaming together. Whether ranked, casual, or custom games – fun comes first here. New members are always welcome!</p><p>Games rotate weekly: Valorant, League of Legends, CS2, Rocket League, and more. Vote in the #game-night channel.</p>',
            'location'       => 'Discord',
            'start_date'     => date('Y-m-d', strtotime('next friday')),
            'start_time'     => '20:00:00',
            'end_time'       => '23:00:00',
            'publish_status' => 'published',
            'event_status'   => 'scheduled',
            'created_at'     => date('Y-m-d H:i:s'),
        ],
    ];

    foreach ($events as $event) {
        $exists = $db->fetch("SELECT id FROM iw_events WHERE slug = :slug LIMIT 1", ['slug' => $event['slug']]);
        if (!$exists) {
            $db->insert('iw_events', $event);
        }
    }

    // ── Gallery Albums ──

    $albums = [
        [
            'title'       => $isDE ? 'Team Galerie' : 'Team Gallery',
            'slug'        => $isDE ? 'team-galerie' : 'team-gallery',
            'description' => $isDE
                ? 'Unser Roster, unsere Coaches und das Team hinter den Kulissen'
                : 'Our roster, our coaches, and the team behind the scenes',
            'is_visible'  => 1,
            'created_at'  => date('Y-m-d H:i:s'),
        ],
        [
            'title'       => 'Event Highlights',
            'slug'        => 'event-highlights',
            'description' => $isDE
                ? 'Die besten Momente unserer Turniere und Community-Events'
                : 'The best moments from our tournaments and community events',
            'is_visible'  => 1,
            'created_at'  => date('Y-m-d H:i:s'),
        ],
    ];

    foreach ($albums as $album) {
        $exists = $db->fetch("SELECT id FROM iw_gallery_albums WHERE slug = :slug LIMIT 1", ['slug' => $album['slug']]);
        if (!$exists) {
            $db->insert('iw_gallery_albums', $album);
        }
    }

    // ── Homepage Sections: Override starter content with Nexus-themed data ──

    // Hero: Cyberpunk gaming style with neon word and glitch effect
    $heroContent = json_encode([
        'title'          => $isDE ? 'Deine digitale Praesenz auf dem naechsten Level' : 'Your Digital Presence on the Next Level',
        'highlight_word' => 'Level Up',
        'neon_word'      => $isDE ? 'Digitale Praesenz' : 'Digital Presence',
        'show_glitch'    => true,
        'eyebrow'        => $isDE ? 'Gaming & Esports Community' : 'Gaming & Esports Community',
        'subtitle'       => $isDE
            ? 'Turniere, Streams und eine Community die zusammenhaelt – willkommen im Nexus.'
            : 'Tournaments, streams, and a community that sticks together – welcome to the Nexus.',
        'image'          => '',
        'portrait_image' => '',
        'portrait_alt'   => '',
        'text_color'     => 'white',
        'heading_size'   => 'lg',
        'heading_weight' => 'bold',
        'cta_text'       => $isDE ? 'Jetzt beitreten' : 'Join Now',
        'cta_url'        => '/community',
        'cta2_text'      => $isDE ? 'Turniere ansehen' : 'View Tournaments',
        'cta2_url'       => $isDE ? '/turniere' : '/tournaments',
        'hero_stats'     => [
            ['value' => '2.4K+', 'label' => $isDE ? 'Community Mitglieder' : 'Community Members'],
            ['value' => '48+',   'label' => $isDE ? 'Events pro Jahr' : 'Events per Year'],
            ['value' => '16',    'label' => $isDE ? 'Titel gewonnen' : 'Titles Won'],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'hero' AND page_context = 'homepage'",
        ['c' => $heroContent]
    );

    // Intro: Gaming community welcome
    $introContent = json_encode([
        'title'        => $isDE ? 'Willkommen im Nexus' : 'Welcome to the Nexus',
        'text'         => $isDE
            ? 'Nexus ist mehr als ein Team – es ist eine Community von Gamern, die gemeinsam spielen, lernen und wachsen. Egal ob Casual oder Competitive: hier findest du deinen Platz. Unsere Turniere sind offen fuer alle Skill-Levels, und unsere Game Nights bringen Spieler aus der ganzen Region zusammen.'
            : 'Nexus is more than a team – it is a community of gamers who play, learn, and grow together. Whether casual or competitive: you will find your place here. Our tournaments are open to all skill levels, and our game nights bring players from across the region together.',
        'color_scheme' => 'alt',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'intro' AND page_context = 'homepage'",
        ['c' => $introContent]
    );

    // Topic Cards: Gaming pillars
    $topicContent = json_encode([
        'title' => $isDE ? 'Was wir bieten' : 'What We Offer',
        'items' => $isDE ? [
            ['icon' => 'trophy', 'title' => 'Turniere', 'text' => 'Regelmaessige Turniere in verschiedenen Disziplinen – von Community-Cups bis zu grossen Championships mit Preispool.', 'url' => '/turniere'],
            ['icon' => 'monitor', 'title' => 'Streaming', 'text' => 'Live-Streams unserer Matches, Turniere und Community-Events auf Twitch und YouTube – verpasse nichts.', 'url' => '/community'],
            ['icon' => 'users', 'title' => 'Community', 'text' => 'Eine aktive Community auf Discord mit Game Nights, Coaching-Sessions und einem freundlichen Miteinander.', 'url' => '/community'],
        ] : [
            ['icon' => 'trophy', 'title' => 'Tournaments', 'text' => 'Regular tournaments across multiple disciplines – from community cups to major championships with prize pools.', 'url' => '/tournaments'],
            ['icon' => 'monitor', 'title' => 'Streaming', 'text' => 'Live streams of our matches, tournaments, and community events on Twitch and YouTube – never miss a moment.', 'url' => '/community'],
            ['icon' => 'users', 'title' => 'Community', 'text' => 'An active community on Discord with game nights, coaching sessions, and a friendly atmosphere.', 'url' => '/community'],
        ],
        'color_scheme' => 'none',
        'card_style'   => 'bordered',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'topic_cards' AND page_context = 'homepage'",
        ['c' => $topicContent]
    );

    // Features: Gaming advantages
    $featuresContent = json_encode([
        'title' => $isDE ? 'Warum Nexus?' : 'Why Nexus?',
        'items' => $isDE ? [
            ['title' => 'Low Latency', 'text' => 'Unsere Turnierserver bieten minimale Latenz fuer faire Wettkampfbedingungen – keine Ausreden, nur Skill.'],
            ['title' => 'Fair Play', 'text' => 'Strenge Anti-Cheat-Richtlinien und erfahrene Admins sorgen fuer ein faires Spielerlebnis in jeder Runde.'],
            ['title' => '24/7 Community', 'text' => 'Unser Discord ist rund um die Uhr aktiv – finde immer Mitspieler, egal zu welcher Tageszeit.'],
        ] : [
            ['title' => 'Low Latency', 'text' => 'Our tournament servers offer minimal latency for fair competitive conditions – no excuses, just skill.'],
            ['title' => 'Fair Play', 'text' => 'Strict anti-cheat policies and experienced admins ensure a fair gaming experience in every round.'],
            ['title' => '24/7 Community', 'text' => 'Our Discord is active around the clock – always find teammates, no matter what time of day.'],
        ],
        'color_scheme' => 'alt',
        'card_style'   => 'flat',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'features' AND page_context = 'homepage'",
        ['c' => $featuresContent]
    );

    // Blog Preview: Gaming blog
    $blogContent = json_encode([
        'title'    => $isDE ? 'Neuigkeiten & Guides' : 'News & Guides',
        'count'    => 3,
        'cta_text' => $isDE ? 'Alle Beitraege' : 'All Posts',
        'cta_url'  => '/blog',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'blog_preview' AND page_context = 'homepage'",
        ['c' => $blogContent]
    );

    // Events Preview: Upcoming tournaments
    $eventsContent = json_encode([
        'title'    => $isDE ? 'Naechste Turniere & Events' : 'Upcoming Tournaments & Events',
        'count'    => 3,
        'cta_text' => $isDE ? 'Alle Events' : 'All Events',
        'cta_url'  => '/events',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'events_preview' AND page_context = 'homepage'",
        ['c' => $eventsContent]
    );

    // CTA: Join the Nexus
    $ctaContent = json_encode([
        'title'              => $isDE ? 'Join the Nexus' : 'Join the Nexus',
        'text'               => $isDE
            ? 'Werde Teil unserer Gaming-Community. Ob Casual-Gamer oder Competitive-Profi – im Nexus findest du deinen Platz. Melde dich auf Discord an und sei beim naechsten Event dabei.'
            : 'Become part of our gaming community. Whether casual gamer or competitive pro – you will find your place in the Nexus. Sign up on Discord and join the next event.',
        'cta_text'           => $isDE ? 'Discord beitreten' : 'Join Discord',
        'cta_url'            => '/community',
        'color_scheme'       => '',
        'section_text_color' => '',
    ], JSON_UNESCAPED_UNICODE);

    $db->query(
        "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'cta' AND page_context = 'homepage'",
        ['c' => $ctaContent]
    );

    // ── Stats: Gaming key figures ──

    $statsContent = json_encode([
        'title'              => '',
        'subtitle'           => '',
        'color_scheme'       => '',
        'section_text_color' => '',
        'section_surface'    => '',
        'text_align'         => '',
        'columns'            => '4',
        'items'              => [
            ['value' => '48',    'label' => $isDE ? 'Events pro Jahr' : 'Events per Year',           'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '2.4K',  'label' => $isDE ? 'Community Mitglieder' : 'Community Members',    'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '860',   'label' => 'Streams',                                               'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '16',    'label' => $isDE ? 'Turniere gewonnen' : 'Tournaments Won',         'icon' => '', 'prefix' => '', 'suffix' => ''],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $statsExists = $db->fetch("SELECT id FROM iw_page_sections WHERE section_type = 'stats' AND page_context = 'homepage' LIMIT 1");
    if ($statsExists) {
        $db->query(
            "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'stats' AND page_context = 'homepage'",
            ['c' => $statsContent]
        );
    } else {
        $db->insert('iw_page_sections', [
            'page_context'   => 'homepage',
            'section_type'   => 'stats',
            'instance_label' => $isDE ? 'Kennzahlen' : 'Key Figures',
            'content'        => $statsContent,
            'is_active'      => 1,
            'sort_order'     => 1,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }

    // ── Testimonials: Gaming community testimonials ──

    $testimonialsContent = json_encode([
        'title'              => $isDE ? 'Das sagt unsere Community' : 'What Our Community Says',
        'subtitle'           => '',
        'color_scheme'       => 'primary',
        'section_text_color' => '',
        'section_surface'    => '',
        'text_align'         => '',
        'columns'            => '2',
        'layout'             => 'staggered',
        'items'              => $isDE ? [
            [
                'quote'  => 'Nexus ist die beste Gaming-Community in der ich je war. Die Turniere sind professionell organisiert, die Admins fair und die Atmosphaere einfach top. Hier fuehlt man sich sofort willkommen.',
                'author' => 'PhantomBlade',
                'role'   => 'Community Member seit 2024',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'Seit ich bei Nexus bin, hat sich mein Gameplay massiv verbessert. Die Coaching-Sessions und das Feedback aus der Community sind Gold wert. Ausserdem macht es einfach Spass, mit so netten Leuten zu zocken.',
                'author' => 'CyberVixen',
                'role'   => 'Competitive Spielerin',
                'avatar' => '',
                'rating' => 5,
            ],
        ] : [
            [
                'quote'  => 'Nexus is the best gaming community I have ever been part of. The tournaments are professionally organized, the admins are fair, and the atmosphere is just great. You feel welcome right away.',
                'author' => 'PhantomBlade',
                'role'   => 'Community Member since 2024',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'Since joining Nexus, my gameplay has improved massively. The coaching sessions and feedback from the community are worth their weight in gold. Plus, it is just fun to game with such great people.',
                'author' => 'CyberVixen',
                'role'   => 'Competitive Player',
                'avatar' => '',
                'rating' => 5,
            ],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $testimonialsExists = $db->fetch("SELECT id FROM iw_page_sections WHERE section_type = 'testimonials' AND page_context = 'homepage' LIMIT 1");
    if ($testimonialsExists) {
        $db->query(
            "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'testimonials' AND page_context = 'homepage'",
            ['c' => $testimonialsContent]
        );
    } else {
        $db->insert('iw_page_sections', [
            'page_context'   => 'homepage',
            'section_type'   => 'testimonials',
            'instance_label' => $isDE ? 'Community-Stimmen' : 'Testimonials',
            'content'        => $testimonialsContent,
            'is_active'      => 1,
            'sort_order'     => 8,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }

    // ── Tournament: Nexus-exclusive section ──

    $tournamentContent = json_encode([
        'title'              => $isDE ? 'Aktive Turniere' : 'Active Tournaments',
        'subtitle'           => $isDE
            ? 'Melde dich an und kaempfe um den Titel – alle Turniere offen fuer Community-Mitglieder.'
            : 'Sign up and fight for the title – all tournaments open to community members.',
        'color_scheme'       => '',
        'section_text_color' => '',
        'items'              => [
            [
                'game'       => 'Valorant',
                'title'      => $isDE ? 'Nexus Valorant Cup' : 'Nexus Valorant Cup',
                'date'       => date('Y-m-d', strtotime('+7 days')),
                'prize'      => '500 EUR',
                'teams'      => '16',
                'status'     => 'open',
                'format'     => 'Single Elimination',
            ],
            [
                'game'       => 'League of Legends',
                'title'      => $isDE ? 'LoL Community League' : 'LoL Community League',
                'date'       => date('Y-m-d', strtotime('+14 days')),
                'prize'      => '1.000 EUR',
                'teams'      => '8',
                'status'     => 'open',
                'format'     => 'Round Robin + Playoffs',
            ],
            [
                'game'       => 'CS2',
                'title'      => 'CS2 Showdown',
                'date'       => date('Y-m-d', strtotime('+21 days')),
                'prize'      => '750 EUR',
                'teams'      => '12',
                'status'     => 'open',
                'format'     => 'Double Elimination',
            ],
            [
                'game'       => 'Rocket League',
                'title'      => $isDE ? 'Rocket League Blitz' : 'Rocket League Blitz',
                'date'       => date('Y-m-d', strtotime('+28 days')),
                'prize'      => '300 EUR',
                'teams'      => '32',
                'status'     => 'open',
                'format'     => 'Single Elimination',
            ],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $tournamentExists = $db->fetch("SELECT id FROM iw_page_sections WHERE section_type = 'tournament' AND page_context = 'homepage' LIMIT 1");
    if ($tournamentExists) {
        $db->query(
            "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'tournament' AND page_context = 'homepage'",
            ['c' => $tournamentContent]
        );
    } else {
        $db->insert('iw_page_sections', [
            'page_context'   => 'homepage',
            'section_type'   => 'tournament',
            'instance_label' => $isDE ? 'Turniere' : 'Tournaments',
            'content'        => $tournamentContent,
            'is_active'      => 1,
            'sort_order'     => 5,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }
}
