<!--***** 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"><?=Auth::user()->name?></h1>
        </div>
    </div>
    <hr>
    <!-- Sidebar Navidation Menus-->
    <ul class="list-unstyled first">
        <li><a href="/web/admin" id="home-li"><i class="icon-home"></i>首页</a></li>
        @foreach($top as $key => $item)
            <li class="">
                {{--<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}}">
                        {{--<i class="{{$item['icon']}}" style="font-size:20px;"></i>--}}
                        <i class="icon-home"></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'])}}">
                                    <a href="{{get_prefix().$child_item['link']}}">
                                        {{--<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>
<script>

    $('nav.side-navbar ul li').removeClass('active');

    var current_url = window.location.pathname;

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

    var urlexist = false;

    for (var i = 0; i < li_arr.length; i++) {
        //console.log($(li_arr[i]).attr('class'))
        // console.log('get_prefix()',"{{get_prefix()}}"+$(li_arr[i]).attr('class')+current_url)

        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]))
            }
        }
    }

    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');

    }

</script>
