@php 
    use App\Models\CategoryModel as CategoryModel;
    use App\Models\MenuModel as MenuModel;
    use App\Helpers\URL;
    use App\Helpers\Template as Template;

    $prefixNews  = config('zvn.url.prefix_news');

    $categoryModel = new CategoryModel();
    $itemsCategory = $categoryModel->listItems(null, ['task' => 'news-list-items']);
    $menuModel = new MenuModel();
    $itemsMenu = $menuModel->listItems(null, ['task' => 'news-list-items']);
    
    $xhtmlMenu = '';
    $xhtmlMenuMobile = '';

    if (count($itemsMenu) > 0) {
        
        $xhtmlMenu = '<nav class="main_nav"><ul class="main_nav_list d-flex flex-row align-items-center justify-content-start">';
        $xhtmlMenuMobile = '<nav class="menu_nav"><ul class="menu_mm">';
        $categoryCurrent = Route::currentRouteName();

        foreach ($itemsMenu as $itemNav) {
            $link       =  url($prefixNews . $itemNav['link']);
            $routeName = Route::currentRouteName();
            if ($itemNav['type_menu'] == 'category_article') {
                $arrCheckRoute = explode('_', $itemNav['type_menu']);
                $arrRouteName = explode('/', $routeName);
                $classActive = in_array($arrRouteName[0], $arrCheckRoute) ? 'class="active"' : '';
            } else {
                $classActive = (request()->route()->uri === $itemNav['link']) ? 'class="active"' : '';
            }
            $xhtmlSubMenu = '';
            if ($itemNav['type_menu'] == 'category_article') {
                $xhtmlSubMenu .= '<ul>';
                Template::showCategories($itemsCategory, $xhtmlSubMenu);
                $xhtmlSubMenu .= '</ul>';
            }
            $xhtmlMenu .= sprintf('<li %s><a href="%s">%s</a>%s</li>', $classActive, $link, $itemNav['name'],$xhtmlSubMenu);
            $xhtmlMenuMobile .= sprintf('<li class="menu_mm"><a href="%s">%s</a>%s</li>', $link, $itemNav['name'],$xhtmlSubMenu);
        }

        if (session('userInfo')) {
            $xhtmlMenuUser = sprintf('<li><a href="%s">%s</a></li>', route('auth/logout'), 'Logout');
        }else {
            $xhtmlMenuUser = sprintf('<li><a href="%s">%s</a></li>', route('auth/login'), 'Login');
        }

        $xhtmlMenu .= $xhtmlMenuUser . '</ul></nav>';
        $xhtmlMenuMobile .= $xhtmlMenuUser . '</ul></nav>';
    }

@endphp

<header class="header">
    <!-- Header Content -->
    <div class="header_content_container">
        <div class="container">
            <div class="row">
                <div class="col">
                    <div class="header_content d-flex flex-row align-items-center justfy-content-start">
                        <div class="logo_container">
                            <a href="{!! route('home') !!}">
                                <div class="logo"><span>ZEND</span>VN</div>
                            </a>
                        </div>
                        <div class="header_extra ml-auto d-flex flex-row align-items-center justify-content-start">
                            <a href="#">
                                <div class="background_image" style="background-image:url({{asset('news/images/zendvn-online.png') }});background-size: contain"></div>

                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Header Navigation & Search -->
    <div class="header_nav_container" id="header">
        <div class="container">
            <div class="row">
                <div class="col">
                    <div class="header_nav_content d-flex flex-row align-items-center justify-content-start">
                        
                        <!-- Logo -->
                        <div class="logo_container">
                            <a href="#">
                                <div class="logo"><span>ZEND</span>VN</div>
                            </a>
                        </div>

                        <!-- Navigation -->
                        {!! $xhtmlMenu !!}

                        <!-- Hamburger -->
                        <div class="hamburger ml-auto menu_mm"><i class="fa fa-bars  trans_200 menu_mm" aria-hidden="true"></i></div>
                    </div>
                </div>
            </div>
        </div>		
    </div>
</header>

<div class="menu d-flex flex-column align-items-end justify-content-start text-right menu_mm trans_400">
    <div class="menu_close_container"><div class="menu_close"><div></div><div></div></div></div>

    {!! $xhtmlMenuMobile !!}
    
    
</div>