<?php
/**
 * Created by PhpStorm.
 * User: eater
 * Date: 4/2/16
 * Time: 9:27 PM
 */

namespace Eater\Glim\Handler;


use Eater\Glim\Model\Server;
use Eater\Glim\Model\ServerQuery;
use Eater\Glim\Service\TwigVars;

class Panel extends Session
{
    protected $shouldHaveUser = true;

    public function beforeHandle()
    {
        $return = parent::beforeHandle();

        if ($return !== null) {
            return $return;
        }

        /** @var TwigVars $twigVar */
        $twigVar = $this->get('twig-vars');

        $twigVar->def(
            'menu',
            [
                [
                    'name' => 'Certificates',
                    'path' => '/panel/certificates'
                ],
                [
                    'name' => 'Servers',
                    'path' => '/panel/servers'
                ],
                [
                    'name' => 'Invites',
                    'path' => '/panel/invites'
                ],
                [
                    'name' => 'Config builder',
                    'path' => '/panel/config-builder'
                ],
                [
                    'name' => 'Profile > ' . $this->getUser()->getUsername(),
                    'path' => '/panel/profile'
                ],
                [
                    'name' => 'Logout',
                    'path' => '/logout'
                ]
            ]
        );

        $twigVar->def('currentpath', $this->getRequest()->getUri()->getPath());
    }

    public function handle()
    {
        return $this->redirect('/panel/certificates');
    }
}