<?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('flux_cms_page_components', function (Blueprint $table) {
            $table->id();
            $table->foreignId('page_id')->constrained('flux_cms_pages')->onDelete('cascade');
            $table->string('component_class'); // Full namespace of the component class
            $table->integer('order')->default(0);
            $table->json('content'); // Alle übersetzten Inhalte der Komponente
            $table->json('settings')->nullable(); // Komponenten-spezifische Einstellungen
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            // Indexes for performance
            $table->index(['page_id', 'order']);
            $table->index(['page_id', 'is_active']);
            $table->index(['component_class']);
        });
    }

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