<?php

namespace Tests\Feature;

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

class AdminDashboardSubscriptionExpiryMiniBarsShouldRenderTest 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_dashboard_should_render_subscription_expiry_mini_bars(): void
    {
        $this->loginAsPlatformAdmin();

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

        $html = (string) $res->getContent();

        $this->assertStringContainsString('data-role="dashboard-sub-expiry-bars"', $html);
        $this->assertStringContainsString('data-role="dashboard-sub-expiring-7d-bar"', $html);
        $this->assertStringContainsString('data-role="dashboard-sub-expired-bar"', $html);

        // 行可点击：直达订阅到期治理集合（含安全 back）
        $this->assertStringContainsString('href="/admin/site-subscriptions?expiry=expiring_7d&back=%2Fadmin"', $html);
        $this->assertStringContainsString('href="/admin/site-subscriptions?expiry=expired&back=%2Fadmin"', $html);

        $css = (string) file_get_contents(public_path('css/admin-components.css'));
        $this->assertStringContainsString('.adm-mini-bar-row{', $css);
        $this->assertStringContainsString('.adm-mini-bar-label{', $css);
        $this->assertStringContainsString('.adm-mini-bar-value{', $css);
    }
}
