<?php

namespace Mtc\Plugins\BlockManager\Tests\Feature;

use Illuminate\Support\Facades\Route;
use Tests\TestCase;

class AdminMountPointTest extends TestCase
{
    public function test_admin_route_is_registered(): void
    {
        $found = collect(Route::getRoutes())->contains(
            fn ($route) => $route->uri() === 'admin/block-manager'
        );

        $this->assertTrue(
            $found,
            'Admin route /admin/block-manager is not registered — '
            . 'BlockManagerServiceProvider::boot() should loadRoutesFrom(__DIR__.\'/../routes/web.php\').'
        );
    }

    public function test_admin_index_route_returns_200(): void
    {
        $response = $this->withoutMiddleware()->get('/admin/block-manager');
        $response->assertStatus(200);
    }

    public function test_admin_index_emits_mount_div(): void
    {
        $body = $this->withoutMiddleware()->get('/admin/block-manager')->getContent();

        $this->assertStringContainsString(
            'id="block-manager-app"',
            $body,
            'Admin shell did not emit the Vue mount div.'
        );
        $this->assertStringContainsString(
            'data-initial-tab="blocks"',
            $body,
            'Admin shell did not set data-initial-tab="blocks" on the mount div.'
        );
    }

    public function test_admin_index_includes_vite_admin_bundle(): void
    {
        $body = $this->withoutMiddleware()->get('/admin/block-manager')->getContent();

        $this->assertStringContainsString(
            'block_manager_admin',
            $body,
            'Admin shell did not reference the block_manager_admin Vite bundle — '
            . 'the manager.twig view should call {{ vite("sites/default/js/block_manager_admin.js") }}.'
        );
    }
}
