<?php

namespace Tests\Feature;

use App\Models\Branch;
use App\Models\Business;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class SuperAdministratorDashboardTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed(DatabaseSeeder::class);
    }

    public function test_super_administrator_dashboard_is_system_wide_and_blade_is_fully_compiled(): void
    {
        $business = Business::firstOrFail();

        $branchA = Branch::create([
            'business_id' => $business->id,
            'name' => 'Dashboard Oversight North',
            'status' => 'active',
        ]);

        $branchB = Branch::create([
            'business_id' => $business->id,
            'name' => 'Dashboard Oversight South',
            'status' => 'active',
        ]);

        $admin = User::where('email', 'admin@microfinance.local')->firstOrFail();

        $response = $this->actingAs($admin)->get(route('dashboard'));

        $response
            ->assertOk()
            ->assertSee('Dashboard')
            ->assertSee('Full system oversight')
            ->assertSee('System Overview')
            ->assertSee('Financial & Portfolio KPIs', false)
            ->assertSee('Collections & Disbursements', false)
            ->assertSee('Income vs Expenses')
            ->assertSee('Portfolio Performance')
            ->assertSee('Loan Portfolio Mix')
            ->assertSee('Branch Performance')
            ->assertSee('Management Alerts')
            ->assertSee('Recent System Activity')
            ->assertSee($branchA->name)
            ->assertSee($branchB->name)
            ->assertDontSee('@foreach', false)
            ->assertDontSee('@endforeach', false)
            ->assertDontSee('@php', false)
            ->assertDontSee('@endphp', false)
            ->assertDontSee('{{ $', false);
    }
}
