<?php

namespace Tests\Feature;

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

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

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

        $plan = Plan::query()->create([
            'code' => 'po_index_compact_time_format_plan',
            'name' => '平台订单列表时间格式测试套餐',
            'billing_cycle' => 'monthly',
            'price' => 10,
            'list_price' => 10,
            'status' => 'active',
            'sort' => 10,
            'published_at' => now(),
        ]);

        $placedAt = now()->setDate(2026, 3, 14)->setTime(11, 22, 33);
        $paidAt = now()->setDate(2026, 3, 14)->setTime(12, 34, 56);

        PlatformOrder::query()->create([
            'merchant_id' => $merchant->id,
            'plan_id' => $plan->id,
            'order_no' => 'PO_INDEX_TIME_FORMAT_0001',
            'order_type' => 'new_purchase',
            'status' => 'activated',
            'payment_status' => 'paid',
            'plan_name' => $plan->name,
            'billing_cycle' => $plan->billing_cycle,
            'period_months' => 1,
            'quantity' => 1,
            'payable_amount' => 10,
            'paid_amount' => 10,
            'placed_at' => $placedAt,
            'paid_at' => $paidAt,
            'activated_at' => now(),
            'meta' => [],
        ]);

        // 精简视图：只显示日期
        $this->get('/admin/platform-orders')
            ->assertOk()
            ->assertSee('2026-03-14', false)
            ->assertDontSee('11:22:33', false)
            ->assertDontSee('12:34:56', false);

        // full 视图：显示日期 + 时间
        $this->get('/admin/platform-orders?view=full')
            ->assertOk()
            ->assertSee('2026-03-14 11:22:33', false)
            ->assertSee('2026-03-14 12:34:56', false);
    }
}
