<?php

declare(strict_types=1);

namespace App\Framework\Console\Examples;

use App\Framework\Console\Components\Table;
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 TableExample
{
    #[ConsoleCommand('demo:table', 'Zeigt eine Beispiel-Tabelle')]
    public function showTable(ConsoleInput $input, ConsoleOutput $output): int
    {
        $output->writeLine('Beispiel für die Table-Komponente', ConsoleStyle::create(
            color: ConsoleColor::BRIGHT_WHITE,
            format: ConsoleFormat::BOLD
        ));
        $output->newLine();

        // Einfache Tabelle
        $table = new Table(
            headerStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_YELLOW, format: ConsoleFormat::BOLD),
            borderStyle: ConsoleStyle::create(color: ConsoleColor::CYAN)
        );

        $table->setHeaders(['Name', 'Alter', 'Stadt'])
              ->addRow(['Max Mustermann', '30', 'Berlin'])
              ->addRow(['Anna Schmidt', '25', 'München'])
              ->addRow(['Peter Weber', '35', 'Hamburg']);

        $output->write($table->render());
        $output->newLine();

        // Komplexere Tabelle mit Produktdaten
        $output->writeLine('Produktübersicht:', ConsoleStyle::create(color: ConsoleColor::BRIGHT_GREEN));

        $productTable = new Table(
            headerStyle: ConsoleStyle::create(color: ConsoleColor::BRIGHT_WHITE, format: ConsoleFormat::BOLD),
            rowStyle: ConsoleStyle::create(color: ConsoleColor::WHITE),
            borderStyle: ConsoleStyle::create(color: ConsoleColor::GRAY)
        );

        $productTable->setHeaders(['Artikel-Nr.', 'Bezeichnung', 'Preis', 'Lagerbestand', 'Status'])
                     ->setPadding(2)
                     ->addRow(['A-1001', 'Tastatur Deluxe', '89,99 €', '45', 'Verfügbar'])
                     ->addRow(['A-1002', 'Gaming Maus Pro', '69,99 €', '12', 'Knapp'])
                     ->addRow(['A-1003', '4K Monitor 27"', '349,99 €', '0', 'Ausverkauft'])
                     ->addRow(['A-1004', 'USB-C Kabel 2m', '19,99 €', '156', 'Verfügbar'])
                     ->addRow(['A-1005', 'Wireless Headset', '129,99 €', '8', 'Knapp']);

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

        return 0;
    }
}
