<?php

namespace Tests\Feature\Marketing;

use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class MarketingLocaleRoutingTest extends TestCase
{
    use RefreshDatabase;
    public function test_home_route_accepts_german_locale_prefix(): void
    {
        $response = $this->get('/de');

        $response->assertOk();
        $response->assertInertia(fn (Assert $page) => $page
            ->component('marketing/Home')
            ->where('locale', 'de')
            ->where('supportedLocales.0', 'de')
        );
    }

    public function test_home_route_accepts_english_locale_prefix(): void
    {
        $response = $this->get('/en');

        $response->assertOk();
        $response->assertInertia(fn (Assert $page) => $page
            ->component('marketing/Home')
            ->where('locale', 'en')
            ->where('supportedLocales.1', 'en')
        );
    }

    public function test_contact_route_respects_locale_and_component(): void
    {
        $response = $this->get('/en/contact');

        // Debug response headers for redirect source during development
        // @phpstan-ignore-next-line
        // var_dump($response->headers->all());

        $response->assertOk();
        $response->assertInertia(fn (Assert $page) => $page
            ->component('marketing/Kontakt')
            ->where('locale', 'en')
        );

        $responseDe = $this->get('/de/kontakt');

        $responseDe->assertOk();
        $responseDe->assertInertia(fn (Assert $page) => $page
            ->component('marketing/Kontakt')
            ->where('locale', 'de')
        );
    }
}
