<?php

declare(strict_types=1);

namespace prj\mockup\outputs\app;

class home_out {
    
    public static function name_demo(array $input): array {
        $age = $input['html']['age'];        
        $first_name = $input['html']['first_name'] ?? "Unknown";
        $last_name = $input['html']['last_name'] ?? "Unknown";
        
        $ret['main'] = ($input['errors']) ? "" : "Hello {$first_name} {$last_name}, You are {$age} years old!" . PHP_EOL;
        $ret['errors'] = $input['errors'];
        $ret['model'] = $input['model'];
        
        return $ret;
    }
    
    public static function show_errors(array $errors): string {
        if ($errors) {
            $message = "Please correct the following errors: ";
            $i = 0;
            foreach($errors as $error) {
                $i++;
                $message .= "<br/>{$i}) " . $error;
            }
            return $message;
        }
        return ""; // No Errors to return here
    }
    
    public static function show_user_details(\Generator $input): void {
        if (! $input->current()) {
            return; // No Data, so Bail here
        }
        \tts\html::show_table_from_generator(
            ['ID', 'First Name', 'Last Name', 'Age'],
            ['id', 'first_name', 'last_name', 'age'],
            $input
        );
    }
    
}
