<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('site_settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->longText('value')->nullable();
            $table->timestamps();
        });

        // Seed defaults
        $defaults = [
            'hero_slides' => json_encode([
                ['url' => '/images/classroom.png', 'title' => 'Nurturing Futures in rural Bangladesh', 'subtitle' => 'Providing quality education and school supplies to children in underprivileged communities.'],
                ['url' => '/images/water.png', 'title' => 'Providing Safe Water and Healthier Lives', 'subtitle' => 'Installing deep tube wells and sanitation facilities to ensure clean drinking water.'],
            ]),
            'hero_badge'        => 'Empowering Lives Since 2012',
            'hero_trust_stats'  => json_encode([
                ['value' => '100%',    'label' => 'Direct-to-Cause model'],
                ['value' => '25,000+', 'label' => 'Lives impacted in Bangladesh'],
                ['value' => 'Govt. Reg','label' => 'No. 2932 / Non-Profit status'],
            ]),
            'hero_quick_donate_title'    => 'Quick Donation',
            'hero_quick_donate_subtitle' => 'Donate securely in 10 seconds',
            'hero_amount_presets'        => json_encode([500, 1000, 5000, 10000]),
            'nav_logo_letter'   => 'H',
            'nav_logo_text'     => 'HORIZON WELFARE',
            'nav_cta_text'      => 'Donate Now',
            'nav_links'         => json_encode([
                ['label' => 'Home',      'view' => 'home',      'visible' => true],
                ['label' => 'About Us',  'view' => 'about',     'visible' => true],
                ['label' => 'Volunteer', 'view' => 'volunteer', 'visible' => true],
            ]),
        ];

        foreach ($defaults as $key => $value) {
            DB::table('site_settings')->insert(['key' => $key, 'value' => $value, 'created_at' => now(), 'updated_at' => now()]);
        }
    }

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