 <?php

use Template\RenderableTemplate as RenderableTemplate;

class Dashboard extends RenderableTemplate {

    public $content;

    public function render($content = '') {
        global $DROPDOWN, $SIDEBAR;

        /*if (is_ajax_request()) {
            if(is_file($this->getView()['location'])){
                $this->content = file_get_contents($this->getView()['location']);
                $this->implate();
            }else{
                $this->content = '';
                $this->implate();
            }
            return;
        }*/

        //global $DROPDOWN, $SIDEBAR;

        $head = '';

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

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

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

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

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

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

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

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

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

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

        $head .=  '<link href="https://unpkg.com/dropzone@5/dist/min/dropzone.min.css" rel="stylesheet">';
        $head .=  '<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>';

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

        $head .=  '<script src="/plugins/bootstrapToastWrapper/dist/bootstrapToastWrapper.js"></script>';

        $head .=  '<script src="/plugins/html5-qrcode/html5-qrcode.min.js"></script>';

        $head .=  '<script src="https://cdn.datatables.net/1.11.4/js/dataTables.bootstrap5.min.js"></script>';
        $head .=  '<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap5.min.css">';

        $head .= '<script src="/dist/libs.js" defer="true"></script>';
        $head .= '<script src="/dist/validation.js" defer="true"></script>';

        $foot = '';
        $foot .= '<script src="/dist/script.js" defer="true"></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);

        $header = '';

        //HACK
        foreach ($DROPDOWN as $item){
            $header .= "<a class='dropdown-item' href='".$item['route']."'>".$item['name']."</a>";
        }

        $this->content = str_replace("{{dropdown}}", $header, $this->content);

        $this->content = str_replace("{{head}}", $head, $this->content);
        $this->content = str_replace("{{footer}}", $foot, $this->content);
        $this->content = str_replace('{{content}}', $content, $this->content);

        return $this->content;

    }

}
