<?php

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

/**
 * Add the Block Manager link under the existing "mtc. only" admin section.
 *
 * Visibility is gated by the existing Menu::getAdminMenu() filter (core/src/Admin/Menu.php:390)
 * which hides any node with parent sub_id=1 from non-MTC admins — no extra
 * permission row needed. Idempotent: updateOrInsert keyed on `path`.
 */
return new class extends Migration
{
    private const MTC_ONLY_PARENT_ID = 1;
    private const PATH = '/admin/block-manager';

    public function up(): void
    {
        DB::table('admin_menu')->updateOrInsert(
            ['path' => self::PATH],
            [
                'sub_id'     => self::MTC_ONLY_PARENT_ID,
                'title'      => 'Block Manager',
                'activePath' => self::PATH,
                'constant'   => '',
                'icon'       => 'fa fa-cube',
                'new_window' => 0,
                'order'      => 200,
            ]
        );
    }

    public function down(): void
    {
        DB::table('admin_menu')->where('path', self::PATH)->delete();
    }
};
