@extends('master')
@section('content')
<style>
  .catergories::before {
    background: #fff;
  }
  .category-item {
    box-shadow: 0px 3.59817px 28.7854px rgba(0, 0, 0, 0.1);
  }
</style>
{{-- <x-slot name="header">
    <h2 class="font-semibold text-xl text-gray-800 leading-tight">
        {{ __('Dashboard') }}
    </h2>
</x-slot> --}}


@if (session()->has('message'))
    <div class="alert alert-icon-right alert-success alert-dismissible mt-2" role="alert">
        <span class="alert-icon">
            <i class="la la-info"></i>
        </span>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
        </button>
        <strong>{{ session('message') }}</strong>
    </div>
@endif
<section class="banner bg-img-none">
    <img src="{{ asset('img/frontend/banner-dow.jpg') }}" alt="Banner image">
    <div class="banner-content">
      <div class="container">
        <div class="row">
          <div class="col-12 col-sm-10 col-md-9 col-lg-7 col-xl-6">
            <h1>Downloads</h1>
          </div>
        </div>
      </div>
    </div>
  </section>

@include('frontend/downloadfilter')

  <section class="downloads-details mobileFilterHeader pb-4">
    <div class="container">
      <h2>List of downloaded files</h2>
      <div class="filterIcon" onclick="showfilterModal();" class="btn btn-primary" data-toggle="modal">
        <svg width="17" height="15" viewBox="0 0 17 15" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M16 0.5H1C0.867392 0.5 0.740215 0.552679 0.646447 0.646447C0.552678 0.740215 0.5 0.867392 0.5 1V1.835C0.500093 1.95309 0.523557 2.07 0.569038 2.17898C0.61452 2.28797 0.68112 2.38687 0.765 2.47L6.5 8.29V13.39L7.5 13.77V8C7.50038 7.9342 7.48777 7.86897 7.46289 7.80805C7.438 7.74713 7.40134 7.69172 7.355 7.645L1.5 1.795V1.5H15.5V1.805L9.665 7.645C9.61503 7.69003 9.57467 7.74468 9.54631 7.80568C9.51796 7.86668 9.50221 7.93277 9.5 8V14.605L10.5 15V8.25L16.235 2.5C16.3202 2.41476 16.3876 2.31336 16.4331 2.20174C16.4786 2.09012 16.5013 1.97053 16.5 1.85V1C16.5 0.867392 16.4473 0.740215 16.3536 0.646447C16.2598 0.552679 16.1326 0.5 16 0.5Z" fill="white"/>
        </svg>
      </div>
    </div>
  </section>
  <section class="category-details downloads-details pt-0">
    <div class="container">
      <div class="row">
        <div class="col-12">
          @forelse($result as $results)
            @if($results->type == 'd')
            @if(isset($datarepodetsIndexed[$results->datarepository_id]))
          <div class="cata-content py-4 py-sm-5">
            <h5>{{$datarepodetsIndexed[$results->datarepository_id]['title']}}</h5>

            <div class="subHead pb-2">
              @if( isset( $categories[$results->category_id] ))
                @if( $categories[$results->category_id]['sub_of'] == NULL )
                  <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Category"><img src="{{ asset('img/frontend/category.svg') }}" alt="" ><span>{{$categories[$results->category_id]['categoryname']}}</span></div>
                @else
                  <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Category"><img src="{{ asset('img/frontend/category.svg') }}" alt="" ><span>{{$categories[$categories[$results->category_id]['sub_of']]['categoryname']}}</span> </div>
                  
                  <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Sub-category"><img src="{{ asset('img/frontend/sub-cat.svg') }}" alt="" ><span>{{$categories[$results->category_id]['categoryname']}}</span></div>
                @endif
              @endif

               <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Classification"><img src="{{ asset('img/frontend/file.svg') }}" alt="" ><span>{{$fileAcces[$datarepodetsIndexed[$results->datarepository_id]['doc_priority']]}}</span></div>
               
               <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Published Date"><span><img src="{{ asset('img/frontend/date.svg') }}" alt="" >@if(!empty($results->datarepository_id) && isset($results->datarepository_id) && isset($datarepodetsIndexed[$results->datarepository_id]['publish_date'])){{date("d M Y", strtotime($datarepodetsIndexed[$results->datarepository_id]['publish_date']))}}@else -- @endif</span></div>
               
               <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Data Source"><span><img src="{{ asset('img/frontend/data-repository.svg') }}" alt="" >Data Repository</span></div>
            </div>
            <div id="description_{{$results->id}}">{!!substr( $datarepodetsIndexed[$results->datarepository_id]['description'],0,400) !!} @if(strlen ( $datarepodetsIndexed[$results->datarepository_id]['description']) > 400)... <a class="readmore" href="javascript:void(0)" onclick="readMore('{{$results->id}}');">View More</a> @endif</div>

             <div id="fulldescripton_{{$results->id}}"  class="listDecs pl-1" style="display:none;" >{!! $datarepodetsIndexed[$results->datarepository_id]['description'] !!}<a class="readmore" href="javascript:void(0)" onclick="readLess('{{$results->id}}');"> View Less</a></div>

            <div class="row mt-3">
              <div class="col-12 mb-2">
                @if($datarepodetsIndexed[$results->datarepository_id]['doc_path'] != '')
                  <a href="{{url('download/'.$results->datarepository_id)}}"><svg width="14" height="16" viewBox="0 0 14 16" fill="none"xmlns="http://www.w3.org/2000/svg"><path
                  d="M12.8334 5.5H9.50004V0.5H4.50004V5.5H1.16671L7.00004 12.1667L12.8334 5.5ZM0.333374 13.8333H13.6667V15.5H0.333374V13.8333Z"
                  fill="#2B7DF7" /></svg>{{$datarepodetsIndexed[$results->datarepository_id]['doc_name']}}</a>
                @endif   
              </div>
              @if(ENVIRONMENT == 'Development')
              @if(Session::has('user.userID') )
              <div class="col-12">
                <div class="dowload-details">
                  <span>Downloaded Count : <span class="downResult"> @if(isset($results->total) && $results->total > 0 ) {{$results->total}} @else -- @endif</span></span> <sab>|</sab> <span>Last Downloaded :<span class="downResult"> 
                    {{date("d M Y - g:i A", strtotime($results->lastdownload))}}</span></span>
                  <!-- <sab>|</sab> <span class="ModelDownload"> <a href="javascript:void(0)">Download Summary</a></span> -->
                </div>
              </div>
              @endif
              @endif
            </div>
        </div>
            @endif
            @elseif($results->type == 'q')
          <div class="cata-content py-4 py-sm-5">
              <h5>{{$quicklinkdetsIndexed[$results->datarepository_id]['title']}}</h5>

            <div class="subHead pb-2">
              @if( isset( $quicklinkcategories[$results->category_id] ))
                   <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Category"><img src="{{ asset('img/frontend/category.svg') }}" alt="" ><span>{{$quicklinkcategories[$results->category_id]['categoryname']}}</span></div>
              @endif

               <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Document Published Date"><img src="{{ asset('img/frontend/date.svg') }}" alt="" ><span>@if(!empty($results->datarepository_id) && isset($results->datarepository_id) && isset($quicklinkdetsIndexed[$results->datarepository_id]['publish_date'])){{date("d M Y", strtotime($quicklinkdetsIndexed[$results->datarepository_id]['publish_date']))}}@else -- @endif</span></div>
               
               <div class="subItems" data-toggle="tooltip" data-placement="bottom" title="Data Source"><span><img src="{{ asset('img/frontend/quick-link.svg') }}"/>Quick Links</span></div>
            </div>
            <div id="description_{{$results->id}}">{!!substr( $quicklinkdetsIndexed[$results->datarepository_id]['description'],0,400) !!} @if(strlen ( $quicklinkdetsIndexed[$results->datarepository_id]['description']) > 400)... <a class="readmore" href="javascript:void(0)" onclick="readMore('{{$results->id}}');">View More</a> @endif</div>

             <div id="fulldescripton_{{$results->id}}"  class="listDecs" style="display:none;" >{!! $quicklinkdetsIndexed[$results->datarepository_id]['description'] !!}<a class="readmore pl-1" href="javascript:void(0)" onclick="readLess('{{$results->id}}');"> View Less</a></div>

            <div class="row mt-3">
              <div class="col-12 mb-2">
                @if($quicklinkdetsIndexed[$results->datarepository_id]['doc_path'] != '')
                  <a href="{{url('download/'.$results->datarepository_id)}}"><svg width="14" height="16" viewBox="0 0 14 16" fill="none"xmlns="http://www.w3.org/2000/svg"><path
                  d="M12.8334 5.5H9.50004V0.5H4.50004V5.5H1.16671L7.00004 12.1667L12.8334 5.5ZM0.333374 13.8333H13.6667V15.5H0.333374V13.8333Z"
                  fill="#2B7DF7" /></svg>{{$quicklinkdetsIndexed[$results->datarepository_id]['doc_name']}}</a>
                @endif   
              </div>
              @if(ENVIRONMENT == 'Development')
              @if(Session::has('user.userID') )
              <div class="col-12">
                <div class="dowload-details">
                  <span>Downloaded Count : <span class="downResult">@if(isset($results->total) && $results->total > 0 ) {{$results->total}} @else -- @endif</span></span> <sab>|</sab> <span>Last Downloaded : <span class="downResult"> 
                    {{date("d M Y - g:i A", strtotime($results->lastdownload))}}</span></span>
                    <!-- <sab>|</sab> <span class="ModelDownload"> <a href="javascript:void(0)">Download Summary</a></span> -->
                </div>
              </div>
              @endif
              @endif
            </div>
            </div>
            @endif
          @empty
            <div class="w-100 pt-3">
              <div class="no-data mb-4">
                <i class="fas fa-exclamation-triangle"></i>
                <h5>No records found</h5>
              </div>
            </div>
          @endforelse
          {{$result->links("pagination::bootstrap-4")}}
        </div>   
      </div>
    </div>
  </section>
  <script type="text/javascript">
  function showfilterModal(){
        $("#filterModal").modal('show');
  }  
  function readMore(id){
    $("#description_"+id).hide();
    $("#fulldescripton_"+id).show();
  }
  function readLess(id){
    $("#fulldescripton_"+id).hide();
    $("#description_"+id).show();
    
  }
  </script>
    @stop