<?php

namespace Tests\Feature;

use App\Models\Merchant;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

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

        $merchant = Merchant::query()->firstOrFail();

        $order = PlatformOrder::query()->create([
            'merchant_id' => $merchant->id,
            'plan_id' => null,
            'site_subscription_id' => null,
            'order_no' => 'PO_INDEX_NO_RECEIPT_FIX_LINK',
            'order_type' => 'new_purchase',
            'status' => 'pending',
            'payment_status' => 'paid',
            'payable_amount' => 10,
            'paid_amount' => 10,
            'paid_at' => now(),
            'meta' => [], // 无 payment_receipts / payment_summary
        ]);

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

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

        // 已付无回执行应提供“去补回执”入口，且锚点必须为 #add-payment-receipt（避免误跳到其它 section）。
        $this->assertStringContainsString('已付无回执', $html);
        $this->assertStringContainsString('/admin/platform-orders/' . $order->id, $html);
        $this->assertStringContainsString('#add-payment-receipt', $html);
    }
}
