<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class FilterDrawerTemplateContractTest extends TestCase
{
    use ListContractFiles;
    use ProjectFileAssertionSupport;

    public function testDrawerTemplatesExposeDrawerAccessibilityHooks(): void
    {
        foreach ($this->drawerListTemplates() as $file) {
            $content = $this->readProjectFile($file);
            $usesPartial = $this->usesSharedListFiltersPartial($content);

            if (!$usesPartial) {
                $this->assertStringContainsString('role="dialog"', $content, $file);
                $this->assertStringContainsString('aria-modal="true"', $content, $file);
                $this->assertStringContainsString('aria-labelledby="', $content, $file);
                $this->assertStringContainsString('data-filter-live-region', $content, $file);
            }

            $this->assertStringNotContainsString('data-filter-drawer-draft-hint', $content, $file);
        }
    }

    public function testAddressBookFilterChipsContract(): void
    {
        $content = $this->readProjectFile('modules/addressbook/pages/address-book/index(default).phtml');
        $moduleContent = $this->readProjectFile('modules/addressbook/web/js/pages/address-book-index.js');

        $this->assertStringNotContainsString('const state = collectFilterState();', $moduleContent);
        $this->assertStringContainsString('data-filter-chips-clear-all-label', $content);
        $this->assertStringContainsString('data-filter-chips-remove-label', $content);
        $this->assertStringContainsString('data-filter-live-applied-message', $content);
        $this->assertStringContainsString('data-filter-live-removed-message', $content);
        $this->assertStringContainsString('data-filter-live-cleared-message', $content);
    }

    public function testSharedListFiltersPartialKeepsDrawerAccessibilityContract(): void
    {
        $content = $this->readProjectFile('templates/partials/app-list-filters.phtml');
        $this->assertStringContainsString('renderGridFilterToolbar(', $content);
        $this->assertStringContainsString('data-filter-drawer-open', $content);
        $this->assertStringContainsString('data-filter-drawer-apply', $content);
        $this->assertStringContainsString('data-active-filter-chips', $content);
        $this->assertStringContainsString('data-filter-chips-clear-all-label', $content);
        $this->assertStringContainsString('data-filter-chips-remove-label', $content);
        $this->assertStringContainsString('role="dialog"', $content);
        $this->assertStringContainsString('aria-modal="true"', $content);
        $this->assertStringContainsString('aria-labelledby=', $content);
        $this->assertStringContainsString('data-filter-live-region', $content);
        $this->assertStringContainsString('data-filter-live-applied-message', $content);
        $this->assertStringContainsString('data-filter-live-removed-message', $content);
        $this->assertStringContainsString('data-filter-live-cleared-message', $content);
    }
}
