<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('site_settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->text('value')->nullable();
            $table->string('type')->default('text'); // text, image, boolean, json
            $table->string('group')->default('general'); // general, branding, social, etc.
            $table->string('label')->nullable();
            $table->text('description')->nullable();
            $table->timestamps();
        });

        // Insérer les paramètres par défaut
        $settings = [
            // Branding
            ['key' => 'site_name', 'value' => 'ATARA LifeStyle', 'type' => 'text', 'group' => 'branding', 'label' => 'Nom du site'],
            ['key' => 'site_logo', 'value' => 'images/logo.png', 'type' => 'image', 'group' => 'branding', 'label' => 'Logo du site'],
            ['key' => 'site_logo_dark', 'value' => null, 'type' => 'image', 'group' => 'branding', 'label' => 'Logo (mode sombre)'],
            ['key' => 'site_favicon', 'value' => 'favicon.svg', 'type' => 'image', 'group' => 'branding', 'label' => 'Favicon'],
            ['key' => 'show_logo_text', 'value' => '0', 'type' => 'boolean', 'group' => 'branding', 'label' => 'Afficher le nom à côté du logo'],
            ['key' => 'logo_height', 'value' => '40', 'type' => 'text', 'group' => 'branding', 'label' => 'Hauteur du logo (px)'],
            
            // Contact
            ['key' => 'contact_email', 'value' => 'contact@atara.com', 'type' => 'text', 'group' => 'contact', 'label' => 'Email de contact'],
            ['key' => 'contact_phone', 'value' => '+225 XX XX XX XX XX', 'type' => 'text', 'group' => 'contact', 'label' => 'Téléphone'],
            ['key' => 'contact_address', 'value' => 'Abidjan, Côte d\'Ivoire', 'type' => 'text', 'group' => 'contact', 'label' => 'Adresse'],
            
            // Social
            ['key' => 'social_facebook', 'value' => '', 'type' => 'text', 'group' => 'social', 'label' => 'Facebook'],
            ['key' => 'social_instagram', 'value' => '', 'type' => 'text', 'group' => 'social', 'label' => 'Instagram'],
            ['key' => 'social_twitter', 'value' => '', 'type' => 'text', 'group' => 'social', 'label' => 'Twitter/X'],
            ['key' => 'social_whatsapp', 'value' => '', 'type' => 'text', 'group' => 'social', 'label' => 'WhatsApp'],
        ];

        foreach ($settings as $setting) {
            \DB::table('site_settings')->insert(array_merge($setting, [
                'created_at' => now(),
                'updated_at' => now()
            ]));
        }
    }

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