<?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_navigation_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('navigation_id')->constrained('flux_cms_navigations')->onDelete('cascade');
            $table->foreignId('page_id')->nullable()->constrained('flux_cms_pages')->onDelete('cascade');
            $table->string('external_url')->nullable();
            $table->json('label'); // Übersetzbarer Menütext
            $table->integer('order')->default(0);
            $table->foreignId('parent_id')->nullable()->constrained('flux_cms_navigation_items')->onDelete('cascade');
            $table->json('settings')->nullable(); // Item-spezifische Einstellungen
            $table->boolean('is_active')->default(true);
            $table->boolean('opens_in_new_tab')->default(false);
            $table->timestamps();

            // Indexes
            $table->index(['navigation_id', 'order']);
            $table->index(['navigation_id', 'parent_id']);
            $table->index(['navigation_id', 'is_active']);
        });
    }

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