<?php

/**
 * Migration 052: Register stats and testimonials section types
 *
 * These section types were added as Extended sections in the PHP registry
 * but were missing from the iw_section_types table, making them invisible
 * in the PageBuilder "Add Section" modal on existing installations.
 */

use App\Database\Migration;

class AddStatsTestimonialsSectionTypes extends Migration
{
    public function up(): void
    {
        $exists = $this->db->fetch(
            "SELECT id FROM iw_section_types WHERE type_key = 'stats' LIMIT 1"
        );
        if (!$exists) {
            $this->db->insert('iw_section_types', [
                'type_key'       => 'stats',
                'label'          => 'Kennzahlen',
                'description'    => 'Grosse Zahlen mit Labels – ideal fuer Statistiken und Erfolge',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M18 20V10M12 20V4M6 20v-6"/></svg>',
                'source'         => 'core',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 28,
            ]);
        }

        $exists = $this->db->fetch(
            "SELECT id FROM iw_section_types WHERE type_key = 'testimonials' LIMIT 1"
        );
        if (!$exists) {
            $this->db->insert('iw_section_types', [
                'type_key'       => 'testimonials',
                'label'          => 'Testimonials',
                'description'    => 'Kundenstimmen mit Zitat, Autor und optionalem Avatar',
                'category'       => 'content',
                'icon_svg'       => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
                'source'         => 'core',
                'allow_multiple' => 1,
                'is_available'   => 1,
                'sort_order'     => 29,
            ]);
        }
    }

    public function down(): void
    {
        $this->db->query("DELETE FROM iw_section_types WHERE type_key IN ('stats', 'testimonials')");
    }
}
