<?php

namespace MintyPHP\Tests\Architecture;

use PHPUnit\Framework\TestCase;

class AsideNavigationContractTest extends TestCase
{
    use ProjectFileAssertionSupport;

    public function testAdminAsideUsesGroupedDetailsStorageContract(): void
    {
        $content = $this->readProjectFile('templates/partials/app-main-aside.phtml');

        $this->assertStringContainsString('data-aside-details-storage="aside-admin-sections-v1"', $content);
        $this->assertStringContainsString('data-aside-details-open-active="1"', $content);
        $this->assertStringContainsString('<details data-details-key="<?php e($groupKey); ?>"', $content);

        $this->assertStringContainsString("'key' => 'admin-organization'", $content);
        $this->assertStringContainsString("'key' => 'admin-roles-permissions'", $content);
        $this->assertStringContainsString("'key' => 'admin-automation'", $content);
        $this->assertStringContainsString("'key' => 'admin-monitoring'", $content);
        $this->assertStringContainsString("'key' => 'admin-logs'", $content);
        $this->assertStringContainsString("'key' => 'admin-system'", $content);
    }

    public function testAsidePanelsUseSharedDetailsOpenStateHelper(): void
    {
        $content = $this->readProjectFile('web/js/components/app-toggle-aside-panels.js');

        $this->assertStringContainsString("import { initPersistedDetailsGroup } from '../core/app-details-open-state.js';", $content);
        $this->assertStringContainsString('initPersistedDetailsGroup({', $content);
        $this->assertStringContainsString("panel.dataset.asideDetailsOpenActive === '1'", $content);
    }

    public function testDetailStateUsesSharedDetailsOpenStateHelper(): void
    {
        $content = $this->readProjectFile('web/js/components/app-details-state.js');

        $this->assertStringContainsString("import { initPersistedDetailsGroup } from '../core/app-details-open-state.js';", $content);
        $this->assertStringContainsString('initPersistedDetailsGroup({', $content);
        $this->assertStringNotContainsString('window.localStorage.setItem(storageKey, JSON.stringify(openKeys));', $content);
    }
}
