@extends('layouts.master')
@section('content')
<style>
</style>
    <div class="flex-1 overflow-y-auto p-8 custom-scrollbar">
        
        <!-- Stats Cards -->
        <div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-3  gap-6 mb-8">
            <!-- Card 1 -->
            <div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
                <div class="flex justify-between items-start mb-4">
                    <div class="p-2 bg-blue-50 rounded-lg text-blue-600">
                        <i data-lucide="database" class="w-5 h-5"></i>
                    </div>
                </div>
                <p class="text-slate-500 text-[10px] font-bold uppercase tracking-wider">Dataset Utama Terinput</p>
                <h4 class="text-2xl font-black text-slate-900 mt-1">{{ $dataset }}</h4>
            </div>
            <!-- Card 2 -->
            <div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
                <div class="flex justify-between items-start mb-4">
                    <div class="p-2 bg-green-50 rounded-lg text-green-600">
                        <i data-lucide="database" class="w-5 h-5"></i>
                    </div>
                </div>
                <p class="text-slate-500 text-[10px] font-bold uppercase tracking-wider">Dataset Tambahan Terinput</p>
                <h4 class="text-2xl font-black text-slate-900 mt-1">{{$datasetTambahan}}</h4>
            </div>
            <!-- Card 3 -->
            
            <!-- Card 4 -->
            
            <div class="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow">
                <div class="flex justify-between items-start mb-4">
                    <div class="p-2 bg-purple-50 rounded-lg text-purple-600">
                        <i data-lucide="upload" class="w-5 h-5"></i>
                    </div>
                    <?php
                        $persentase = (($total/@$datasetInstansi)*100);
                    ?>
                    <span class="text-xs font-bold {{$persentase >= 60 ? 'text-emerald-500 bg-emerald-50' : 'text-red-500 bg-red-50'}}  px-2 py-1 rounded">{{round($persentase)}}%</span>
                </div>
                <p class="text-slate-500 text-[10px] font-bold uppercase tracking-wider">Dataset Utama Instansi Terinput</p>
                <h4 class="text-2xl font-black text-slate-900 mt-1">{{ $total }} / {{ @$datasetInstansi }}</h4>
            </div>
        </div>

        @if((session('group_id') == 1) || (session('group_alias') == 'admin') || (session('group_alias') == 'admin_ta'))
            <!-- Datatable Section -->
            <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">
                <div class="p-6 border-b border-slate-100 flex flex-col md:flex-row md:items-center justify-between gap-4">
                    <div>
                        <h3 class="text-lg font-bold text-slate-900">Mapping Dataset SLHD - Tahun {{date('Y')}}</h3>
                        {{-- <p class="text-xs text-slate-500 font-medium">Pengelolaan data masuk dari berbagai stasiun pemantauan.</p> --}}
                    </div>
                    {{-- <div class="flex items-center space-x-2">
                        <button class="p-2 border border-slate-200 rounded-xl hover:bg-slate-50 transition-colors flex items-center text-sm font-semibold text-slate-600">
                            <i data-lucide="download-cloud" class="w-4 h-4 mr-2"></i> Ekspor
                        </button>
                        <button class="p-2 bg-slate-900 text-white rounded-xl hover:bg-slate-800 transition-colors flex items-center text-sm font-semibold">
                            <i data-lucide="filter" class="w-4 h-4 mr-2"></i> Filter
                        </button>
                    </div> --}}
                </div>

                <div class="overflow-x-auto p-8">
                    
                    <table class="w-full border text-left border-collapse" 
                        data-search="true"
                        data-toggle="table"
                        data-pagination="true"
                        data-toolbar="#toolbar"
                        data-show-refresh="true"
                        data-url="{{route($route.'.gridTabel')}}"
                        data-sort-name="ids"
                        data-sort-order="desc"
                        data-page-size="10"
                        data-id-field="id"
                        id="grid-data">
                        <thead class="bg-slate-100 border-b border-slate-100">
                        <tr>
                            <th class="border font-bold text-slate-900 text-center tengah" data-width="10" data-field="no">No</th>
                            <th class="border font-bold text-slate-900 text-center" data-field="name">Instansi</th>
                            <th class="border font-bold text-slate-900 text-center tengah" data-width="20" data-field="dataset">Dataset</th>
                            <th class="border font-bold text-slate-900 text-center tengah" data-width="20" data-field="persentase">Persentase</th>
                        </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>     
        @else
            <div class="grid grid-cols-1 xl:grid-cols-2 gap-2">
                <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">
                    <div class="p-6 border-b border-slate-100 flex flex-col md:flex-row md:items-center justify-between gap-4">
                        <div>
                            <h3 class="text-lg font-bold text-slate-900">Dataset Utama Tahun {{date('Y')}}</h3>
                        </div>
                    </div>

                    <div class="overflow-x-auto p-8">
                        
                        <table class="w-full border" 
                            data-search="false"
                            data-toggle="table"
                            data-pagination="true"
                            data-toolbar="#toolbar"
                            data-show-refresh="false"
                            data-url="{{route($route.'.gridInstansiUtama')}}"
                            data-sort-name="ids"
                            data-sort-order="desc"
                            data-page-size="10"
                            data-id-field="id"
                            id="grid-data1">
                            <thead class="bg-slate-100 border-b border-slate-100">
                            <tr>
                                <th class="text-[10px] border font-bold text-slate-900 text-center tengah align-middle" style="vertical-align: middle!important;" data-field="action">#</th>
                                <th class="text-[10px] border font-bold text-slate-900 text-center" data-field="name">Dataset</th>
                                <th class="text-[10px] border font-bold text-slate-900 text-center tengah" data-field="pic">PIC</th>
                                <th class="text-[10px] border font-bold text-slate-900 text-center" data-field="status">Status</th>
                            </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>  
                <div class="bg-white rounded-3xl border border-slate-200 shadow-sm overflow-hidden">
                    <div class="p-6 border-b border-slate-100 flex flex-col md:flex-row md:items-center justify-between gap-4">
                        <div>
                            <h3 class="text-lg font-bold text-slate-900">Dataset Tambahan Tahun {{date('Y')}}</h3>
                        </div>
                    </div>

                    <div class="overflow-x-auto p-8">
                        
                        <table class="w-full border text-left border-collapse" 
                            data-search="false"
                            data-toggle="table"
                            data-pagination="true"
                            data-toolbar="#toolbar"
                            data-show-refresh="false"
                            data-url="{{route($route.'.gridInstansiTambahan')}}"
                            data-sort-name="ids"
                            data-sort-order="desc"
                            data-page-size="10"
                            data-id-field="id"
                            id="grid-data2">
                            <thead class="bg-slate-100 border-b border-slate-100">
                            <tr>
                                <th class="text-[10px] border font-bold text-slate-900 text-center tengah" data-width="5" data-field="no">No</th>
                                <th class="text-[10px] border font-bold text-slate-900 text-center" data-field="name">Dataset</th>
                            </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>  
            </div>
        @endif
    </div>

    <div id="modal" class="fixed inset-0 bg-black/50 hidden items-center justify-center z-50">

        <!-- Modal Box -->
        <div class="bg-white w-full max-w-4xl rounded-2xl shadow-2xl p-6 relative animate-scale">
            
            <!-- Close Button -->
            <button 
                onclick="closeModal()" 
                class="absolute top-3 right-3 text-gray-400 hover:text-gray-600 text-xl">
                &times;
            </button>

            <h2 class="text-xl font-bold mb-4 title">Tabel Data Dirjen Bina Marga</h2>
            <table class="w-full border text-left border-collapse" 
                data-search="false"
                data-toggle="table"
                data-pagination="true"
                data-toolbar="#toolbar"
                data-show-refresh="false"
                data-url=""
                data-sort-name="ids"
                data-sort-order="desc"
                data-page-size="10"
                data-id-field="id"
                id="bodyTabelModal">
                <thead class="bg-slate-100 border-b border-slate-100">
                <tr>
                    <th class="text-[10px] border font-bold text-slate-900 text-center tengah" data-width="3" data-field="no">No</th>
                    <th class="text-[10px] border font-bold text-slate-900 text-center" data-field="tabel">Tabel Utama</th>
                    <th class="text-[10px] border font-bold text-slate-900 text-center tengah" data-field="status">Status</th>
                    <th class="text-[10px] border font-bold text-slate-900 text-center" data-field="tanggal">Tanggal Unggah</th>
                </tr>
                </thead>
                <tbody></tbody>
            </table>

            {{-- <table class="w-full border text-left border-collapse">
                <thead class="bg-slate-100 border-b border-slate-100">
                    <tr>
                        <th class="p-2 border font-bold text-slate-900 text-center" data-field="name">No</th>
                        <th class="p-2 border font-bold text-slate-900 text-center" data-field="name">Dataset</th>
                        <th class="p-2 border font-bold text-slate-900 text-center" data-field="name">Tanggal Input</th>
                    </tr>
                </thead>
                <tbody id="bodyTabelModal">
                    <tr>
                        <td class="p-2 border text-slate-900 text-center" data-field="name">1</td>
                        <td class="p-2 border text-slate-900 text-center" data-field="name">Tes</td>
                        <td class="p-2 border text-slate-900 text-center" data-field="name">2</td>
                    </tr>
                </tbody>
            </table> --}}
            

        </div>
    </div>
@endsection
@section('js')
<script>
    $("#grid-data").on("click", ".btnModal", function() {
        
        document.getElementById('modal').classList.remove('hidden');
        document.getElementById('modal').classList.add('flex');

        var id = $(this).attr('data-id');
        var name = $(this).attr('data-name');
        
        var base_url = "{{url('/')}}";
        var html = '';
        var url = base_url + '/getResourceDataDashboard/' + id;
        $('.title').html('Tabel Data '+name);

        $('#bodyTabelModal').bootstrapTable('refresh', {
            url: url
        });
        
    });

function closeModal() {
    document.getElementById('modal').classList.remove('flex');
    document.getElementById('modal').classList.add('hidden');
}
</script>
@endsection