<?php

use \Carbon\Carbon;
$id = auth()->user()->id;
$notisall = \Overdrive\Web\Model\NotificationTable::where('status','=',0)->where('fk_users','=',$id)
            ->where('created_at','>',Carbon::now()->subDays(5))->orderBy('created_at','DESC')->get();


$menu = Cache::get('menu');

if (Session::has('locale')) {
    $locale = Session::get('locale', Config::get('app.locale'));
} else {
    
    $locale = \Lang::locale();
}

?>



<div class="col-xl-3 col-md-3 menu-close">
    <div class="sidebar-with-bg sidebar-shadow " style="min-height: 100vh">
        
            <div class="sidebar-heading">
                <div class="avatar-sidebar">
                    <figure><img alt="jobhub" src="{{ asset('overide/web/themes/kpm/assets/imgs/page/job-single/avatar-job.png') }}"/></figure>
                    <div class="sidebar-info">
                        <span class="sidebar-company" style="font-size:12px">{{auth()->user()->name}}</span>
                        <span class="sidebar-website-text"  style="font-size:11px">{{auth()->user()->roles->implode('name', ', ')}}</span>
                        <div class="dropdowm" >
                            <button class="btn btn-dots btn-dots-abs-right dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">@if(count($notisall) > 0)<span id="notis" class="badge rounded-pill badge-notification bg-danger spinner-grow">{{count($notisall)}}</span> @else <span id="notis" class="badge rounded-pill badge-notification bg-warning">{{count($notisall)}}</span>@endif </button>
                            <ul class="dropdown-menu dropdown-menu-light">
                                <li ><a class="dropdown-item" href="/auth/logout" style="font-size:12px !important;">Logout</a></li>
                                <div class="row p-2">
                                    <li></li>
                                    <span style="font-size: 11px !important;"><i class="fi-rr-edit mr-5 text-grey-6"></i>Notification</span>
                                    <br>
                                    <br>
                                    <div class="post-list-small" style="font-size: 11px !important;">
                                        @forelse($notisall as $key => $notis)
                                        <div onclick="updatenotis({{$notis->id}})" class="post-list-small-item d-flex align-items-center shadow" style="background: rgba(81, 146, 255, 0.12);padding:3px">
                                            
                                            <div class="content">
                                                <span>{{$notis->content}}</span>
                                                <div class="post-meta text-muted d-flex align-items-center mb-15">
                                                    <div class="date">
                                                        <span>{{date('d-m-Y h:m:s',strtotime($notis->created_at))}}</span>
                                                    </div>
                                                    
                                                </div>
                                            </div>
                                        </div>
                                        @empty
                                        <div class="post-list-small-item d-flex align-items-center shadow" style="background: rgba(242, 189, 30, 0.3);padding:3px">
                                            
                                            <div class="content">
                                                <span>No new Notification</span>
                                            </div>
                                        </div>
                                        @endforelse
                                        
                                    </div>
                                </div>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        <hr>

        <nav class="" style="font-size: small;">

            <!-- Menu start -->
            <ul class="side-menu__sub-open backcolor">

                @if ((auth()->user()->status == 'ACTIVE') OR (auth()->user()->status == 1))
                        @foreach($menu as $key => $mainmenu )

                            @if($mainmenu->status == 1)

                                @if(count($mainmenu->activechild) > 0)

                                    <!-- parent 1 -->
                                    @if(auth()->user()->hasPermission(json_decode($mainmenu->permission)) || auth()->user()->hasPermission('*'))

                                    <!-- firstlayer -->
                                    <li>
                                        <a href="javascript:;.html" class="side-menu side-menu{{ request()->is($mainmenu->route) ? '--active' : '' }}">
                                          <div class="side-menu__icon" style="float: left;margin-right: 15px;"> 

                                            @if($mainmenu->icon) 
                                              <i data-feather="{{$mainmenu->icon}}"></i>
                                            @else
                                              <i data-feather="layout"></i>
                                            @endif

                                          </div>
                                          <div class="side-menu__title" style="margin-bottom:22px">
                                              @if($locale ==  'en') {{$mainmenu->name_en}} @else {{$mainmenu->name_bm}} @endif  
                                              <div class="side-menu__sub-icon " style="float: right;"> <i data-feather="chevron-down"></i> </div>
                                          </div>
                                        </a>


                                            <?php $childish = ($mainmenu->activechild->implode('route', ','));?>
                                            @foreach($mainmenu->activechild as $childkey => $child)
                                              <?php $childsub = ($child->activesub->implode('route', ',')); ?>
                                            @endforeach
                                            <?php 

                                              $childish =  explode(',', $childish);
                                              $childsub =  explode(',', $childsub);

                                              $combined = array_merge($childish, $childsub);
                                            ?>


                                      @if( request()->is(($combined)))
                                        <ul class="side-menu__sub-open backcolor">
                                      @else
                                        <ul class="backcolor">
                                      @endif



                                        @foreach($mainmenu->activechild as $childkey => $child)

                                            @if(count($child->activesub) > 0)

                                                  <!-- parent 2 -->
                                                  <!-- secondlayer -->
                                                  @if(auth()->user()->hasPermission(json_decode($child->permission)) || auth()->user()->hasPermission('*'))
                                                  <li style="margin-bottom:15px;margin-left:10px">
                                                    <a href="javascript:;.html" class="side-menu side-menu{{ request()->is($child->route) ? '--active' : '' }}">
                                                      <div class="side-menu__icon" style="float: left;margin-right: 15px;"> 
                                                        @if($child->icon) 
                                                          <i data-feather="{{$child->icon}}"></i>
                                                        @else
                                                          <i data-feather="layout"></i>
                                                        @endif
                                                      </div>
                                                      <div class="side-menu__title">@if($locale ==  'en') {{$child->name_en}} @else {{$child->name_bm}} @endif
                                                          <div class="side-menu__sub-icon " style="float: right;"> <i data-feather="chevron-down"></i> </div>
                                                      </div>
                                                    </a>
                                                    <?php 
                                                        $subroute = ($child->activesub->implode('route', ','));

                                                        $subroute =  explode(',', $subroute);
                                                    ?>
                                                    @if( request()->is(($subroute)))
                                                    <ul class="side-menu__sub-open backcolor">
                                                    @else
                                                    <ul class="backcolor">
                                                    @endif
                                                    <div class="row">
                                                      @foreach($child->activesub as $subkey => $sub)
                                                            <!-- sub -->
                                                          @if(auth()->user()->hasPermission(json_decode($sub->permission)) || auth()->user()->hasPermission('*'))

                                                              <li style="margin-top:5px;margin-bottom:5px">
                                                                  <a href="/{{$sub->route}}" class="side-menu side-menu{{ request()->is($sub->route)? '--active' : '' }}">
                                                                      <div class="side-menu__icon" style="float: left;margin-right: 15px;"> 
                                                                        @if($sub->icon) 
                                                                            <i data-feather="{{$sub->icon}}"></i>
                                                                          @else
                                                                            <i data-feather="layout"></i>
                                                                          @endif
                                                                      </div>
                                                                      <div class="side-menu__title">@if($locale ==  'en') {{$sub->name_en}} @else {{$sub->name_bm}} @endif</div>
                                                                  </a>
                                                              </li>

                                                          @endif
                                                      @endforeach 
                                                  </div>

                                                    </ul>
                                                  </li>
                                                  @endif

                                            @else


                                                <!-- child  -->

                                                @if(auth()->user()->hasPermission(json_decode($child->permission)) || auth()->user()->hasPermission('*'))
                                                <li style="margin-bottom:15px;margin-left:10px">
                                                    <a href="/{{$child->route}}" class="side-menu side-menu{{ request()->is($child->route)? '--active' : '' }}">
                                                        <div class="side-menu__icon" style="float: left;margin-right: 15px;"> 

                                                          @if($child->icon) 
                                                            <i data-feather="{{$child->icon}}"></i>
                                                          @else
                                                            <i data-feather="layout"></i>
                                                          @endif
                                                        </div>
                                                        <div class="side-menu__title">@if($locale ==  'en') {{$child->name_en}} @else {{$child->name_bm}} @endif </div>
                                                    </a>
                                                </li>
                                                @endif

                                            @endif

                                        @endforeach 
                                        </ul>
                                    </li>
                                    <div class="side-nav__devider my-6 lines"></div>
                                    @endif

                                @else 

                                    <!-- main -->
                                    @if(auth()->user()->hasPermission(json_decode($mainmenu->permission)) || auth()->user()->hasPermission('*'))

                                      <li>
                                          <a href="/{{$mainmenu->route}}" class="side-menu side-menu{{ request()->is($mainmenu->route) ? '--active' : '' }}">
                                              <div class="side-menu__icon" style="float: left;margin-right: 15px;"> 
                                                @if($mainmenu->icon) 
                                                  <i data-feather="{{$mainmenu->icon}}"></i>
                                                @else
                                                  <i data-feather="layout"></i>
                                                @endif
                                              </div>
                                              <div class="side-menu__title">

                                                  @if($locale ==  'en') {{$mainmenu->name_en}} @else {{$mainmenu->name_bm}} @endif                                         
                                              </div>
                                          </a>
                                        
                                      </li>
                                      <div class="side-nav__devider my-6 lines"></div>


                                    @endif


                                @endif

                            @endif

                        @endforeach 


                @elseif(auth()->user()->status == 2)
                    <li>
                        <a href="" class="side-menu side-menu {{ request()->is('home') ? '--active' : '' }}">
                            <div class="side-menu__icon" style="float: left;margin-right: 15px;"> <i data-feather="home"></i> </div>
                            <div class="side-menu__title">
                                You are not allowed to use the system
                            </div>
                        </a>
                    </li>
                @else
                    <li>
                        <a href="" class="side-menu side-menu {{ request()->is('home') ? '--active' : '' }}">
                            <div class="side-menu__icon" style="float: left;margin-right: 15px;"> <i data-feather="home"></i> </div>
                            <div class="side-menu__title">
                                Your Access is still inactive
                            </div>
                        </a>
                    </li>
                @endif
              
            </ul>
        </nav>


    </div>
</div>

@push('script')

<script type="text/javascript">

      function updatenotis(id)
      {
            //update notis
            var ids = id;

            $.ajax({
                    url: "{{ URL::to('/backend/notisread/')}}"+"/"+ids,
                    type: "get",
                    beforeSend: function () 
                    {
                       
                   
                    },
                    success: function(url)
                    {       
                       window.location.replace(url);
                    }


                });

                
          // alert('clicked');
      }
</script>

@endpush