<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('app_sections', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->string('title');
            $table->string('background_color', 20)->nullable();
            $table->boolean('is_active')->default(true);
            $table->unsignedInteger('order_no')->nullable();
            $table->timestamps();
        });

        $now = now();

        DB::table('app_sections')->insert([
            [
                'key' => 'hero_principal',
                'title' => 'Hero principal',
                'background_color' => '#ffffff',
                'is_active' => true,
                'order_no' => 1,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'app',
                'title' => 'App',
                'background_color' => '#fff7f2',
                'is_active' => true,
                'order_no' => 2,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'promociones_beneficios',
                'title' => 'Promociones y beneficios',
                'background_color' => '#ffffff',
                'is_active' => true,
                'order_no' => 3,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'como_usar',
                'title' => 'Cómo usar la app',
                'background_color' => '#fff7f2',
                'is_active' => true,
                'order_no' => 4,
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'preguntas_frecuentes',
                'title' => 'Preguntas frecuentes',
                'background_color' => '#ffffff',
                'is_active' => true,
                'order_no' => 5,
                'created_at' => $now,
                'updated_at' => $now,
            ],
        ]);
    }

    public function down(): void
    {
        Schema::dropIfExists('app_sections');
    }
};
