@extends('layouts.master')
@section('content')
<!-- Page Title Start -->
<div class="flex justify-between items-center mb-6">
    <h4 class="text-slate-900 dark:text-slate-200 text-lg font-medium">Dashboard</h4>
</div>
<!-- Page Title End -->

@if(session('group_id') == 1)
<div class="grid xl:grid-cols-4 lg:grid-cols-2 grid-cols-1 gap-6 mb-6">
    @foreach($group as $dataGroup)
    <?php
        $bg = '';

        if(@$dataGroup->alias == 'dinas'){
            $bg = 'success';
        }elseif(@$dataGroup->alias == 'biro'){
            $bg = 'warning';
        }elseif(@$dataGroup->alias == 'badan'){
            $bg = 'danger';
        }elseif(@$dataGroup->alias == 'deputi'){
            $bg = 'info';
        }

    ?>
    <div class="card border-top-{{$bg}}">
        <div class="p-6">
            <div class="flex flex-col items-center">
                <div class="w-full">
                    {{-- <div class="flex justify-between">
                        <div class="p-1 bg-primary text-white rounded text-xs">{{date('Y')}}</div>
                    </div> --}}
                    <div class="flex items-center justify-between">
                        <div class="px-4 py-3 rounded-full bg-{{$bg}}-light">
                            <i class="ri-database-2-line text-lg text-{{$bg}}"></i>
                        </div>
                        <div>
                            <?php
                            $count = $classDataset::where('tahun',date('Y'))->whereHas('instansi',function($query) use ($dataGroup){
                                $query->where('parent','ilike','%'.$dataGroup->alias.'%');
                            })->count();
                            ?>
                            <h2 class="text-3xl bold my-3 py-0.5">{{$count}}</h2> 
                        </div>
                    </div>
                    
                </div>
                <div class="w-full">
                    <div class="">
                        <div class="mb-2"><h5 class="uppercase text-sm font-bold mt-0 truncate">Data {{$dataGroup->name}}</h5></div>
                        <a href="{{url('dashboard/dataset/'.$dataGroup->alias)}}" class="text-{{ $bg }} text-xs">Lihat Selengkapnya&nbsp;<i class="ri-arrow-right-line"></i></a>
                    </div>
                </div>
            </div> <!-- end row-->
        </div> <!-- end p-6 -->
    </div> <!-- end card -->
    @endforeach

    
</div>
@endif
<div class="grid xl:grid-cols-1 lg:grid-cols-1 grid-cols-1 gap-6 mb-6">
    <div class="card">
        <div class="p-6">
            <div>
                <div class="mb-5">
                    <h5 class="text-md font-bold">10 Data Update Terakhir</h5>
                </div>
                <table class="gridjs-table" >
                  <thead class="gridjs-thead">
                    <tr class="gridjs-tr bg-primary-light">
                      <th width="15%" class="gridjs-td gridjs-th text-sm">#</th>
                      <th class="gridjs-td gridjs-th text-sm">No</th>
                      <th class="gridjs-td gridjs-th text-sm">Resource Data</th>
                      <th class="gridjs-td gridjs-th text-sm">Jumlah Upload Dataset</th>
                    </tr>
                  </thead>
                  <tbody class="gridjs-tbody">
                    @foreach ($resource as $k => $res)
                        <tr class="gridjs-tr">
                        <td class="gridjs-td gridjs-th text-sm">
                            @if(session('group_id') == 1)
                                <a href="{{ url('dashboard/dataset/resource/'.encode_id($res->MsTemplateId)) }}" class="btn w-full bg-success text-white">Lihat Data</a>
                            @else
                                <a href="{{ url('dashboard/dataset/resource/instansi/'.encode_id(auth()->user()->ms_instansi_id).'/'.encode_id($res->MsTemplateId)) }}" class="btn w-full bg-success text-white">Lihat Data</a>
                            @endif
                        </td>
                        <td class="gridjs-td gridjs-th text-sm">{{$k+1}}</td>
                        <td class="gridjs-td gridjs-th text-sm">{{ $res->name }}</td>
                        <td class="gridjs-td gridjs-th text-sm text-center">{{ $res->dataset->count() }}</td>
                        </tr>
                    @endforeach
                  </tbody>
              </table>
            </div>
        </div>
    </div>
</div>
<div class="grid xl:grid-cols-1 lg:grid-cols-1 grid-cols-1 gap-6 mb-6 hidden">
    <div class="card">
        <div class="p-6">
            <div>
                <div id="toolbar">
                    <h5 class="text-md font-bold">10 Data Update Terakhir</h5>
                </div>
                <table class="gridjs-table" 
                    data-search="true"
                    data-toggle="table"
                    data-pagination="true"
                    data-toolbar="#toolbar"
                    data-show-refresh="false"
                    data-url="{{route('modules.dashboard.grid')}}"
                    data-sort-name="ids"
                    data-sort-order="desc"
                    data-page-size="10"
                    data-id-field="id"
                    id="grid-data">
                  <thead class="gridjs-thead">
                    <tr class="gridjs-tr bg-primary-light">
                      <th class="gridjs-td gridjs-th text-sm" data-width="10" data-field="action">#</th>
                      <th class="gridjs-td gridjs-th text-sm" data-width="10" data-field="no">No</th>
                      <th class="gridjs-td gridjs-th text-sm" data-field="instansi">Nama Instansi</th>
                      <th class="gridjs-td gridjs-th text-sm" data-field="name">Nama Dataset</th>
                      <th class="gridjs-td gridjs-th text-sm" data-field="tahun">Tahun</th>
                      <th class="gridjs-td gridjs-th text-sm text-center" data-field="status">Status</th>
                      <th class="gridjs-td gridjs-th text-sm" data-field="created_at">Tanggal Dibuat</th>
                    </tr>
                  </thead>
                  <tbody class="gridjs-tbody"></tbody>
              </table>
            </div>
        </div>
    </div>
</div>
<!-- end row -->
@endsection
@section('js')
<script src="{{asset('assets/js/pages/dashboard-analytics.js')}}"></script>
<!-- Apex Charts js -->
<script src="{{asset('assets/libs/apexcharts/apexcharts.min.js')}}"></script>

<!-- Vector Map Js -->
<script src="{{asset('assets/libs/jsvectormap/js/jsvectormap.min.js')}}"></script>
<script src="{{asset('assets/libs/jsvectormap/maps/world-merc.js')}}"></script>
<script src="{{asset('assets/libs/jsvectormap/maps/world.js')}}"></script>
@endsection