

<?php $__env->startSection('content'); ?>
<div class="space-y-8">
    
    <div class="flex flex-col md:flex-row md:items-center md:justify-between bg-white p-6 rounded-2xl border border-gray-100 shadow-sm gap-4">
        <div>
            <h1 class="text-2xl font-black text-gray-800 tracking-tight">Selamat Datang Kembali, <?php echo e(auth()->user()->name); ?>!</h1>
            <p class="text-sm text-gray-500 mt-1">Berikut adalah ringkasan performa operasional dan produksi Tempe Zhi hari ini.</p>
        </div>
        <div class="text-sm font-bold text-green-800 bg-green-50 px-4 py-2 rounded-xl border border-green-100 self-start md:self-auto">
            <?php echo e(\Carbon\Carbon::now()->isoFormat('D MMMM YYYY')); ?>

        </div>
    </div>


    
    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
        
        <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm flex items-center justify-between hover:shadow-md transition-all">
            <div>
                <p class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Mitra Bisnis</p>
                <h3 class="text-2xl font-black text-gray-800 mt-1">
                    <?php echo e($totalMitra); ?> <span class="text-xs font-normal text-gray-400">Aktif</span>
                </h3>
                <a href="<?php echo e(route('admin.mitra.index')); ?>" class="inline-block text-[11px] font-bold text-green-700 mt-2 hover:underline">Detail Mitra &rarr;</a>
            </div>
            <div class="p-3 bg-green-50 text-green-700 rounded-xl">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                </svg>
            </div>
        </div>

        <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm flex items-center justify-between hover:shadow-md transition-all">
            <div>
                <p class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Varian Produk</p>
                <h3 class="text-2xl font-black text-gray-800 mt-1">
                    <?php echo e($totalProduk); ?> <span class="text-xs font-normal text-gray-400">Jenis</span>
                </h3>
                <span class="inline-block text-[11px] text-gray-400 mt-2">Item terdaftar</span>
            </div>
            <div class="p-3 bg-teal-50 text-teal-600 rounded-xl">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l-8 4" />
                </svg>
            </div>
        </div>

        <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm flex items-center justify-between hover:shadow-md transition-all">
            <div>
                <p class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Kunjungan Industri</p>
                <h3 class="text-2xl font-black <?php echo e($kunjunganMenunggu > 0 ? 'text-amber-600' : 'text-gray-800'); ?> mt-1">
                    <?php echo e($kunjunganMenunggu); ?> <span class="text-xs font-normal text-gray-400">Antrean</span>
                </h3>
                <span class="inline-block text-[11px] font-semibold <?php echo e($kunjunganMenunggu > 0 ? 'text-amber-600' : 'text-gray-400'); ?> mt-2">
                    <?php echo e($kunjunganMenunggu > 0 ? 'Butuh Konfirmasi' : 'Belum ada pengajuan'); ?>

                </span>
            </div>
            <div class="p-3 <?php echo e($kunjunganMenunggu > 0 ? 'bg-amber-50 text-amber-600 animate-pulse' : 'bg-gray-50 text-gray-400'); ?> rounded-xl">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
            </div>
        </div>

        
        <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm flex flex-col justify-between hover:shadow-md transition-all">
            <div class="flex items-center justify-between w-full">
                <div>
                    <p class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Stok Kritis (&le; 5)</p>
                    
                </div>
                <div class="p-3 <?php echo e($bahanKritis->isNotEmpty() ? 'bg-red-50 text-red-600' : 'bg-gray-50 text-gray-400'); ?> rounded-xl">
                    <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
                    </svg>
                </div>
            </div>
            
            
            <div class="space-y-1.5 pt-2 mt-2 border-t border-gray-50 max-h-[65px] overflow-y-auto">
                <?php if($bahanKritis->isNotEmpty()): ?>
                    <?php $__currentLoopData = $bahanKritis; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="flex justify-between items-center text-[11px] font-bold">
                            <span class="text-gray-600 truncate max-w-[120px]"><?php echo e($item->bahanbaku->nama_bahan ?? 'Bahan Terhapus'); ?></span>
                            <span class="text-red-600 bg-red-50 px-1.5 py-0.5 rounded font-extrabold text-[10px]">Sisa: <?php echo e($item->stok); ?></span>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php else: ?>
                    <span class="inline-block text-[11px] font-semibold text-gray-400">Kondisi Aman</span>
                <?php endif; ?>
            </div>
        </div>

    </div>

    
    <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm mb-8" x-data="{ rentang: 'minggu' }">
        <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-3">
            <div>
                <h3 class="font-bold text-gray-800 text-base">Grafik Tren Hasil Produksi Tempe</h3>
                <p class="text-xs text-gray-400">Data kuantitas total pencatatan produk jadi dari hari ke hari.</p>
            </div>
            
            
            <div class="bg-gray-100 p-1 rounded-xl flex gap-1 self-end sm:self-auto">
                <button @click="rentang = 'minggu'; perbaruiChart('minggu')" 
                        :class="rentang === 'minggu' ? 'bg-white text-green-800 shadow-sm' : 'text-gray-500 hover:text-gray-800'"
                        class="px-4 py-1.5 rounded-lg text-xs font-bold transition-all cursor-pointer">
                    1 Minggu
                </button>
                <button @click="rentang = 'bulan'; perbaruiChart('bulan')" 
                        :class="rentang === 'bulan' ? 'bg-white text-green-800 shadow-sm' : 'text-gray-500 hover:text-gray-800'"
                        class="px-4 py-1.5 rounded-lg text-xs font-bold transition-all cursor-pointer">
                    1 Bulan
                </button>
            </div>
        </div>
        
        
        <div class="w-full h-[320px]">
            <canvas id="produksiChart"></canvas>
        </div>
    </div>

    
    <div class="bg-white p-6 rounded-[30px] border border-gray-100 shadow-sm">
        <div class="flex justify-between items-center mb-4">
            <div>
                <h3 class="font-bold text-gray-800 text-base">Aktivitas Pesanan Terkini</h3>
                <p class="text-xs text-gray-400 mt-0.5">Daftar 5 transaksi terbaru dari pihak customer-mitra.</p>
            </div>
            <a href="<?php echo e(route('pesanan.index')); ?>" class="text-xs font-bold text-green-700 hover:underline">Semua Pesanan &rarr;</a>
        </div>
        
        <div class="overflow-x-auto">
            <table class="w-full text-left text-sm">
                <thead>
                    <tr class="text-gray-400 text-xs uppercase border-b border-gray-50">
                        <th class="py-3 font-bold">Kode Transaksi</th>
                        <th class="py-3 font-bold">Nama Mitra</th>
                        <th class="py-3 font-bold text-center">Status Alur</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50 text-gray-700 font-medium">
                    <?php $__empty_1 = true; $__currentLoopData = $pesananTerbaru; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="hover:bg-gray-50/50 transition-colors">
                        <td class="py-3.5 font-bold text-gray-800">#<?php echo e($p->kode_pesanan); ?></td>
                        <td class="py-3.5 text-xs text-gray-600"><?php echo e($p->user->name ?? 'Mitra'); ?></td>
                        <td class="py-3.5 text-center">
                            <span class="inline-block text-[9px] font-extrabold px-3 py-1 rounded-full uppercase tracking-wider
                                <?php echo e($p->status == 'pending' ? 'bg-red-50 text-red-600 border border-red-100' : ''); ?>

                                <?php echo e($p->status == 'dijadwalkan' ? 'bg-blue-50 text-blue-600 border border-blue-100' : ''); ?>

                                <?php echo e($p->status == 'dikirim' ? 'bg-yellow-50 text-yellow-600 border border-yellow-100' : ''); ?>">
                                <?php echo e($p->status); ?>

                            </span>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="3" class="py-8 text-center text-xs text-gray-400 italic">Belum ada pesanan masuk dalam sistem.</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

