<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $section = DB::table('admin_menu')->where('title', 'like', '%mtc%')->where('sub_id', 0)->value('id');

        if (!$section) {
            return; // no mtc-only section on this install; skip gracefully
        }

        if (DB::table('admin_menu')->where('path', '/admin/site-readiness')->exists()) {
            return;
        }

        DB::table('admin_menu')->insert([
            'sub_id'     => $section,
            'title'      => 'Site Readiness',
            'path'       => '/admin/site-readiness',
            'activePath' => '/admin/site-readiness',
            'constant'   => '',
            'icon'       => 'fa fa-heartbeat',
            'new_window' => 0,
            'order'      => 100,
        ]);
    }

    public function down(): void
    {
        DB::table('admin_menu')->where('path', '/admin/site-readiness')->delete();
    }
};
