<?php
/**
 * app/plugins/resume/controllers/resume.php
 *
 * This is the bug reports controller.
 *
 * @package TP Resume
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Controllers;

use TheTempusProject\Houdini\Classes\Issues;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Classes\Controller;
use TheTempusProject\Models\Positions;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Houdini\Classes\Template;

class Resume extends Controller {
    protected static $positions;


    public function __construct() {
        parent::__construct();
        Components::append( 'TEMPLATE_JS_INCLUDES', Template::parse(
            '<script language="JavaScript" crossorigin="anonymous" type="text/javascript" src="{ROOT_URL}app/plugins/resume/js/resume.js"></script>'
        ) );
    }


    public function index() {
        self::$positions = new Positions;
        self::$title = '{SITENAME} - Resume';
        self::$pageDescription = 'Its not the longest resume in the world, but I\'m certainly proud of it.';

        $positions = self::$positions->listPaginated();
        if ( false == $positions ) {
            Issues::add( 'error', 'Well, this is embarrassing, surely he wouldn\'t just have no resume..... right.... Dave? ... erm Joey?' );
            return;
        } else {
            Components::set( 'RESUME_NAV', Views::simpleView( 'resume.nav') );
            Components::set( 'RESUME_DOWNLOADS', Views::simpleView( 'resume.download') );
            if ( !Input::exists( 'view' ) ) {
                return Views::view( 'resume.resume', $positions );
            } else {
                Components::append( 'TEMPLATE_CSS_INCLUDES', Template::parse('<link rel="stylesheet" href="{ROOT_URL}app/plugins/resume/css/timeline.css" />') );
                $side = 'left';
                foreach ($positions as $key => $position) {
                    $position->side = $side; // Add the new entry for side
                    $side = ($side === 'left') ? 'right' : 'left'; // Alternate between left and right
                }
                return Views::view( 'resume.timeline', $positions );
            }
        }
    }
    public function test() {
        self::$positions = new Positions;
        self::$title = '{SITENAME} - Resume';
        self::$pageDescription = 'Its not the longest resume in the world, but I\'m certainly proud of it.';

                return Views::view( 'resume.test' );
    }
}