</div>


<script>
    const ctx = document.getElementById('produksiChart').getContext('2d');
    
    // Parsing data array dari Controller Laravel ke JSON Javascript Objek
    const dataGrafik = {
        minggu: {
            labels: <?php echo json_encode($chartMingguLabels); ?>,
            data: <?php echo json_encode($chartMingguData); ?>

        },
        bulan: {
            labels: <?php echo json_encode($chartBulanLabels); ?>,
            data: <?php echo json_encode($chartBulanData); ?>

        }
    };

    // Render Awal Grafik Line (Default Rentang 1 Minggu)
    let produksiChart = new Chart(ctx, {
        type: 'line',
        data: {
            labels: dataGrafik.minggu.labels,
            datasets: [{
                label: 'Total Hasil Produksi (pcs)',
                data: dataGrafik.minggu.data,
                backgroundColor: 'rgba(21, 128, 61, 0.08)', // Warna gradasi bawah garis hiasan
                borderColor: 'rgba(21, 128, 61, 1)', // Warna utama garis
                borderWidth: 3,
                pointBackgroundColor: 'rgba(21, 128, 61, 1)',
                pointRadius: 4,
                pointHoverRadius: 6,
                tension: 0.3, // Efek kelengkungan kurva halus (Smooth curve)
                fill: true
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: { display: false } // Sembunyikan label kotak default atas
            },
            scales: {
                y: {
                    beginAtZero: true,
                    grid: { color: '#f9fafb' },
                    ticks: { font: { size: 11, family: 'sans-serif' } }
                },
                x: {
                    grid: { display: false },
                    ticks: { font: { size: 10, weight: '500' } }
                }
            }
        }
    });

    // Trigger Aksi Penggantian Tipe Rentang Waktu Grafik (Client-side manipulasi)
    function perbaruiChart(rentangWaktu) {
        produksiChart.data.labels = dataGrafik[rentangWaktu].labels;
        produksiChart.data.datasets[0].data = dataGrafik[rentangWaktu].data;
        
        // Atur ukuran bulatan titik koordinat agar tidak menumpuk padat saat sebulan penuh
        if (rentangWaktu === 'bulan') {
            produksiChart.data.datasets[0].pointRadius = 1.5;
            produksiChart.data.datasets[0].pointHoverRadius = 4;
        } else {
            produksiChart.data.datasets[0].pointRadius = 4;
            produksiChart.data.datasets[0].pointHoverRadius = 6;
        }
        
        // Perintahkan Chart.js me-render ulang grafik komponen
        produksiChart.update();
    }
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\TempeZhi\resources\views/admin/dashboard.blade.php ENDPATH**/ ?>