<?php

require_once __DIR__ . '/../vendor/autoload.php';

use PHPNative\Framework\Application;
use PHPNative\Ui\Widget\Container;
use PHPNative\Ui\Window;

// Create application
$app = new Application();
$window = new Window('Alpha Blending Test', 400, 400);

// Custom container to test alpha blending
class AlphaTestContainer extends Container
{
    public function render(&$renderer, ?\PHPNative\Framework\TextRenderer $textRenderer = null): void
    {
        parent::render($renderer, $textRenderer);

        // Enable alpha blending for renderer
        sdl_set_render_draw_blend_mode($renderer, SDL_BLENDMODE_BLEND);

        // Draw 3 overlapping semi-transparent rectangles
        // Red rectangle - alpha 30
        sdl_set_render_draw_color($renderer, 255, 0, 0, 30);
        sdl_render_fill_rect($renderer, ['x' => 50, 'y' => 100, 'w' => 100, 'h' => 100]);

        // Green rectangle - alpha 30
        sdl_set_render_draw_color($renderer, 0, 255, 0, 30);
        sdl_render_fill_rect($renderer, ['x' => 100, 'y' => 100, 'w' => 100, 'h' => 100]);

        // Blue rectangle - alpha 30
        sdl_set_render_draw_color($renderer, 0, 0, 255, 30);
        sdl_render_fill_rect($renderer, ['x' => 150, 'y' => 100, 'w' => 100, 'h' => 100]);

        // Test: 10 black layers with alpha 3
        for ($i = 0; $i < 10; $i++) {
            sdl_set_render_draw_color($renderer, 0, 0, 0, 3);
            sdl_render_fill_rect($renderer, ['x' => 50, 'y' => 250, 'w' => 200 + $i * 10, 'h' => 100]);
        }
    }
}

$mainContainer = new AlphaTestContainer('flex items-center justify-center bg-gray-200');

// Set window content and run
$window->setRoot($mainContainer);
$app->addWindow($window);
$app->run();
