<?php

namespace Tests\Feature;

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

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

        // 仅给 paid + pending，但不带 sync_status=unsynced。
        // 治理口径：批量仅标记为已生效必须锁定待生效集合（paid + pending + unsynced），避免把失败/已同步等异常单混入。
        $res = $this->get('/admin/platform-orders?payment_status=paid&status=pending');
        $res->assertOk();

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

        $this->assertStringContainsString('批量仅标记为已生效（当前筛选范围）', $html);
        $this->assertStringContainsString('data-role="batch-mark-activated-blocked-hint"', $html);
        $this->assertStringContainsString('sync_status=unsynced', $html);

        $this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
    }
}
