<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $exists = DB::table('admin_menu')
            ->where('title', 'Style Guide')
            ->where('sub_id', 1)
            ->exists();

        if (!$exists) {
            $nextOrder = DB::table('admin_menu')
                ->where('sub_id', 1)
                ->max('order') + 1;

            DB::table('admin_menu')->insert([
                'sub_id' => 1,
                'title' => 'Style Guide',
                'path' => '/core/admin/styleguide.php',
                'activePath' => '/core/admin/styleguide.php',
                'constant' => '',
                'icon' => 'fa fa-paint-brush',
                'new_window' => 1,
                'order' => $nextOrder,
            ]);
        }
    }

    public function down(): void
    {
        DB::table('admin_menu')
            ->where('title', 'Style Guide')
            ->where('sub_id', 1)
            ->delete();
    }
};
