

<?php $__env->startSection('title', 'Invoice'); ?>

<?php $__env->startSection('content'); ?>
<?php
    $isCompact = ($density ?? 'comfortable') === 'compact';
?>
<div class="space-y-6">
    <div class="bg-white border border-gray-100 rounded-2xl shadow-sm p-4 sm:p-5">
        <div class="flex flex-col lg:flex-row lg:items-center justify-between gap-4">
            <div>
                <h1 class="text-xl font-bold text-gray-900">Invoice</h1>
                <p class="text-sm text-gray-500 mt-0.5">Manual, dari service, dan pencatatan pembayaran dalam satu modul.</p>
            </div>
            <div class="flex flex-wrap gap-2">
                <a href="<?php echo e(route('admin.invoices.create')); ?>" class="inline-flex items-center gap-2 rounded-xl bg-brand-600 hover:bg-brand-700 text-white text-sm font-semibold px-4 py-2.5 transition shadow-sm">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
                    </svg>
                    Invoice Manual
                </a>
                <a href="<?php echo e(route('admin.customers.create')); ?>" class="inline-flex items-center gap-2 rounded-xl border border-gray-300 bg-white text-sm font-semibold text-gray-700 px-4 py-2.5 hover:bg-gray-50 transition">
                    Tambah Pelanggan
                </a>
            </div>
        </div>

        <div class="mt-4 flex flex-wrap items-center justify-between gap-3 border-t border-gray-100 pt-4">
            <div>
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Kerapatan Tabel</p>
                <p class="text-xs text-gray-500">Pilih mode nyaman atau padat untuk input harian.</p>
            </div>
            <div class="inline-flex rounded-xl border border-gray-200 bg-gray-50 p-1">
                <a href="<?php echo e(route('admin.invoices.index', request()->except('page') + ['density' => 'comfortable'])); ?>"
                   class="px-3 py-1.5 text-xs font-semibold rounded-lg transition <?php echo e($isCompact ? 'text-gray-600 hover:bg-gray-100' : 'bg-white text-brand-700 shadow-sm'); ?>">
                    Comfortable
                </a>
                <a href="<?php echo e(route('admin.invoices.index', request()->except('page') + ['density' => 'compact'])); ?>"
                   class="px-3 py-1.5 text-xs font-semibold rounded-lg transition <?php echo e($isCompact ? 'bg-white text-brand-700 shadow-sm' : 'text-gray-600 hover:bg-gray-100'); ?>">
                    Compact
                </a>
            </div>
        </div>
    </div>

    <div class="flex flex-col lg:flex-row lg:items-center justify-between gap-4">
        <div>
            <h2 class="text-sm font-semibold uppercase tracking-wide text-gray-400">Ringkasan</h2>
            <p class="text-sm text-gray-500 mt-0.5">Pantau status invoice dan pembayaran dalam satu layar.</p>
        </div>
    </div>

    <div class="grid grid-cols-2 lg:grid-cols-5 gap-4">
        <div class="rounded-2xl bg-white border border-gray-100 p-4 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Draft</p>
            <p class="mt-2 text-2xl font-bold text-gray-900"><?php echo e($stats['draft']); ?></p>
        </div>
        <div class="rounded-2xl bg-white border border-gray-100 p-4 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Review</p>
            <p class="mt-2 text-2xl font-bold text-indigo-600"><?php echo e($stats['review'] ?? 0); ?></p>
        </div>
        <div class="rounded-2xl bg-white border border-gray-100 p-4 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Issued</p>
            <p class="mt-2 text-2xl font-bold text-gray-900"><?php echo e($stats['issued']); ?></p>
        </div>
        <div class="rounded-2xl bg-white border border-gray-100 p-4 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Belum Dibayar</p>
            <p class="mt-2 text-2xl font-bold text-amber-600"><?php echo e($stats['unpaid']); ?></p>
        </div>
        <div class="rounded-2xl bg-white border border-gray-100 p-4 shadow-sm">
            <p class="text-xs font-semibold uppercase tracking-wide text-gray-400">Lunas</p>
            <p class="mt-2 text-2xl font-bold text-emerald-600"><?php echo e($stats['paid']); ?></p>
        </div>
    </div>

    <form method="GET" class="grid grid-cols-1 md:grid-cols-4 gap-3 bg-white rounded-2xl border border-gray-100 shadow-sm p-4">
        <input type="hidden" name="density" value="<?php echo e($density ?? 'comfortable'); ?>">
        <input type="text" name="search" value="<?php echo e($search); ?>" placeholder="Cari nomor invoice atau pelanggan"
               class="rounded-xl border border-gray-200 px-4 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent">
        <select name="status" class="rounded-xl border border-gray-200 px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent">
            <option value="">Semua status invoice</option>
            <?php $__currentLoopData = \App\Models\Invoice::STATUSES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($item); ?>" <?php if($status === $item): echo 'selected'; endif; ?>><?php echo e(ucfirst($item)); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <select name="payment_status" class="rounded-xl border border-gray-200 px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent">
            <option value="">Semua status bayar</option>
            <?php $__currentLoopData = \App\Models\Invoice::PAYMENT_STATUSES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($item); ?>" <?php if($paymentStatus === $item): echo 'selected'; endif; ?>><?php echo e(ucfirst($item)); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <select name="source_type" class="rounded-xl border border-gray-200 px-3 py-2.5 text-sm bg-white focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent">
            <option value="">Semua sumber</option>
            <?php $__currentLoopData = \App\Models\Invoice::SOURCES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($item); ?>" <?php if($sourceType === $item): echo 'selected'; endif; ?>><?php echo e(ucfirst($item)); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <div class="md:col-span-4 flex gap-2">
            <button type="submit" class="rounded-xl bg-brand-600 hover:bg-brand-700 text-white text-sm font-semibold px-4 py-2.5 transition">Filter</button>
            <a href="<?php echo e(route('admin.invoices.index', ['density' => $density ?? 'comfortable'])); ?>" class="rounded-xl border border-gray-300 text-gray-700 text-sm font-medium px-4 py-2.5 hover:bg-gray-50 transition">Reset</a>
        </div>
    </form>

    <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
        <div class="overflow-x-auto">
            <table class="w-full text-sm">
                <thead>
                    <tr class="bg-gray-50 border-b border-gray-100 text-left">
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600">Invoice</th>
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600">Pelanggan</th>
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600">Sumber</th>
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600">Status</th>
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600">Total</th>
                        <th class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> font-semibold text-gray-600 text-right">Aksi</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-50">
                    <?php $__empty_1 = true; $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="hover:bg-gray-50/70 transition">
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?>">
                            <p class="font-semibold text-gray-900"><?php echo e($invoice->invoice_number ?: 'Draft #' . $invoice->id); ?></p>
                            <p class="text-xs text-gray-400"><?php echo e(optional($invoice->invoice_date)->format('d M Y') ?: '-'); ?></p>
                        </td>
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?>">
                            <p class="font-medium text-gray-800"><?php echo e($invoice->customer->name); ?></p>
                            <p class="text-xs text-gray-400"><?php echo e($invoice->customer->code ?: 'Tanpa kode'); ?></p>
                        </td>
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?>">
                            <span class="inline-flex items-center rounded-full bg-slate-100 text-slate-700 px-2.5 py-1 text-xs font-semibold"><?php echo e(ucfirst($invoice->source_type)); ?></span>
                        </td>
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> space-y-1">
                            <span class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold <?php echo e($invoice->status === 'issued' ? 'bg-brand-100 text-brand-700' : ($invoice->status === 'review' ? 'bg-indigo-100 text-indigo-700' : ($invoice->status === 'cancelled' ? 'bg-rose-100 text-rose-700' : 'bg-amber-100 text-amber-700'))); ?>"><?php echo e(ucfirst($invoice->status)); ?></span>
                            <div>
                                <span class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold <?php echo e($invoice->payment_status === 'paid' ? 'bg-emerald-100 text-emerald-700' : ($invoice->payment_status === 'partial' ? 'bg-sky-100 text-sky-700' : 'bg-amber-100 text-amber-700')); ?>"><?php echo e(ucfirst($invoice->payment_status)); ?></span>
                            </div>
                        </td>
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?>">
                            <p class="font-semibold text-gray-900">Rp <?php echo e(number_format((float) $invoice->grand_total, 0, ',', '.')); ?></p>
                            <p class="text-xs text-gray-400">Sisa Rp <?php echo e(number_format((float) $invoice->balance_due, 0, ',', '.')); ?></p>
                        </td>
                        <td class="<?php echo e($isCompact ? 'px-3 py-2.5' : 'px-5 py-3'); ?> text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="<?php echo e(route('admin.invoices.show', $invoice)); ?>" class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5 rounded-lg border border-gray-200 text-gray-700 hover:bg-gray-50 transition">Detail</a>
                                <?php if($invoice->status === 'draft'): ?>
                                <a href="<?php echo e(route('admin.invoices.edit', $invoice)); ?>" class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5 rounded-lg border border-brand-200 text-brand-700 hover:bg-brand-50 transition">Edit</a>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="6" class="<?php echo e($isCompact ? 'px-3 py-8' : 'px-5 py-10'); ?> text-center text-sm text-gray-400">Belum ada invoice.</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <?php echo e($invoices->links()); ?>

</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\Service-sistem\resources\views/admin/invoices/index.blade.php ENDPATH**/ ?>