<?php

use Template\RenderableTemplate as RenderableTemplate;

class Dashboard extends RenderableTemplate {
    
    public $content;
    
    public function render() {
        if (is_ajax_request()) {
            $this->content = file_get_contents($this->getView()['location']);
            $this->implate();
            return;
        }

        global $DROPDOWN, $SIDEBAR;
        
        $head = '';
        $head .=  '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
        $head .=  '<script src="/plugins/jquery/jquery.min.js"></script>';

        $head .=  '<script src="/plugins/mousetrap/mousetrap.min.js"></script>';

        $head .=  '<script src="/plugins/jquery-mask-plugin/jquery.mask.min.js"></script>';

        $head .=  '<link href="/plugins/bootstrap/bootstrap.min.css" rel="stylesheet" />';
        $head .=  '<script src="/plugins/bootstrap/bootstrap.min.js"></script>';

        $head .=  '<link href="/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />';

        $head .=  '<link href="/plugins/normalize-css/normalize.css" rel="stylesheet">';
        $head .=  '<link href="/dist/style.css" rel="stylesheet">';

        $head .=  '<link href="/dist/theme/black_and_white.css" rel="stylesheet">';

        $head .=  '<link href="/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">';
        $head .=  '<script src="/plugins/metisMenu/metisMenu.min.js"></script>';

        $head .=  '<link href="/plugins/select2/select2.min.css" rel="stylesheet">';
        $head .=  '<script src="/plugins/select2/select2.min.js"></script>';

        $head .=  '<link rel="stylesheet" href="/plugins/datatables/dataTables.css">';
        $head .=  '<script src="/plugins/datatables/dataTables.js"></script>';

        $head .=  '<link rel="stylesheet" href="/plugins/trumbowyg/ui/trumbowyg.min.css">';
        $head .=  '<script src="/plugins/trumbowyg/trumbowyg.min.js"></script>';
        
        $foot = '';
        $foot .= '<script src="/dist/script.js"></script>';
        $foot .= '<script src="/dist/exercicio_form.js"></script>';
        
        $this->content = file_get_contents(__DIR__ . '/template.html');

        $this->content = str_replace("{{usermenu}}", "", $this->content);
        $this->content = str_replace("{{elements}}", $SIDEBAR->render(), $this->content);

        $this->content = str_replace("{{head}}", $head, $this->content);
        
        if(is_file($this->getView()['location'])){
            $this->content = str_replace('{{>content}}', $this->replaceSections(file_get_contents($this->getView()['location']), $this->_view['values']), $this->content);
        }else{
            $this->content = str_replace('{{>content}}', '', $this->content);
        }
        
        $this->content = str_replace("{{footer}}", $foot, $this->content);
        
        $this->implate();
        
    }

}
