<?php

declare(strict_types=1);

namespace ex\outputs\app;

class home_out {
    
    public static function name_demo(array $input): array {
        
        $age = $input['html']['age'];
        
        $first_name = $input['html']['first_name'];
        
        if ($first_name === "Chris") {
            $more = "I think you will like this!";
        } else {
            // Lets make a HyperLink as an Example for Chris
            $more = "<a href=\"" . \tts\request::get_url(
                    "/app/home", 
                    "name_demo", ['age'=>38,'first_name'=>"Chris"]
                ) . "\">See Chris</a>";
        }

        if ($input['errors']) {
            $ret['main'] = $more;
        } else {
            $ret['main'] = "Hello {$first_name}, You are {$age} years old!" . PHP_EOL . $more;
        }
        
        $ret['errors'] = $input['errors'];
        $ret['model'] = $input['model'];
        
        return $ret;
    }
    
    public static function show_errors(array $errors): string {
        if ($errors) {
            $message = "Sorry, but we had the following errors: ";
            $i = 0;
            foreach($errors as $error) {
                $i++;
                $message .= "<br/>{$i}) " . $error;
            }
            return $message;
        }
        return "Yeah, no errors were made!";
    }
    
    public static function show_user_details(array $input): void {
        if (! count($input)) {
            return;
        }
        \tts\html::show_table(['ID', 'First Name', 'Last Name', 'Age'], $input);
    }
    
}