<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class AuthHelpLinksContractTest extends TestCase
{
    use ProjectFileAssertionSupport;

    public function testAuthHelpLinksPartialSupportsContextFlags(): void
    {
        $content = $this->readProjectFile('templates/partials/auth-help-links.phtml');

        $this->assertStringContainsString('$authHelpContext', $content);
        $this->assertStringContainsString("'show_forgot'", $content);
        $this->assertStringContainsString("'show_register'", $content);
        $this->assertStringContainsString("'show_back_to_login'", $content);
        $this->assertStringContainsString("'show_support'", $content);
    }

    public function testRegisterLinkRemainsGuardedByRegistrationFlag(): void
    {
        $content = $this->readProjectFile('templates/partials/auth-help-links.phtml');

        $this->assertStringContainsString('allowRegistration()', $content);
        $this->assertStringContainsString("lurl('register')", $content);
    }

    public function testLoginTemplateDefinesStageSpecificLinkMatrix(): void
    {
        $content = $this->readProjectFile('pages/auth/login(login).phtml');

        $this->assertStringContainsString("'show_register' => true", $content);
        $this->assertStringContainsString("'show_support' => true", $content);
        $this->assertStringContainsString('\'show_forgot\' => !empty($selectedTenantMethods[\'local\'])', $content);
        $this->assertStringContainsString('$stage === \'choose_tenant\'', $content);
    }

    public function testSecondaryAuthPagesProvideBackToLoginAndSupportLinks(): void
    {
        $files = [
            'pages/auth/register(login).phtml',
            'pages/auth/forgot(login).phtml',
            'pages/auth/verify(login).phtml',
            'pages/auth/reset(login).phtml',
            'pages/auth/verify-email(login).phtml',
        ];

        foreach ($files as $file) {
            $content = $this->readProjectFile($file);
            $this->assertStringContainsString("'show_back_to_login' => true", $content, $file);
            $this->assertStringContainsString("'show_support' => true", $content, $file);
            $this->assertStringContainsString("templatePath('partials/auth-help-links.phtml')", $content, $file);
        }
    }
}
