<?php

/**
 * Theme-specific seed: Arcade (Retro Gaming)
 *
 * Creates retro-gaming-oriented demo content with pixel art blogs,
 * high scores, gaming events, team party members, and 8-bit themed
 * homepage sections. Used during installation when the Arcade theme
 * is selected.
 */
function seedArcadeTheme(\App\Core\Database $db, string $language = 'de'): void
{
    $isDE = $language === 'de';

    // ── Pages ──

    $pages = [
        [
            'title'      => $isDE ? 'Spiele' : 'Games',
            'slug'       => $isDE ? 'spiele' : 'games',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Unsere Spielesammlung – von klassischen Arcade-Hits bis zu modernen Indie-Titeln. Entdecke die besten Retro-Games und neue Pixel-Art-Abenteuer.</p>'
                : '<p>Our game collection – from classic arcade hits to modern indie titles. Discover the best retro games and new pixel art adventures.</p>',
            'sort_order' => 3,
        ],
        [
            'title'      => $isDE ? 'Highscores' : 'High Scores',
            'slug'       => 'highscores',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Die ewige Bestenliste – wer hat die meisten Punkte? Trage dich ein und kaempfe um den ersten Platz in der Hall of Fame.</p>'
                : '<p>The eternal leaderboard – who has the most points? Enter your name and fight for the top spot in the Hall of Fame.</p>',
            'sort_order' => 4,
        ],
        [
            'title'      => $isDE ? 'Community' : 'Community',
            'slug'       => 'community',
            'template'   => 'page',
            'content'    => $isDE
                ? '<p>Tritt unserer Gaming-Community bei! Tausche Tipps aus, finde Mitspieler fuer Multiplayer-Sessions und diskutiere ueber alles rund um Retro-Gaming.</p>'
                : '<p>Join our gaming community! Share tips, find co-op partners for multiplayer sessions, and discuss everything retro gaming.</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 ? 'Pixel Art Grundlagen: So erstellst du deine ersten Sprites' : 'Pixel Art Basics: How to Create Your First Sprites',
            'slug'         => $isDE ? 'pixel-art-grundlagen' : 'pixel-art-basics',
            'excerpt'      => $isDE
                ? 'Alles was du fuer dein erstes Pixel-Art-Projekt brauchst – Werkzeuge, Techniken und die wichtigsten Regeln fuer authentisches Retro-Design.'
                : 'Everything you need for your first pixel art project – tools, techniques, and the most important rules for authentic retro design.',
            'content'      => $isDE
                ? '<p>Pixel Art ist weit mehr als nur niedrig aufgeloeste Grafik – es ist eine eigene Kunstform mit klaren Regeln und endlosen Moeglichkeiten. In diesem Guide erklaere ich dir die Grundlagen, mit denen du sofort loslegen kannst.</p><p>Das wichtigste Werkzeug ist ein guter Editor. Aseprite ist der Standard fuer professionelle Pixel Artists, aber auch kostenlose Tools wie Libresprite oder sogar der Browser-basierte Piskel.com reichen fuer den Anfang aus. Das Prinzip ist immer dasselbe: ein Pixel nach dem anderen, Farbe fuer Farbe.</p><p>Fange mit einer kleinen Palette an – 8 bis 16 Farben sind genug fuer den Start. Zu viele Farben lassen deine Sprites chaotisch wirken. Klassische Paletten wie Pico-8 oder die Game Boy Palette sind hervorragende Ausgangspunkte.</p>'
                : '<p>Pixel art is far more than just low-resolution graphics – it is its own art form with clear rules and endless possibilities. In this guide I explain the basics so you can get started right away.</p><p>The most important tool is a good editor. Aseprite is the standard for professional pixel artists, but free tools like Libresprite or even the browser-based Piskel.com are sufficient for beginners. The principle is always the same: one pixel at a time, color by color.</p><p>Start with a small palette – 8 to 16 colors are enough to begin. Too many colors make your sprites look chaotic. Classic palettes like Pico-8 or the Game Boy palette are excellent starting points.</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 ? 'Game Loops: Das Herzschlag-Prinzip hinter jedem Spiel' : 'Game Loops: The Heartbeat Principle Behind Every Game',
            'slug'         => $isDE ? 'game-loops-herzschlag' : 'game-loops-heartbeat',
            'excerpt'      => $isDE
                ? 'Wie funktioniert ein Game Loop? Wir erklaeren Update, Render und Input-Handling – das Fundament jeder Spielentwicklung.'
                : 'How does a game loop work? We explain update, render, and input handling – the foundation of every game development.',
            'content'      => $isDE
                ? '<p>Jedes Videospiel – egal ob simples Snake oder komplexes Open-World-RPG – basiert auf demselben Prinzip: dem Game Loop. Dieser Kreislauf aus Eingabe verarbeiten, Spielzustand aktualisieren und Bildschirm rendern laeuft dutzende bis hunderte Male pro Sekunde ab.</p><p>Der klassische Game Loop sieht so aus: Zuerst werden alle Eingaben (Tastatur, Gamepad, Touch) gesammelt. Dann wird der Spielzustand aktualisiert – Bewegungen berechnet, Kollisionen geprueft, KI entschieden. Zuletzt wird alles auf den Bildschirm gemalt. Dann beginnt das Ganze von vorne.</p><p>Fuer Retro-Spiele auf 8-Bit-Hardware war dieser Loop auf 60 Hz optimiert – genau das Gefuehl, das wir bis heute als "fluessiges Gameplay" bezeichnen.</p>'
                : '<p>Every video game – whether a simple Snake or a complex open-world RPG – is based on the same principle: the game loop. This cycle of processing input, updating game state, and rendering the screen runs dozens to hundreds of times per second.</p><p>The classic game loop looks like this: First, all inputs (keyboard, gamepad, touch) are collected. Then the game state is updated – movements calculated, collisions checked, AI decisions made. Finally, everything is drawn to the screen. Then the whole thing starts over.</p><p>For retro games on 8-bit hardware, this loop was optimized for 60 Hz – exactly the feeling we still call "fluid gameplay" today.</p>',
            'status'       => 'published',
            'is_featured'  => 0,
            'category_id'  => $catId,
            'author_id'    => $authorId,
            'published_at' => date('Y-m-d H:i:s', strtotime('-4 days')),
            'created_at'   => date('Y-m-d H:i:s', strtotime('-4 days')),
            'updated_at'   => date('Y-m-d H:i:s', strtotime('-4 days')),
        ],
        [
            'title'        => $isDE ? 'Arcade-Hallen der 80er: Eine goldene Aera des Gamings' : 'Arcades of the 80s: A Golden Era of Gaming',
            'slug'         => $isDE ? 'arcade-hallen-80er' : 'arcades-80s-golden-era',
            'excerpt'      => $isDE
                ? 'Pac-Man, Donkey Kong, Space Invaders – eine Reise in die Zeit der Spielhallen, die die Videospielkultur fuer immer gepraegt haben.'
                : 'Pac-Man, Donkey Kong, Space Invaders – a journey back to the era of arcades that forever shaped video game culture.',
            'content'      => $isDE
                ? '<p>In den fruehen 1980er Jahren war die Spielhalle der soziale Mittelpunkt fuer eine ganze Generation. Gegen eine Handvoll Muenzen durfte man sich an monumentalen Cabinets versuchen, die technisch haushoch ueber alles waren, was man zu Hause hatte.</p><p>Pac-Man (1980) wurde zum ersten echten popkulturellen Phaenomen der Spielegeschichte. Donkey Kong gab einem gewissen Mario seine erste Hauptrolle. Und Space Invaders soll in Japan zeitweise eine Muenzknappheit verursacht haben, weil alle Wechselgeld fuer die Automaten brauchten.</p><p>Was diese Aera so besonders macht: die Entwickler mussten mit extremen Hardwarebeschraenkungen kreativ sein. Kein freier RAM, kein freier ROM. Jedes Byte zaehlt. Das Ergebnis ist zeitloses Design, das noch heute fasziniert.</p>'
                : '<p>In the early 1980s, the arcade was the social hub for an entire generation. For a handful of coins, you could try your hand at monumental cabinets that were technically far superior to anything available at home.</p><p>Pac-Man (1980) became the first true pop-cultural phenomenon in gaming history. Donkey Kong gave a certain Mario his first starring role. And Space Invaders reportedly caused a coin shortage in Japan because everyone needed change for the machines.</p><p>What makes this era so special: developers had to be creative with extreme hardware limitations. No free RAM, no free ROM. Every byte counts. The result is timeless design that still fascinates today.</p>',
            'status'       => 'published',
            'is_featured'  => 0,
            'category_id'  => $catId,
            'author_id'    => $authorId,
            'published_at' => date('Y-m-d H:i:s', strtotime('-8 days')),
            'created_at'   => date('Y-m-d H:i:s', strtotime('-8 days')),
            'updated_at'   => date('Y-m-d H:i:s', strtotime('-8 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 ──

    $events = [
        [
            'title'          => $isDE ? 'Retro Gaming Night' : 'Retro Gaming Night',
            'slug'           => 'retro-gaming-night',
            'excerpt'        => $isDE
                ? 'Gemeinsames Zocken von Klassikern – von Pong bis Street Fighter II. Alle Konsolen willkommen!'
                : 'Gaming classics together – from Pong to Street Fighter II. All consoles welcome!',
            'content'        => $isDE
                ? '<p>An der Retro Gaming Night spielen wir gemeinsam die groessten Klassiker der Videospielgeschichte. Von Atari 2600 ueber NES und SNES bis hin zu Sega Mega Drive – alle Konsolen sind willkommen. Bring dein eigenes Geraet oder nutze unsere Community-Hardware.</p><p>Format: Freies Spielen + Turnier-Brackets fuer Street Fighter II, Mario Kart und Tetris. Preis fuer den Gesamtsieger: eine original Pac-Man Spielhallen-Platine.</p>'
                : '<p>At Retro Gaming Night we play the greatest classics of video game history together. From Atari 2600 through NES and SNES to Sega Mega Drive – all consoles welcome. Bring your own device or use our community hardware.</p><p>Format: Free play + tournament brackets for Street Fighter II, Mario Kart, and Tetris. Prize for the overall winner: an original Pac-Man arcade board.</p>',
            'location'       => $isDE ? 'Jugendhaus Mitte, Hauptstr. 1' : 'Community Center, Main St. 1',
            'start_date'     => date('Y-m-d', strtotime('+14 days')),
            'start_time'     => '18:00:00',
            'end_time'       => '23:00:00',
            'publish_status' => 'published',
            'event_status'   => 'scheduled',
            'created_at'     => date('Y-m-d H:i:s'),
        ],
        [
            'title'          => $isDE ? 'Pixel Art Workshop: Charaktere zeichnen' : 'Pixel Art Workshop: Drawing Characters',
            'slug'           => 'pixel-art-workshop-charaktere',
            'excerpt'        => $isDE
                ? 'Lerne in 3 Stunden, eigene Game-Charaktere im Pixel-Art-Stil zu erstellen – fuer Anfaenger und Fortgeschrittene.'
                : 'Learn to create your own game characters in pixel art style in 3 hours – for beginners and advanced artists.',
            'content'        => $isDE
                ? '<p>In diesem Workshop lernst du Schritt fuer Schritt, wie du eigene Spielcharaktere im Pixel-Art-Stil erstellst. Wir beginnen mit einfachen Formen und arbeiten uns bis zu animierten Sprites vor.</p><p>Materialien: Laptop oder Tablet mit Aseprite (kostenlose Demo reicht). Vorkenntnisse werden nicht benoetigt – wir starten bei null. Am Ende des Workshops haelst du drei eigene animierte Sprites in den Haenden, die du direkt in deinen Spielen verwenden kannst.</p>'
                : '<p>In this workshop you will learn step by step how to create your own game characters in pixel art style. We start with simple shapes and work our way up to animated sprites.</p><p>Materials: Laptop or tablet with Aseprite (free demo is enough). No prior knowledge required – we start from scratch. At the end of the workshop you will have three original animated sprites that you can use directly in your games.</p>',
            'location'       => 'Online / Discord',
            'start_date'     => date('Y-m-d', strtotime('+28 days')),
            'start_time'     => '15:00:00',
            'end_time'       => '18:00:00',
            'publish_status' => 'published',
            'event_status'   => 'scheduled',
            'created_at'     => date('Y-m-d H:i:s'),
        ],
        [
            'title'          => $isDE ? 'Arcade Jam: 48h Game Jam' : 'Arcade Jam: 48h Game Jam',
            'slug'           => 'arcade-jam-48h',
            'excerpt'        => $isDE
                ? '48 Stunden, ein Thema, unendliche Moeglichkeiten – entwickle dein eigenes Retro-Spiel und gewinne tolle Preise.'
                : '48 hours, one theme, endless possibilities – develop your own retro game and win great prizes.',
            'content'        => $isDE
                ? '<p>Der Arcade Jam ist unser jaehrlicher Game Jam fuer alle, die schon immer ein eigenes Spiel entwickeln wollten. In 48 Stunden – vom Freitagabend bis Sonntagabend – wird ein kleines Spiel passend zum Monatsthema entwickelt.</p><p>Alle Skill-Level willkommen: Solo oder im Team bis 4 Personen. Engines nach Wahl – Pico-8, Unity, Godot, Love2D oder pure HTML5. Bewertung durch Community-Voting in drei Kategorien: Gameplay, Pixelart, Originalitaet.</p>'
                : '<p>The Arcade Jam is our annual game jam for everyone who has always wanted to develop their own game. In 48 hours – from Friday evening to Sunday evening – a small game matching the monthly theme is developed.</p><p>All skill levels welcome: solo or in teams up to 4 people. Engines of your choice – Pico-8, Unity, Godot, Love2D, or pure HTML5. Judged by community voting in three categories: Gameplay, Pixel Art, Originality.</p>',
            'location'       => 'Online / itch.io',
            'start_date'     => date('Y-m-d', strtotime('next friday +5 weeks')),
            'start_time'     => '20:00:00',
            'end_time'       => '20: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 ? 'Spielhallen-Galerie' : 'Arcade Gallery',
            'slug'        => $isDE ? 'spielhallen-galerie' : 'arcade-gallery',
            'description' => $isDE
                ? 'Fotos und Screenshots aus unseren Retro-Gaming-Events und der Community'
                : 'Photos and screenshots from our retro gaming events and community',
            'is_visible'  => 1,
            'created_at'  => date('Y-m-d H:i:s'),
        ],
        [
            'title'       => $isDE ? 'Pixel Art Galerie' : 'Pixel Art Gallery',
            'slug'        => $isDE ? 'pixel-art-galerie' : 'pixel-art-gallery',
            'description' => $isDE
                ? 'Die besten Pixel-Art-Werke unserer Community-Mitglieder'
                : 'The best pixel art creations from our community members',
            '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 ──

    // Hero: PRESS START – Retro Gaming
    $heroContent = json_encode([
        'title'          => 'PRESS START',
        'highlight_word' => 'Press',
        'eyebrow'        => 'Player 1 Ready',
        'subtitle'       => $isDE
            ? 'Willkommen in der Welt des Retro-Gamings – Pixel Art, 8-Bit-Sound und unendlich viele Leben warten auf dich.'
            : 'Welcome to the world of retro gaming – pixel art, 8-bit sound, and endless lives await you.',
        'image'          => '',
        'portrait_image' => '',
        'portrait_alt'   => '',
        'text_color'     => 'white',
        'heading_size'   => 'xl',
        'heading_weight' => 'bold',
        'cta_text'       => $isDE ? 'Jetzt spielen' : 'Play Now',
        'cta_url'        => $isDE ? '/spiele' : '/games',
        'cta2_text'      => $isDE ? 'Highscores' : 'High Scores',
        'cta2_url'       => '/highscores',
        'show_starfield' => 1,
        'show_cursor'    => 1,
        'hero_stats'     => [
            ['value' => '12.480', 'label' => $isDE ? 'Beitraege' : 'Posts'],
            ['value' => '98.750', 'label' => $isDE ? 'Besucher'  : 'Visitors'],
            ['value' => '5.320',  'label' => $isDE ? 'Downloads' : 'Downloads'],
        ],
    ], 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: Willkommen im Arcade
    $introContent = json_encode([
        'title'        => $isDE ? 'Willkommen im Arcade' : 'Welcome to the Arcade',
        'text'         => $isDE
            ? 'Hier lebt der Geist der 8-Bit-Aera weiter. Von den ersten Pixel-Sprites der 80er bis zu modernen Indie-Games mit Retro-Flair – wir feiern alles, was Spielkultur ausmacht. Ob du selbst entwickelst, sammelst oder einfach spielst: hier findest du Gleichgesinnte. Drei Leben, acht Bits, unendlich viel Spass.'
            : 'The spirit of the 8-bit era lives on here. From the first pixel sprites of the 80s to modern indie games with a retro flair – we celebrate everything that makes gaming culture. Whether you develop, collect, or simply play: you will find like-minded people here. Three lives, eight bits, endless fun.',
        '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]
    );

    // Features: Power-Ups
    $featuresContent = json_encode([
        'title' => $isDE ? 'Power-Ups freischalten' : 'Unlock Power-Ups',
        'items' => $isDE ? [
            ['icon' => 'heart',     'title' => 'Extra Leben',  'text' => 'Regelmaessige Backups und Versionierung – dein Content ist immer sicher. Kein Game Over, kein Datenverlust.'],
            ['icon' => 'star',      'title' => 'Stern-Power',  'text' => 'Blitzschnelle Ladezeiten und optimiertes Caching sorgen fuer maximale Performance – deine Webseite ist unaufhaltsam.'],
            ['icon' => 'shield',    'title' => 'Schutzschild', 'text' => 'CSRF-Schutz, Prepared Statements und gehaertetes Sicherheitssystem halten Angreifer aus dem Game.'],
            ['icon' => 'zap',       'title' => 'Speed Boost',  'text' => 'Server-Side Rendering ohne Framework-Overhead. Deine Seite laesst andere einfach hinter sich.'],
            ['icon' => 'gamepad-2', 'title' => 'Full Control', 'text' => 'Jedes Feature ist togglebar. Du entscheidest, was aktiv ist – vollstaendige Kontrolle ueber dein System.'],
            ['icon' => 'trophy',    'title' => 'High Score',   'text' => 'Analytik, Statistiken und Auswertungen – behalte deinen Score im Blick und verbessere dich kontinuierlich.'],
        ] : [
            ['icon' => 'heart',     'title' => 'Extra Lives',  'text' => 'Regular backups and versioning – your content is always safe. No game over, no data loss.'],
            ['icon' => 'star',      'title' => 'Star Power',   'text' => 'Lightning-fast load times and optimized caching ensure maximum performance – your website is unstoppable.'],
            ['icon' => 'shield',    'title' => 'Shield',       'text' => 'CSRF protection, prepared statements, and hardened security keep attackers out of the game.'],
            ['icon' => 'zap',       'title' => 'Speed Boost',  'text' => 'Server-side rendering without framework overhead. Your site simply leaves others behind.'],
            ['icon' => 'gamepad-2', 'title' => 'Full Control', 'text' => 'Every feature is toggleable. You decide what is active – full control over your system.'],
            ['icon' => 'trophy',    'title' => 'High Score',   'text' => 'Analytics, statistics, and evaluations – keep your score in sight and continuously improve.'],
        ],
        'color_scheme' => 'alt',
        'card_style'   => 'bordered',
    ], 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]
    );

    // Topic Cards
    $topicContent = json_encode([
        'title' => $isDE ? 'Auswaehlen und losspielen' : 'Select and Play',
        'items' => $isDE ? [
            ['icon' => 'gamepad-2', 'title' => 'Retro Games', 'text' => 'Klassiker von Atari, NES, SNES und Mega Drive – die Original-Hardware und ihre besten Spiele im Spotlight.',        'url' => '/spiele'],
            ['icon' => 'image',     'title' => 'Pixel Art',   'text' => 'Tutorials, Workshops und eine Galerie mit den besten Pixel-Art-Werken unserer Community.',                             'url' => '/community'],
            ['icon' => 'users',     'title' => 'Community',   'text' => 'Discord, Game Jams und monatliche Events – verbinde dich mit anderen Retro-Enthusiasten in aller Welt.',              'url' => '/community'],
        ] : [
            ['icon' => 'gamepad-2', 'title' => 'Retro Games', 'text' => 'Classics from Atari, NES, SNES, and Mega Drive – the original hardware and its best games in the spotlight.',        'url' => '/games'],
            ['icon' => 'image',     'title' => 'Pixel Art',   'text' => 'Tutorials, workshops, and a gallery with the best pixel art works from our community.',                               'url' => '/community'],
            ['icon' => 'users',     'title' => 'Community',   'text' => 'Discord, game jams, and monthly events – connect with other retro enthusiasts from around the world.',               '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]
    );

    // Blog Preview
    $blogContent = json_encode([
        'title'    => $isDE ? 'Neueste Beitraege' : 'Latest Posts',
        '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
    $eventsContent = json_encode([
        'title'    => $isDE ? 'Naechste Events' : 'Upcoming 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: Game Over? Nein!
    $ctaContent = json_encode([
        'title'              => $isDE ? 'Game Over? Nein! Jetzt Mitspielen.' : 'Game Over? No! Join Now.',
        'text'               => $isDE
            ? 'Steck eine Muenze ein und tritt unserer Community bei. Retro-Gaming-Events, Pixel-Art-Workshops, Game Jams – es gibt immer ein neues Level zu entdecken. Insert coin and continue!'
            : 'Insert a coin and join our community. Retro gaming events, pixel art workshops, game jams – there is always a new level to discover. Insert coin and continue!',
        'cta_text'           => '[ INSERT COIN ]',
        '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: GAME STATS ──

    $statsContent = json_encode([
        'title'              => 'GAME STATS',
        'subtitle'           => '',
        'color_scheme'       => '',
        'section_text_color' => '',
        'section_surface'    => '',
        'text_align'         => 'center',
        'columns'            => '4',
        'items'              => [
            ['value' => '12480', 'label' => $isDE ? 'Beitraege'  : 'Posts',     'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '98750', 'label' => $isDE ? 'Besucher'   : 'Visitors',  'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '5320',  'label' => $isDE ? 'Downloads'  : 'Downloads', 'icon' => '', 'prefix' => '', 'suffix' => ''],
            ['value' => '3140',  'label' => $isDE ? 'Kommentare' : 'Comments',  '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' => 'GAME STATS',
            'content'        => $statsContent,
            'is_active'      => 1,
            'sort_order'     => 3,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }

    // ── Testimonials: Player Reviews ──

    $testimonialsContent = json_encode([
        'title'              => 'Player Reviews',
        'subtitle'           => $isDE ? '– was unsere Community sagt –' : '– what our community says –',
        'color_scheme'       => 'primary',
        'section_text_color' => '',
        'section_surface'    => '',
        'text_align'         => '',
        'columns'            => '3',
        'layout'             => 'grid',
        'items'              => $isDE ? [
            [
                'quote'  => 'Das beste Retro-Gaming-Portal das ich je gefunden habe. Die Events sind super organisiert, die Community freundlich und die Pixel-Art-Workshops haben mein Hobby auf ein neues Level gehoben. 10/10 – would play again!',
                'author' => 'PixelHero_42',
                'role'   => 'Community-Mitglied, Level 99',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'Endlich eine Seite, die Retro-Gaming so ernst nimmt wie ich. Die Spielerezensionen sind tiefgruendig, die Guides praxisnah und der Arcade Jam war das Highlight meines Jahres. Respekt ans Team!',
                'author' => 'RetroQueen_8bit',
                'role'   => 'Pixel-Artist und Game-Jam-Siegerin',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'INSERT COIN, SELECT CHARACTER, FIGHT! Genau so fuehlt sich diese Community an. Ich bin nach der ersten Retro Gaming Night nie mehr weggegangen. Danke fuer drei Leben plus Continues!',
                'author' => 'CoinOp_Master',
                'role'   => 'Arcade-Sammler und Highscore-Jaeger',
                'avatar' => '',
                'rating' => 5,
            ],
        ] : [
            [
                'quote'  => 'The best retro gaming portal I have ever found. The events are superbly organized, the community is friendly, and the pixel art workshops took my hobby to the next level. 10/10 – would play again!',
                'author' => 'PixelHero_42',
                'role'   => 'Community Member, Level 99',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'Finally a site that takes retro gaming as seriously as I do. The game reviews are in-depth, the guides are practical, and the Arcade Jam was the highlight of my year. Respect to the team!',
                'author' => 'RetroQueen_8bit',
                'role'   => 'Pixel Artist and Game Jam Winner',
                'avatar' => '',
                'rating' => 5,
            ],
            [
                'quote'  => 'INSERT COIN, SELECT CHARACTER, FIGHT! That is exactly what this community feels like. I never left after the first Retro Gaming Night. Thanks for three lives plus continues!',
                'author' => 'CoinOp_Master',
                'role'   => 'Arcade Collector and Highscore Hunter',
                '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' => 'Player Reviews',
            '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'),
        ]);
    }

    // ── High Score: Arcade-exclusive section ──

    $highScoreContent = json_encode([
        'title'              => 'HALL OF FAME',
        'subtitle'           => '- TOP SCORES -',
        'color_scheme'       => '',
        'section_text_color' => '',
        'items'              => [
            ['rank' => 1, 'initials' => 'BNY', 'score' => '12.480', 'label' => $isDE ? 'Beitraege'  : 'Posts'],
            ['rank' => 2, 'initials' => 'USR', 'score' => '98.750', 'label' => $isDE ? 'Besucher'   : 'Visitors'],
            ['rank' => 3, 'initials' => 'DWN', 'score' => '5.320',  'label' => $isDE ? 'Downloads'  : 'Downloads'],
            ['rank' => 4, 'initials' => 'CMT', 'score' => '3.140',  'label' => $isDE ? 'Kommentare' : 'Comments'],
            ['rank' => 5, 'initials' => 'SHR', 'score' => '1.890',  'label' => $isDE ? 'Shares'     : 'Shares'],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $highScoreExists = $db->fetch("SELECT id FROM iw_page_sections WHERE section_type = 'high_score' AND page_context = 'homepage' LIMIT 1");
    if ($highScoreExists) {
        $db->query(
            "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'high_score' AND page_context = 'homepage'",
            ['c' => $highScoreContent]
        );
    } else {
        $db->insert('iw_page_sections', [
            'page_context'   => 'homepage',
            'section_type'   => 'high_score',
            'instance_label' => 'Hall of Fame',
            'content'        => $highScoreContent,
            'is_active'      => 1,
            'sort_order'     => 6,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }

    // ── Team: Party Members ──

    $teamContent = json_encode([
        'title'              => $isDE ? 'Party Members' : 'Party Members',
        'subtitle'           => $isDE ? 'Waehle deinen Charakter' : 'Choose your character',
        'color_scheme'       => 'alt',
        'section_text_color' => '',
        'columns'            => '3',
        'layout'             => 'cards',
        'items'              => $isDE ? [
            [
                'name'   => 'GameMaster_X',
                'role'   => 'Game Master',
                'text'   => 'Der Endboss der Spielleitung. Entwickelt Regelwerke, designed Events und ist verantwortlich dafuer, dass alle im Spiel bleiben. 20 Jahre Erfahrung, Level MAX.',
                'avatar' => '',
                'icon'   => 'crown',
            ],
            [
                'name'   => 'PixelWitch',
                'role'   => 'Pixel Artist',
                'text'   => 'Erschafft Welten mit 16 Farben. Von Character-Sprites ueber Tilesets bis zu ganzen Environments – ihre Kreationen atmen 8-Bit-Nostalgie.',
                'avatar' => '',
                'icon'   => 'sparkles',
            ],
            [
                'name'   => 'CodeWizard',
                'role'   => 'Code Wizard',
                'text'   => 'Schreibt Game-Engines in reinem PHP und findet Freude an jeder Optimierung. Sein Lebensmotto: "Every byte counts." Spezialmagie: Performance-Debugging.',
                'avatar' => '',
                'icon'   => 'code',
            ],
        ] : [
            [
                'name'   => 'GameMaster_X',
                'role'   => 'Game Master',
                'text'   => 'The final boss of game management. Develops rule systems, designs events, and ensures everyone stays in the game. 20 years experience, Level MAX.',
                'avatar' => '',
                'icon'   => 'crown',
            ],
            [
                'name'   => 'PixelWitch',
                'role'   => 'Pixel Artist',
                'text'   => 'Creates worlds with 16 colors. From character sprites to tilesets to entire environments – her creations breathe 8-bit nostalgia.',
                'avatar' => '',
                'icon'   => 'sparkles',
            ],
            [
                'name'   => 'CodeWizard',
                'role'   => 'Code Wizard',
                'text'   => 'Writes game engines in pure PHP and finds joy in every optimization. Life motto: "Every byte counts." Special magic: performance debugging.',
                'avatar' => '',
                'icon'   => 'code',
            ],
        ],
    ], JSON_UNESCAPED_UNICODE);

    $teamExists = $db->fetch("SELECT id FROM iw_page_sections WHERE section_type = 'team_section' AND page_context = 'homepage' LIMIT 1");
    if ($teamExists) {
        $db->query(
            "UPDATE iw_page_sections SET content = :c, is_active = 1 WHERE section_type = 'team_section' AND page_context = 'homepage'",
            ['c' => $teamContent]
        );
    } else {
        $db->insert('iw_page_sections', [
            'page_context'   => 'homepage',
            'section_type'   => 'team_section',
            'instance_label' => 'Party Members',
            'content'        => $teamContent,
            'is_active'      => 1,
            'sort_order'     => 9,
            'created_at'     => date('Y-m-d H:i:s'),
            'updated_at'     => date('Y-m-d H:i:s'),
        ]);
    }

    // ── Trust Showcase: Arcade Achievement Badges ──

    $trustContent = json_encode([
        'title'              => $isDE ? 'Achievements freigeschaltet' : 'Achievements Unlocked',
        'subtitle'           => '',
        'color_scheme'       => '',
        'section_text_color' => '',
        'layout'             => 'badges',
        'items'              => [
            ['icon' => 'trophy', 'text' => '1st Place Winner'],
            ['icon' => 'shield', 'text' => 'Security Expert'],
            ['icon' => 'zap',    'text' => 'Speed Runner'],
            ['icon' => 'star',   'text' => 'All Stars'],
            ['icon' => 'heart',  'text' => 'Extra Life'],
            ['icon' => 'award',  'text' => 'Game Complete'],
        ],
    ], JSON_UNESCAPED_UNICODE);

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