<!--***** SIDE NAVBAR *****-->
<style>
    nav.side-navbar ul a.choice {
        background: linear-gradient(to left, #7c8ce4, #2196f3) !important;
        border-left: 4px solid #7b4397 !important;
        color: #fff !important;
    }
</style>
<nav class="side-navbar">
    <div class="sidebar-header d-flex align-items-center">
        <div class="avatar"><img src=" {{ asset('xadmin/img/avatar-1.jpg')}}" alt="..."
                                 class="img-fluid rounded-circle"></div>
        <div class="title">
            <h1 class="h4"><?=\Illuminate\Support\Facades\Auth::user()->name?></h1>
        </div>
    </div>
    <hr>
    <!-- Sidebar Navidation Menus-->
    <ul class="list-unstyled first">
        <li class=""><a href="/web/admin" id="home-li"><i class="icon-home"></i>首页</a></li>
        @foreach($left as $key => $item)
            <li class="{{parse_custom_str($item['link'])}}">
                {{--<a href="index.blade.php2"><i class="icon-home"></i>Home</a>--}}

                @if(count($item['son'])>0)
                    <a href="#top{{$key}}" data-toggle="collapse">
                        {{--<i class="" style="font-size:20px;"></i>--}}

                        <i class="iconfont">{!! $item['icon'] !!}</i>
                        <cite>{{$item['name']}}</cite>

                        {{--<cite>{{trans('index.'.$item['key_name'])}} </cite>--}}
                        {{--<i class="iconfont nav_right">&#xe697;</i>--}}
                    </a>

                @else

                    <a href="#top{{$key}}" onclick="redirectTo('{{get_prefix().$item["link"]}}')">
                        {{--<i class="{{$item['icon']}}" style="font-size:20px;"></i>--}}
                        <i class="iconfont">{!! $item['icon'] !!}</i>
                        <cite>{{$item['name']}}</cite>
                        {{--<cite>{{trans('index.'.$item['key_name'])}} </cite>--}}
                        {{--<i class="iconfont nav_right">&#xe697;</i>--}}
                    </a>

                @endif

                @if(count($item['son'])>0)
                    <ul id="top{{$key}}" class="second collapse list-unstyled">
                        @foreach($item['son'] as $k => $child_item)
                            @if($child_item['show'] == 1)
                                <li class="{{parse_custom_str($child_item['link'])}}" onclick="redirectTo('{{get_prefix().$child_item["link"]}}')">
                                    <a href="javascript:;" >
                                        {{--<i class="iconfont">&#xe6a7;</i>--}}
                                        <cite>{{$child_item['name']}}</cite>
                                        {{--<cite>{{ trans('index.'.$child_item['key_name']) }}</cite>--}}
                                    </a>
                                </li>
                            @endif
                        @endforeach
                    </ul>
                @endif

            </li>
        @endforeach


    </ul>

</nav>

<style>

    nav.side-navbar ul a.choice {
        background: linear-gradient(to left, #7c8ce4, #2196f3) !important;
        border-left: 4px solid #7b4397 !important;
        color: #fff !important;
    }

</style>
<script>

    function secondSiliderBar() {


        /**
         * 处理包含有子类的侧边栏
         */
        $('nav.side-navbar > ul li').removeClass('active');

        /**
         * 获取当前页面url控制器路径
         * @type {string}
         */
        var current_url = window.location.pathname;

        var li_arr = $('nav.side-navbar ul > li');

        console.log("current_url",current_url);


        var urlexist = false;

        for (var i = 0; i < li_arr.length; i++) {
            console.log($(li_arr[i]).attr('class'))

            console.log('url_controller'+i,"{{get_prefix()}}"+"/"+$(li_arr[i]).attr('class'))

            if ("{{get_prefix()}}" + "/" + $(li_arr[i]).attr('class') == current_url) {


                urlexist = true;

                $.cookie('previous_url', $(li_arr[i]).attr('class').substr($(li_arr[i]).attr('class').lastIndexOf("/") + 1));

                if (urlexist) {

                    //console.log("$(li_arr[i]).attr('class') parent",$(li_arr[i]).parent().parent().addClass('active'))

                    //设置选中侧边栏背景颜色,即ul.first li背景颜色
                    $(li_arr[i]).parent().parent().addClass('active');

                    //设置选中侧边箭头朝下，即ul.first > a 属性aria-expanded=true
                    $(li_arr[i]).parent().parent().children("a:eq(0)").attr('aria-expanded', true);

                    //设置选中侧边展开
                    $(li_arr[i]).parent().addClass('show');

                    //设置选择项颜色
                    $(li_arr[i]).children("a:eq(0)").addClass('choice');



                    console.log('$(li_arr[i])', $(li_arr[i]))
                }
            }
        }





        console.log("1111111111111111",urlexist)

        if (!urlexist) {

            previous_url = $.cookie('previous_url');
            $('nav.side-navbar ul li.' + previous_url + '').parent().parent().addClass('active');
            $('nav.side-navbar ul li.' + previous_url + '').parent().parent().children("a:eq(0)").attr('aria-expanded', true);
            $('nav.side-navbar ul li.' + previous_url + '').parent().addClass('show');
            $('nav.side-navbar ul li.' + previous_url + '').children("a:eq(0)").addClass('choice');

        }

        if (current_url == '/web/admin') {

            $('a').removeClass('choice')
            $('a').attr('aria-expanded', false)
            $('ul').removeClass('show');
            $('li').removeClass('active');

            $('#home-li').addClass('choice');

        }

    }


    secondSiliderBar();

    function redirectTo(url){
        var category_id = $.cookie('media_category_id');
        var appid = $.cookie('appid');
        window.location.href = url+'?category_id='+category_id+'&appid='+appid;
    }

</script>
