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

<?php $__env->startSection('content'); ?>

<div class="d-flex align-items-center justify-content-between mb-4">
    <div>
        <h5 class="fw-700 mb-0" style="color:#1e293b;">All Invoices</h5>
        <small class="text-muted"><?php echo e($invoices->total()); ?> invoice<?php echo e($invoices->total() !== 1 ? 's' : ''); ?> found</small>
    </div>
    <a href="<?php echo e(route('invoices.create')); ?>" class="btn" style="background:#00a651;color:white;font-weight:600;">
        <i class="bi bi-plus-lg me-2"></i>New Invoice
    </a>
</div>


<div class="card table-card mb-3">
    <div class="p-3 border-bottom">
        <div class="d-flex flex-wrap gap-2 align-items-center">
            
            <div class="d-flex flex-wrap gap-1 me-auto">
                <?php
                    $statuses = [
                        ''          => 'All',
                        'draft'     => 'Draft',
                        'sent'      => 'Sent',
                        'viewed'    => 'Viewed',
                        'paid'      => 'Paid',
                        'overdue'   => 'Overdue',
                        'cancelled' => 'Cancelled',
                    ];
                    $currentStatus = request('status', '');
                ?>
                <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <a href="<?php echo e(route('invoices.index', array_merge(request()->except('page'), ['status' => $value]))); ?>"
                       class="btn btn-sm <?php echo e($currentStatus === $value ? 'btn-dark' : 'btn-outline-secondary'); ?>"
                       style="font-size:0.78rem;">
                        <?php echo e($label); ?>

                        <?php if($value && isset($statusCounts[$value])): ?>
                            <span class="ms-1 opacity-75"><?php echo e($statusCounts[$value]); ?></span>
                        <?php endif; ?>
                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            
            <form method="GET" action="<?php echo e(route('invoices.index')); ?>" class="d-flex gap-2">
                <?php if(request('status')): ?>
                    <input type="hidden" name="status" value="<?php echo e(request('status')); ?>">
                <?php endif; ?>
                <div class="input-group input-group-sm" style="width:220px;">
                    <span class="input-group-text bg-light border-end-0">
                        <i class="bi bi-search text-muted" style="font-size:0.75rem;"></i>
                    </span>
                    <input type="text" name="search" class="form-control border-start-0"
                           placeholder="Search invoices..."
                           value="<?php echo e(request('search')); ?>">
                </div>
                <button type="submit" class="btn btn-sm btn-light">Go</button>
                <?php if(request('search')): ?>
                    <a href="<?php echo e(route('invoices.index', request()->except(['search','page']))); ?>" class="btn btn-sm btn-light">
                        <i class="bi bi-x"></i>
                    </a>
                <?php endif; ?>
            </form>
        </div>
    </div>

    
    <?php if($invoices->isEmpty()): ?>
        <div class="empty-state">
            <div class="empty-icon"><i class="bi bi-receipt"></i></div>
            <h5>No invoices found</h5>
            <p><?php echo e(request('search') ? 'Try a different search term.' : 'Create your first invoice to get started.'); ?></p>
            <?php if(!request('search')): ?>
                <a href="<?php echo e(route('invoices.create')); ?>" class="btn" style="background:#00a651;color:white;">
                    <i class="bi bi-plus-lg me-2"></i>Create Invoice
                </a>
            <?php endif; ?>
        </div>
    <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover mb-0">
                <thead>
                    <tr>
                        <th style="width:130px;">Invoice #</th>
                        <th>Client</th>
                        <th class="d-none d-md-table-cell">Issue Date</th>
                        <th class="d-none d-md-table-cell">Due Date</th>
                        <th>Amount</th>
                        <th>Status</th>
                        <th style="width:120px;"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td>
                            <a href="<?php echo e(route('invoices.show', $invoice)); ?>"
                               class="text-decoration-none fw-600"
                               style="font-family:monospace;color:#1e293b;">
                                <?php echo e($invoice->invoice_number); ?>

                            </a>
                        </td>
                        <td>
                            <div style="font-size:0.875rem;color:#374151;">
                                <?php echo e($invoice->client->display_name); ?>

                            </div>
                            <?php if($invoice->client->business_name && $invoice->client->name !== $invoice->client->business_name): ?>
                                <small class="text-muted"><?php echo e($invoice->client->name); ?></small>
                            <?php endif; ?>
                        </td>
                        <td class="d-none d-md-table-cell text-muted small">
                            <?php echo e($invoice->issue_date->format('d/m/Y')); ?>

                        </td>
                        <td class="d-none d-md-table-cell small">
                            <span class="<?php echo e($invoice->isOverdue() ? 'text-danger fw-600' : 'text-muted'); ?>">
                                <?php echo e($invoice->due_date->format('d/m/Y')); ?>

                            </span>
                            <?php if($invoice->isOverdue()): ?>
                                <div style="font-size:0.72rem;color:#dc2626;">
                                    <?php echo e($invoice->due_date->diffForHumans()); ?>

                                </div>
                            <?php endif; ?>
                        </td>
                        <td class="fw-600" style="color:#1e293b;">
                            ₦<?php echo e(number_format($invoice->total, 2)); ?>

                        </td>
                        <td>
                            <span class="status-badge badge-<?php echo e($invoice->status); ?>">
                                <?php echo e($invoice->status_badge['label']); ?>

                            </span>
                        </td>
                        <td>
                            <div class="d-flex gap-1">
                                <a href="<?php echo e(route('invoices.show', $invoice)); ?>"
                                   class="btn btn-sm btn-light" title="View">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <?php if($invoice->isDraft()): ?>
                                    <a href="<?php echo e(route('invoices.edit', $invoice)); ?>"
                                       class="btn btn-sm btn-light" title="Edit">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                <?php endif; ?>
                                <a href="<?php echo e(route('invoices.download', $invoice)); ?>"
                                   class="btn btn-sm btn-light" title="Download PDF">
                                    <i class="bi bi-download"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>

        
        <?php if($invoices->hasPages()): ?>
            <div class="p-3 border-top">
                <?php echo e($invoices->links()); ?>

            </div>
        <?php endif; ?>
    <?php endif; ?>
</div>

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

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Bunmi\Desktop\crud\resources\views/invoices/index.blade.php ENDPATH**/ ?>