<?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
    {
        Schema::create('menus', function (Blueprint $table) {
            $table->id();
            $table->string('slug', 50)->unique()->nullable(); // Lokasi halaman yang akan ditampilkan
            $table->string('name', 150);
            $table->string('url',50)->nullable(); // Lokasi halaman yang akan ditampilkan
            $table->string('route')->nullable(); // bisa null untuk menu parent
            $table->foreignId('parent_id')->nullable()->constrained('menus')->onDelete('cascade');
            $table->boolean('is_global')->default(false); // menu untuk semua user
            $table->boolean('is_active')->default(true);
            $table->integer('level')->nullable(); // Menandakan apakah ini menu utama
            $table->string('tipe', 50)->default('main'); // Jenis menu: 'portal' atau 'admin'
            $table->string('view_path', 150)->nullable();
            $table->string('view_file', 100)->nullable()->default('default');
            $table->string('icon', 50)->nullable()->default('ti-smart-home');
            $table->integer('order')->default(0); // urutan tampilan menu
            $table->timestamps();
        });

        Schema::create('role_menu', function (Blueprint $table) {
            $table->id();
            $table->foreignId('role_id')->constrained()->onDelete('cascade');
            $table->foreignId('menu_id')->constrained()->onDelete('cascade');
            $table->timestamps();
        });        
    }

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