<?php
/**
 * app/controllers/admin/home.php
 *
 * This is the admin dashboard controller.
 *
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Controllers\Admin;

use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Classes\AdminController;
use TheTempusProject\Models\User;
use TheTempusProject\Models\Comments;
use TheTempusProject\Models\Posts;
use TheTempusProject\Plugins\Comments as CommentPlugin;
use TheTempusProject\Plugins\Blog as BlogPlugin;
use TheTempusProject\Canary\Bin\Canary as Debug;

class Home extends AdminController {
    public static $user;
    public static $comments;
    public static $posts;

    public function __construct() {
        parent::__construct();
        self::$title = 'Admin - Home';
    }

    public function index() {
        Components::set( 'commentDash', '' );
        if ( class_exists( 'TheTempusProject\Plugins\Comments' ) ) {
            $plugin = new CommentPlugin;

            if ( ! $plugin->checkEnabled() ) {
                Debug::info( 'Comments Plugin is disabled in the control panel.' );
            } else {
                $comments = new Comments;
                $commentList = Views::simpleView( 'comments.admin.dashboard', $comments->recent( 'all', 5 ) );
                Components::set( 'commentDash', $commentList );
            }
        }

        if ( class_exists( 'TheTempusProject\Plugins\Blog' ) ) {
            $plugin = new BlogPlugin;

            if ( ! $plugin->checkEnabled() ) {
                Debug::info( 'Blog Plugin is disabled in the control panel.' );
                Components::set( 'blogDash', '' );
            } else {
                $posts = new Posts;
                $postsList = Views::simpleView( 'blog.admin.dashboard', $posts->recent( 5 ) );
                Components::set( 'blogDash', $postsList );
            }
        }

        self::$user = new User;
        $users = Views::simpleView( 'admin.dashboard.users', self::$user->recent( 5 ) );
        Components::set( 'userDash', $users );

        Views::view( 'admin.dashboard.dash' );
    }
}
