<?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::table('website_settings', function (Blueprint $table) {
            // Navbar enhancements
            $table->string('navbar_cta_text', 100)->nullable()->after('navbar_style');
            $table->string('navbar_cta_link', 500)->nullable()->after('navbar_cta_text');
            $table->boolean('navbar_show_social')->default(false)->after('navbar_cta_link');
            $table->string('navbar_logo_position', 10)->default('start')->after('navbar_show_social');

            // Footer builder
            $table->smallInteger('footer_columns')->default(4)->after('custom_css');
            $table->jsonb('footer_blocks')->default('[]')->after('footer_columns');
            $table->string('footer_bottom_text', 500)->nullable()->after('footer_blocks');
            $table->string('footer_style', 20)->default('dark')->after('footer_bottom_text');
        });

        // Update navbar_style CHECK to support 8 variants
        DB::statement("ALTER TABLE website_settings DROP CONSTRAINT IF EXISTS website_settings_navbar_style_check");
        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_navbar_style_check CHECK (navbar_style IN ('solid', 'transparent', 'floating', 'centered', 'hamburger_always', 'side_drawer', 'minimal', 'mega'))");

        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_navbar_logo_position_check CHECK (navbar_logo_position IN ('start', 'center', 'end'))");
        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_footer_style_check CHECK (footer_style IN ('dark', 'light', 'accent', 'transparent'))");
    }

    public function down(): void
    {
        DB::statement("ALTER TABLE website_settings DROP CONSTRAINT IF EXISTS website_settings_navbar_logo_position_check");
        DB::statement("ALTER TABLE website_settings DROP CONSTRAINT IF EXISTS website_settings_footer_style_check");

        Schema::table('website_settings', function (Blueprint $table) {
            $table->dropColumn([
                'navbar_cta_text', 'navbar_cta_link', 'navbar_show_social', 'navbar_logo_position',
                'footer_columns', 'footer_blocks', 'footer_bottom_text', 'footer_style',
            ]);
        });

        DB::statement("ALTER TABLE website_settings DROP CONSTRAINT IF EXISTS website_settings_navbar_style_check");
        DB::statement("ALTER TABLE website_settings ADD CONSTRAINT website_settings_navbar_style_check CHECK (navbar_style IN ('solid', 'transparent', 'floating'))");
    }
};
