<?php
/**
 * app/templates/admin/admin.inc.php
 *
 * This is the loader for the admin template.
 *
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Templates;

use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Houdini\Classes\Navigation;
use TheTempusProject\Houdini\Classes\Components;
use TheTempusProject\Bedrock\Functions\Input;
use TheTempusProject\TheTempusProject as App;
use TheTempusProject\Houdini\Classes\Template;

class AdminLoader extends DefaultLoader {
    public function __construct() {
        parent::__construct();
        $links = Navigation::getMenuLinks( App::ADMIN_MENU_NAME );
        foreach ( $links as $key => $link ) {
            if ( is_array( $link->url ) ) {
                $links[$key]->linkClasses = 'nav-link d-flex align-items-center justify-content-between';
                $links[$key]->linkAttributes = Template::parse( 'aria-controls="{dropdownName}Dropdown" data-bs-toggle="collapse" aria-haspopup="true" aria-expanded="false"' );
                $name = trim(strip_tags( $link->text ) );
                Components::set( 'dropdownName', $name );
                $out = [];
                foreach ( $link->url as $subKey => $subLink ) {
                    $out[] = (object) $subLink;
                }
                $links[$key]->url = '#' . $name . 'Dropdown';
                $links[$key]->text = '<span>' . $link->text . '</span><i class="fa fa-fw fa-caret-down ms-2"></i>';
                $links[$key]->duuuuuuuh = Views::simpleView( 'nav.adminSub', $out );
            } else {
                $links[$key]->linkClasses = 'nav-link';
                $links[$key]->linkAttributes = '';
                $links[$key]->duuuuuuuh = '';
            }
        }
        Components::set( 'ADMIN_LINKS', Views::simpleView( 'nav.admin', $links ) );
        Navigation::setCrumbComponent( 'ADMIN_BREADCRUMBS', Input::get( 'url' ) );
    }
}
