<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // Drop dummy table if it was created
        Schema::dropIfExists('landing_pages_and_sections_tables');
        Schema::dropIfExists('landing_page_sections');
        Schema::dropIfExists('landing_pages');

        Schema::create('landing_pages', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('slug')->unique();
            $table->foreignId('product_id')->nullable()->constrained('products')->nullOnDelete();
            $table->decimal('landing_price', 10, 2)->nullable();
            $table->string('fb_pixel_id')->nullable();
            $table->boolean('is_active')->default(true);
            
            // Theme settings for professional styling customization
            $table->string('template_style')->default('minimalist'); // 'minimalist', 'organic', 'bold'
            $table->string('primary_color')->default('#4f46e5');
            $table->string('secondary_color')->default('#06b6d4');
            $table->integer('gradient_angle')->default(135);
            $table->string('font_family')->default('Inter');
            
            $table->timestamps();
        });

        Schema::create('landing_page_sections', function (Blueprint $table) {
            $table->id();
            $table->foreignId('landing_page_id')->constrained('landing_pages')->onDelete('cascade');
            $table->string('block_type');
            $table->json('content');
            $table->integer('sort_order')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('landing_page_sections');
        Schema::dropIfExists('landing_pages');
    }
};
