<?php
namespace App\Utilities;
class MenuHelper {
    public static function HeaderMenuRecursive(array $headerMenu, string $type):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="navbar-nav ml-auto">';
                foreach($headerMenu as $hk=>$hv){
                    $html .= '<li class="nav-item">';
                        if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                            $html .= '<a class="nav-link " id="'.str_replace(' ','-', strtolower($hv['pageName'])).$type.'" href="javascript:void(0)">'.$hv['title'].' <i class="fa fa-angle-down" aria-hidden="true"></i></a>';
                            $html .= self::HeaderMenuRecursiveSub($hv['subMenu'],$type, $hv);
                        } else {
                            $html .= '<a class="nav-link" id="'.str_replace(' ','-', strtolower($hv['pageName'])).$type.'" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                        }
                    $html .= '</li>';
                }
            $html .='</ul>';
        }
        return $html;
    }
    public static function HeaderMenuRecursiveSub(array $headerMenu, string $type, array $currentVal):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="sub-menu">';
            foreach($headerMenu as $hk=>$hv){
                $html .= '<li class="nav-item">';
                    if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                        $html .= '<a class="" href="javascript:void(0)">'.$hv['title'].'</a>';
                        $html .= self::HeaderMenuRecursiveSubSecond($hv['subMenu'],$type, $hv);
                    } else {
                        $html .= '<a class="" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                    }
                $html .= '</li>';
            }
            $html .='</ul>';
        }
        return $html;
    }    
    public static function HeaderMenuRecursiveSubSecond(array $headerMenu, string $type, array $currentVal):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="sub-menu">';
            foreach($headerMenu as $hk=>$hv){
                $html .= '<li class="nav-item">';
                    if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                        $html .= '<a class="" href="javascript:void(0)">'.$hv['title'].' <img class="arrow" src="'.asset('assets/image/common/menuDropdown.png').'" /></a>';
                        $html .= self::HeaderMenuRecursiveSubSecond($hv['subMenu'],$type, $hv);
                    } else {
                        $html .= '<a class="" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                    }
                $html .= '</li>';
            }
            $html .='</ul>';
        }
        return $html;
    }
    public static function HeaderMenuSideRecursive(array $headerMenu, string $type):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="mobileNavLink">';
            foreach($headerMenu as $hk=>$hv){
                $html .= '<li class="gr'.($hk+1).'">';
                    if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                        $html .= '<a class="" id="'.str_replace(' ','-', strtolower($hv['pageName'])).$type.'" href="javascript:void(0)">'.$hv['title'].'</a>';
                        $html .= self::HeaderMenuSideRecursiveSub($hv['subMenu'],$type, $hv);
                    } else {
                        $html .= '<a class="" id="'.str_replace(' ','-', strtolower($hv['pageName'])).$type.'" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                    }
                $html .= '</li>';
            }
            $html .='</ul>';
        }
        return $html;
    }
    public static function HeaderMenuSideRecursiveSub(array $headerMenu, string $type, array $currentVal):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="subMenu">';
                $html .='<li><a href="'.url('/').'/'.$currentVal['slug'].'">All '.$currentVal['title'].'</a></li>';
                foreach($headerMenu as $hk=>$hv){
                    $html .= '<li>';
                        $html .= '<a class="" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                        if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                            $html .= self::HeaderMenuSideRecursiveSub($hv['subMenu'],$type,$hv);
                        }
                    $html .= '</li>';
                }
            $html .='</ul>';
        }
        return $html;
    }
    public static function HeaderMenuFooterRecursive(array $headerMenu, string $type):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul>';
            foreach($headerMenu as $hk=>$hv){
                $html .= '<li class="gr'.($hk+1).'">';
                    $html .= '<a class="" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                    if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                        $html .= self::HeaderMenuFooterRecursiveSub($hv['subMenu'],$type);
                    }
                $html .= '</li>';
            }
            $html .='</ul>';
        }
        return $html;
    }
    public static function HeaderMenuFooterRecursiveSub(array $headerMenu, string $type):string {
        $html = '';
        if(count($headerMenu) > 0){
            $html .='<ul class="item-data">';
            foreach($headerMenu as $hk=>$hv){
                $html .= '<li>';
                    $html .= '<a class="" id="'.str_replace(' ','-', strtolower($hv['pageName'])).$type.'" href="'.url('/').'/'.$hv['slug'].'">'.$hv['title'].'</a>';
                    if(isset($hv['subMenu']) && count($hv['subMenu']) > 0){
                        $html .= self::HeaderMenuFooterRecursiveSub($hv['subMenu'],$type);
                    }
                $html .= '</li>';
            }
            $html .='</ul>';
        }
        return $html;
    }
}