<?php $__env->startSection('title', 'Riwayat Pergerakan Stok'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-6">
    <!-- Header -->
    <div class="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
        <h2 class="text-2xl font-bold text-gray-800 flex items-center gap-2">
            <i class="bi bi-clock-history text-primary"></i>
            Riwayat Stok (Stock Logs)
        </h2>
        <a href="<?php echo e(route('admin.stock_logs.create')); ?>" class="px-5 py-2.5 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-xl shadow-sm transition flex items-center gap-2">
            <i class="bi bi-plus-lg text-sm"></i> Tambah Stok
        </a>
    </div>

    <!-- Filter -->
    <div class="bg-white p-4 rounded-2xl shadow-sm border border-gray-200">
        <form method="GET" action="<?php echo e(route('admin.stock_logs.index')); ?>" class="flex gap-4">
            <div class="flex-1">
                <select name="produk_id" class="w-full text-sm border-gray-300 rounded-lg focus:ring-primary focus:border-primary">
                    <option value="">-- Semua Produk --</option>
                    <?php $__currentLoopData = $produks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $produk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($produk->id); ?>" <?php echo e(request('produk_id') == $produk->id ? 'selected' : ''); ?>>
                            <?php echo e($produk->nama); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <button type="submit" class="px-5 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition shadow-sm">
                Filter
            </button>
            <?php if(request()->filled('produk_id')): ?>
                <a href="<?php echo e(route('admin.stock_logs.index')); ?>" class="px-5 py-2 bg-gray-100 text-gray-700 text-sm font-medium rounded-lg hover:bg-gray-200 transition">
                    Reset
                </a>
            <?php endif; ?>
        </form>
    </div>

    <!-- Table -->
    <div class="bg-white border border-gray-200 rounded-2xl shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full text-sm text-left text-gray-600">
                <thead class="bg-gray-50 text-xs uppercase text-gray-500">
                    <tr>
                        <th class="px-6 py-3">Tanggal Waktu</th>
                        <th class="px-6 py-3">Produk & Varian</th>
                        <th class="px-6 py-3">User</th>
                        <th class="px-6 py-3">Tipe</th>
                        <th class="px-6 py-3 text-center">+/-</th>
                        <th class="px-6 py-3 text-center">Stok Sblm &rarr; Ssdh</th>
                        <th class="px-6 py-3">Keterangan</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    <?php $__empty_1 = true; $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="hover:bg-gray-50 transition">
                        <td class="px-6 py-4">
                            <?php echo e($log->created_at->format('d M Y, H:i')); ?>

                        </td>
                        <td class="px-6 py-4">
                            <span class="font-medium text-gray-800 tracking-tight"><?php echo e($log->produkVarian->produk->nama ?? 'Produk Terhapus'); ?></span>
                            <div class="text-xs text-gray-500 mt-1">
                                Varian: <?php echo e($log->produkVarian->ukuran ?? '-'); ?> / <?php echo e($log->produkVarian->warna ?? '-'); ?>

                                <?php if($log->produkVarian && $log->produkVarian->sku): ?>
                                 (SKU: <?php echo e($log->produkVarian->sku); ?>)
                                <?php endif; ?>
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            <?php echo e($log->user->nama ?? ($log->user->name ?? 'Sistem')); ?>

                        </td>
                        <td class="px-6 py-4">
                            <?php if($log->tipe_pergerakan == 'in'): ?>
                                <span class="px-2 py-1 text-[10px] font-bold tracking-wider rounded bg-green-100 text-green-700 uppercase">Input</span>
                            <?php elseif($log->tipe_pergerakan == 'out'): ?>
                                <span class="px-2 py-1 text-[10px] font-bold tracking-wider rounded bg-red-100 text-red-700 uppercase">Output</span>
                            <?php else: ?>
                                <span class="px-2 py-1 text-[10px] font-bold tracking-wider rounded bg-blue-100 text-blue-700 uppercase">Adjust</span>
                            <?php endif; ?>
                        </td>
                        <td class="px-6 py-4 text-center font-bold <?php echo e($log->tipe_pergerakan == 'out' ? 'text-red-500' : 'text-green-600'); ?>">
                            <?php echo e($log->tipe_pergerakan == 'out' ? '-' : '+'); ?><?php echo e(abs($log->jumlah)); ?>

                        </td>
                        <td class="px-6 py-4 text-center text-gray-500 font-medium">
                            <?php echo e($log->stok_sebelum); ?> <i class="bi bi-arrow-right mx-1"></i> <span class="text-gray-900 border-b border-gray-300 pb-0.5"><?php echo e($log->stok_sesudah); ?></span>
                        </td>
                        <td class="px-6 py-4 text-xs text-gray-500">
                            <?php echo e($log->keterangan ?? '-'); ?>

                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="7" class="text-center py-12">
                            <div class="flex flex-col items-center text-gray-400">
                                <i class="bi bi-clock-history text-4xl mb-3 border-2 border-gray-200 rounded-full p-4 border-dashed"></i>
                                <p>Belum ada riwayat pergerakan stok</p>
                            </div>
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <div class="px-6 py-4 border-t border-gray-100 bg-gray-50">
            <?php echo e($logs->links()); ?>

        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\Toko-miftah\resources\views/admin/stock_logs/index.blade.php ENDPATH**/ ?>