<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminDashboardKpiCardsShouldBeEqualHeightByCssGuardTest extends TestCase
{
    use RefreshDatabase;

    protected function loginAsPlatformAdmin(): void
    {
        $this->seed();

        $this->post('/admin/login', [
            'email' => 'platform.admin@demo.local',
            'password' => 'Platform@123456',
        ])->assertRedirect('/admin');
    }

    public function test_kpi_grid_should_enable_equal_height_cards_via_css(): void
    {
        $this->loginAsPlatformAdmin();

        $res = $this->get('/admin');
        $res->assertOk();

        // 结构护栏：KPI 区必须存在
        $res->assertSee('data-role="kpi-grid"', false);

        $css = (string) file_get_contents(public_path('css/admin-components.css'));

        // 护栏：kpi-grid 应显式 stretch，且卡片应为 flex column（保证等高和脚注沉底）
        $this->assertStringContainsString('.kpi-grid{', $css);
        $this->assertStringContainsString('align-items:stretch', $css);

        // 关键：grid 场景必须清理 admin-base.css 的 `.card + .card{margin-top:20px;}` 纵向堆叠规则
        // 否则会出现“第一张卡在上、第二张卡整体下沉”的错位。
        $this->assertStringContainsString('.kpi-grid .card{', $css);
        $this->assertStringContainsString('margin-top:0', $css);
        $this->assertStringContainsString('.two-col .card{', $css);
        $this->assertStringContainsString('margin-top:0', $css);

        $this->assertStringContainsString('.kpi-grid .card', $css);
        $this->assertStringContainsString('display:flex', $css);
        $this->assertStringContainsString('flex-direction:column', $css);
        $this->assertStringContainsString('.kpi-grid .stat-card-footnote', $css);
        $this->assertStringContainsString('margin-top:auto', $css);
    }
}
