<?php

describe('Auth Background Pattern', function () {
    test('auth pattern SVG file exists', function () {
        $svgPath = public_path('images/auth-pattern.svg');

        expect(file_exists($svgPath))->toBeTrue();
    });

    test('auth pattern SVG is under 5KB', function () {
        $svgPath = public_path('images/auth-pattern.svg');
        $fileSize = filesize($svgPath);

        // 5KB = 5120 bytes
        expect($fileSize)->toBeLessThan(5120);
    });

    test('auth pattern SVG uses correct brand color', function () {
        $svgContent = file_get_contents(public_path('images/auth-pattern.svg'));

        // Warm Gold #A68966
        expect($svgContent)->toContain('#A68966');
    });

    test('auth pattern SVG has appropriate opacity', function () {
        $svgContent = file_get_contents(public_path('images/auth-pattern.svg'));

        // Opacity should be 5-8% (0.05-0.08)
        expect($svgContent)->toContain('fill-opacity="0.06"');
    });

    test('auth pattern CSS class is defined', function () {
        $cssContent = file_get_contents(resource_path('css/app.css'));

        expect($cssContent)->toContain('.auth-pattern');
        expect($cssContent)->toContain('.auth-pattern::before');
    });

    test('auth pattern CSS uses pseudo-element with repeat', function () {
        $cssContent = file_get_contents(resource_path('css/app.css'));

        expect($cssContent)->toContain("background-image: url('/images/auth-pattern.svg')");
        expect($cssContent)->toContain('background-repeat: repeat');
    });

    test('auth pattern CSS does not block interactions', function () {
        $cssContent = file_get_contents(resource_path('css/app.css'));

        // Pattern should not intercept clicks
        expect($cssContent)->toContain('pointer-events: none');
    });

    test('auth split layout uses pattern class', function () {
        $layoutContent = file_get_contents(resource_path('views/components/layouts/auth/split.blade.php'));

        expect($layoutContent)->toContain('auth-pattern');
    });

    test('login page renders with pattern applied', function () {
        $response = $this->get(route('login'));

        $response->assertOk();
        $response->assertSee('auth-pattern', escape: false);
    });

    test('register page renders with pattern applied', function () {
        $response = $this->get(route('password.request'));

        $response->assertOk();
        $response->assertSee('auth-pattern', escape: false);
    });

    test('pattern renders correctly in Arabic locale', function () {
        session(['locale' => 'ar']);

        $response = $this->get(route('login'));

        $response->assertOk();
        $response->assertSee('auth-pattern', escape: false);
        $response->assertSee('dir="rtl"', escape: false);
    });

    test('pattern renders correctly in English locale', function () {
        session(['locale' => 'en']);

        $response = $this->get(route('login'));

        $response->assertOk();
        $response->assertSee('auth-pattern', escape: false);
        $response->assertSee('dir="ltr"', escape: false);
    });
});
