<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class ListTitlebarContractTest extends TestCase
{
    use ProjectFileAssertionSupport;

    /**
     * @return list<string>
     */
    private function titlebarTemplateFiles(): array
    {
        return [
            'pages/admin/users/index(default).phtml',
            'pages/admin/tenants/index(default).phtml',
            'pages/admin/departments/index(default).phtml',
            'pages/admin/roles/index(default).phtml',
            'pages/admin/permissions/index(default).phtml',
            'pages/admin/mail-log/index(default).phtml',
            'pages/admin/scheduled-jobs/index(default).phtml',
            'pages/admin/api-audit/index(default).phtml',
            'pages/admin/import-audit/index(default).phtml',
            'pages/admin/user-lifecycle-audit/index(default).phtml',
            'pages/admin/system-audit/index(default).phtml',
            'pages/address-book/index(default).phtml',
            'pages/search/index(default).phtml',
            'pages/help/hotkeys(default).phtml',
        ];
    }

    public function testTemplatesUseSharedListTitlebarPartial(): void
    {
        foreach ($this->titlebarTemplateFiles() as $file) {
            $content = $this->readProjectFile($file);
            $this->assertStringContainsString("require templatePath('partials/app-list-titlebar.phtml');", $content, $file);
        }
    }

    public function testTemplatesDoNotInlineLegacyListTitlebarMarkup(): void
    {
        foreach ($this->titlebarTemplateFiles() as $file) {
            $content = $this->readProjectFile($file);
            $this->assertSame(0, preg_match('/<div\s+class=\"app-list-titlebar\"/', $content), $file);
        }
    }
}
