<?php

declare(strict_types=1);

namespace App\Framework\Console\Examples;

use App\Framework\Console\Components\TreeHelper;
use App\Framework\Console\ConsoleColor;
use App\Framework\Console\ConsoleCommand;
use App\Framework\Console\ConsoleFormat;
use App\Framework\Console\ConsoleInput;
use App\Framework\Console\ConsoleOutput;
use App\Framework\Console\ConsoleStyle;

final class TreeExample
{
    #[ConsoleCommand('demo:tree', 'Zeigt ein Beispiel für die TreeHelper-Komponente')]
    public function showTreeExample(ConsoleInput $input, ConsoleOutput $output): int
    {
        $output->writeLine('Beispiel für den TreeHelper', ConsoleStyle::create(
            color: ConsoleColor::BRIGHT_WHITE,
            format: ConsoleFormat::BOLD
        ));
        $output->newLine();

        // Einfaches Verzeichnisbeispiel
        $tree = new TreeHelper('Projektstruktur');
        $tree->setNodeStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_CYAN, format: ConsoleFormat::BOLD));
        $tree->setLeafStyle(ConsoleStyle::create(color: ConsoleColor::WHITE));

        $srcNode = $tree->addNode('src/');

        $domainNode = $srcNode->addNode('Domain/');
        $domainNode->addNode('User/')->addLeaf('User.php')->addLeaf('UserRepository.php');
        $domainNode->addNode('Product/')->addLeaf('Product.php')->addLeaf('ProductRepository.php');

        $frameworkNode = $srcNode->addNode('Framework/');
        $consoleNode = $frameworkNode->addNode('Console/');
        $consoleNode->addNode('Components/')
            ->addLeaf('Table.php')
            ->addLeaf('TextBox.php')
            ->addLeaf('TreeHelper.php');

        $consoleNode->addLeaf('ConsoleColor.php');
        $consoleNode->addLeaf('ConsoleFormat.php');
        $consoleNode->addLeaf('ConsoleOutput.php');

        $testNode = $tree->addNode('tests/');
        $testNode->addLeaf('UserTest.php');
        $testNode->addLeaf('ProductTest.php');

        $tree->addLeaf('composer.json');
        $tree->addLeaf('README.md');

        $output->write($tree->render());
        $output->newLine(2);

        // Zweites Beispiel: Kategorien
        $output->writeLine('Kategorie-Baum:', ConsoleStyle::create(color: ConsoleColor::BRIGHT_GREEN));

        $categories = new TreeHelper();
        $categories->setNodeStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_YELLOW, format: ConsoleFormat::BOLD));
        $categories->setLeafStyle(ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE));
        $categories->setLineStyle(ConsoleStyle::create(color: ConsoleColor::GRAY));

        $electronics = $categories->addNode('Elektronik');

        $computers = $electronics->addNode('Computer & Zubehör');
        $computers->addLeaf('Laptops');
        $computers->addLeaf('Desktop-PCs');
        $peripherie = $computers->addNode('Peripheriegeräte');
        $peripherie->addLeaf('Monitore');
        $peripherie->addLeaf('Tastaturen');
        $peripherie->addLeaf('Mäuse');

        $smartphones = $electronics->addNode('Smartphones & Zubehör');
        $smartphones->addLeaf('Handys');
        $smartphones->addLeaf('Hüllen');
        $smartphones->addLeaf('Ladegeräte');

        $kleidung = $categories->addNode('Kleidung');
        $kleidung->addLeaf('Herren');
        $kleidung->addLeaf('Damen');
        $kleidung->addLeaf('Kinder');

        $output->write($categories->render());

        return 0;
    }
}
