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

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

<div class="d-flex align-items-center justify-content-between mb-4 flex-wrap gap-2">
    <div class="d-flex align-items-center gap-3">
        <a href="<?php echo e(route('invoices.index')); ?>" class="btn btn-sm btn-light">
            <i class="bi bi-arrow-left"></i>
        </a>
        <div>
            <h5 class="fw-700 mb-0" style="color:#1e293b;"><?php echo e($invoice->invoice_number); ?></h5>
            <span class="status-badge badge-<?php echo e($invoice->status); ?> mt-1">
                <?php echo e($invoice->status_badge['label']); ?>

            </span>
        </div>
    </div>

    
    <div class="d-flex flex-wrap gap-2">
        <?php if($invoice->isDraft()): ?>
            <a href="<?php echo e(route('invoices.edit', $invoice)); ?>" class="btn btn-outline-secondary btn-sm fw-500">
                <i class="bi bi-pencil me-1"></i>Edit
            </a>
        <?php endif; ?>

        <?php if($invoice->canBeSent()): ?>
            <form method="POST" action="<?php echo e(route('invoices.send', $invoice)); ?>">
                <?php echo csrf_field(); ?>
                <button type="submit" class="btn btn-primary btn-sm fw-500"
                        onclick="return confirm('Send invoice to <?php echo e($invoice->client->email); ?>?')">
                    <i class="bi bi-send me-1"></i>
                    <?php echo e($invoice->isSent() || $invoice->isViewed() ? 'Resend' : 'Send'); ?>

                </button>
            </form>
        <?php endif; ?>

        <a href="<?php echo e(route('invoices.download', $invoice)); ?>" class="btn btn-outline-secondary btn-sm fw-500">
            <i class="bi bi-download me-1"></i>PDF
        </a>

        <?php if($invoice->canBeMarkedPaid()): ?>
            <form method="POST" action="<?php echo e(route('invoices.mark-paid', $invoice)); ?>">
                <?php echo csrf_field(); ?>
                <button type="submit" class="btn btn-success btn-sm fw-500"
                        onclick="return confirm('Mark <?php echo e($invoice->invoice_number); ?> as paid?')">
                    <i class="bi bi-check-circle me-1"></i>Mark Paid
                </button>
            </form>
        <?php endif; ?>

        <div class="dropdown">
            <button class="btn btn-light btn-sm" data-bs-toggle="dropdown">
                <i class="bi bi-three-dots-vertical"></i>
            </button>
            <ul class="dropdown-menu dropdown-menu-end" style="font-size:0.875rem;">
                <li>
                    <form method="POST" action="<?php echo e(route('invoices.duplicate', $invoice)); ?>">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="dropdown-item">
                            <i class="bi bi-copy me-2"></i>Duplicate
                        </button>
                    </form>
                </li>
                <li>
                    <a class="dropdown-item" href="<?php echo e($invoice->public_url); ?>" target="_blank">
                        <i class="bi bi-link-45deg me-2"></i>View Public Link
                    </a>
                </li>
                <li>
                    <button type="button" class="dropdown-item" onclick="copyPublicLink()">
                        <i class="bi bi-clipboard me-2"></i>Copy Payment Link
                    </button>
                </li>
                <?php if(!$invoice->isPaid() && !$invoice->isCancelled()): ?>
                    <li><hr class="dropdown-divider"></li>
                    <li>
                        <form method="POST" action="<?php echo e(route('invoices.cancel', $invoice)); ?>">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="dropdown-item text-warning"
                                    onclick="return confirm('Cancel this invoice? This cannot be undone.')">
                                <i class="bi bi-x-circle me-2"></i>Cancel Invoice
                            </button>
                        </form>
                    </li>
                <?php endif; ?>
                <?php if($invoice->isDraft()): ?>
                    <li>
                        <form method="POST" action="<?php echo e(route('invoices.destroy', $invoice)); ?>">
                            <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                            <button type="submit" class="dropdown-item text-danger"
                                    onclick="return confirm('Delete this draft invoice? This cannot be undone.')">
                                <i class="bi bi-trash3 me-2"></i>Delete Draft
                            </button>
                        </form>
                    </li>
                <?php endif; ?>
            </ul>
        </div>
    </div>
</div>

<div class="row g-3">
    
    <div class="col-lg-8">
        <div class="card table-card p-4">
            
            <div class="d-flex justify-content-between align-items-start mb-4 flex-wrap gap-3">
                <div>
                    <?php if(auth()->user()->logo_path): ?>
                        <img src="<?php echo e(auth()->user()->logo_url); ?>" alt="logo" style="max-height:60px;max-width:160px;object-fit:contain;margin-bottom:0.75rem;display:block;">
                    <?php endif; ?>
                    <div class="fw-700 fs-5" style="color:#1e293b;"><?php echo e(auth()->user()->business_name); ?></div>
                    <?php if(auth()->user()->address): ?>
                        <div class="text-muted small" style="max-width:200px;"><?php echo e(auth()->user()->address); ?></div>
                    <?php endif; ?>
                    <?php if(auth()->user()->phone): ?>
                        <div class="text-muted small"><?php echo e(auth()->user()->phone); ?></div>
                    <?php endif; ?>
                </div>
                <div class="text-end">
                    <div class="text-muted" style="font-size:0.72rem;text-transform:uppercase;letter-spacing:0.08em;">Invoice</div>
                    <div class="fw-700 fs-4" style="font-family:monospace;color:#1e293b;"><?php echo e($invoice->invoice_number); ?></div>
                    <span class="status-badge badge-<?php echo e($invoice->status); ?>"><?php echo e($invoice->status_badge['label']); ?></span>
                </div>
            </div>

            <hr style="border-color:#e2e8f0;">

            
            <div class="row mb-4">
                <div class="col-sm-6">
                    <div class="text-muted mb-1" style="font-size:0.72rem;text-transform:uppercase;letter-spacing:0.08em;">Bill To</div>
                    <div class="fw-600" style="color:#1e293b;"><?php echo e($invoice->client->display_name); ?></div>
                    <?php if($invoice->client->email): ?>
                        <div class="text-muted small"><?php echo e($invoice->client->email); ?></div>
                    <?php endif; ?>
                    <?php if($invoice->client->phone): ?>
                        <div class="text-muted small"><?php echo e($invoice->client->phone); ?></div>
                    <?php endif; ?>
                    <?php if($invoice->client->address): ?>
                        <div class="text-muted small"><?php echo e($invoice->client->address); ?></div>
                    <?php endif; ?>
                </div>
                <div class="col-sm-6 mt-3 mt-sm-0">
                    <div class="row g-1" style="font-size:0.875rem;">
                        <div class="col-5 text-muted">Issue Date:</div>
                        <div class="col-7 fw-500"><?php echo e($invoice->issue_date->format('d/m/Y')); ?></div>
                        <div class="col-5 text-muted">Due Date:</div>
                        <div class="col-7 fw-500 <?php echo e($invoice->isOverdue() ? 'text-danger' : ''); ?>">
                            <?php echo e($invoice->due_date->format('d/m/Y')); ?>

                        </div>
                        <?php if($invoice->paid_at): ?>
                            <div class="col-5 text-muted">Paid On:</div>
                            <div class="col-7 fw-500 text-success"><?php echo e($invoice->paid_at->format('d/m/Y')); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            
            <div class="table-responsive">
                <table class="table mb-0" style="font-size:0.875rem;">
                    <thead>
                        <tr style="background:#f8fafc;">
                            <th class="ps-0">Description</th>
                            <th class="text-center" style="width:80px;">Qty</th>
                            <th class="text-end" style="width:130px;">Unit Price</th>
                            <th class="text-end pe-0" style="width:130px;">Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $invoice->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td class="ps-0"><?php echo e($item->description); ?></td>
                            <td class="text-center"><?php echo e($item->quantity); ?></td>
                            <td class="text-end">₦<?php echo e(number_format($item->unit_price, 2)); ?></td>
                            <td class="text-end pe-0 fw-500">₦<?php echo e(number_format($item->total, 2)); ?></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="3" class="text-end text-muted ps-0">Subtotal</td>
                            <td class="text-end pe-0">₦<?php echo e(number_format($invoice->subtotal, 2)); ?></td>
                        </tr>
                        <tr>
                            <td colspan="3" class="text-end text-muted ps-0">VAT (<?php echo e($invoice->vat_rate); ?>%)</td>
                            <td class="text-end pe-0">₦<?php echo e(number_format($invoice->vat_amount, 2)); ?></td>
                        </tr>
                        <?php if($invoice->discount > 0): ?>
                        <tr>
                            <td colspan="3" class="text-end text-muted ps-0">Discount</td>
                            <td class="text-end pe-0 text-danger">-₦<?php echo e(number_format($invoice->discount, 2)); ?></td>
                        </tr>
                        <?php endif; ?>
                        <tr style="border-top:2px solid #e2e8f0;">
                            <td colspan="3" class="text-end fw-700 fs-6 ps-0">Total</td>
                            <td class="text-end pe-0 fw-700 fs-6" style="color:#00a651;">
                                ₦<?php echo e(number_format($invoice->total, 2)); ?>

                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>

            <?php if($invoice->notes): ?>
                <div class="mt-4 p-3 rounded" style="background:#f8fafc;font-size:0.875rem;">
                    <div class="text-muted mb-1" style="font-size:0.72rem;text-transform:uppercase;letter-spacing:0.08em;">Notes</div>
                    <?php echo e($invoice->notes); ?>

                </div>
            <?php endif; ?>

            
            <?php if(auth()->user()->bank_name): ?>
            <div class="mt-4 p-3 rounded" style="background:#f0fdf4;border:1px solid #bbf7d0;font-size:0.875rem;">
                <div class="fw-600 mb-1" style="color:#15803d;font-size:0.8rem;">Payment Details</div>
                <div style="color:#166534;">
                    <strong>Bank:</strong> <?php echo e(auth()->user()->bank_name); ?> &nbsp;|&nbsp;
                    <strong>Account:</strong> <?php echo e(auth()->user()->account_number); ?> &nbsp;|&nbsp;
                    <strong>Name:</strong> <?php echo e(auth()->user()->account_name); ?>

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

    
    <div class="col-lg-4">
        
        <div class="card table-card p-3 mb-3">
            <div class="form-section-title mb-2" style="font-size:0.72rem;font-weight:700;text-transform:uppercase;letter-spacing:0.07em;color:#94a3b8;">
                <i class="bi bi-link-45deg me-1"></i>Payment Link
            </div>
            <div class="input-group input-group-sm">
                <input type="text" class="form-control" id="publicLinkInput"
                       value="<?php echo e($invoice->public_url); ?>" readonly style="font-size:0.75rem;">
                <button class="btn btn-outline-secondary" onclick="copyPublicLink()" title="Copy link">
                    <i class="bi bi-clipboard"></i>
                </button>
            </div>
            <a href="<?php echo e($invoice->public_url); ?>" target="_blank" class="btn btn-sm btn-outline-primary mt-2 w-100">
                <i class="bi bi-eye me-1"></i>Preview Client View
            </a>
        </div>

        
        <div class="card table-card p-3 mb-3">
            <div class="form-section-title mb-3" style="font-size:0.72rem;font-weight:700;text-transform:uppercase;letter-spacing:0.07em;color:#94a3b8;">
                <i class="bi bi-clock-history me-1"></i>Timeline
            </div>
            <div class="d-flex flex-column gap-2" style="font-size:0.825rem;">
                <div class="d-flex gap-2 align-items-start">
                    <div style="width:8px;height:8px;background:#00a651;border-radius:50%;margin-top:5px;flex-shrink:0;"></div>
                    <div>
                        <div class="fw-500">Created</div>
                        <div class="text-muted" style="font-size:0.75rem;"><?php echo e($invoice->created_at->format('d/m/Y H:i')); ?></div>
                    </div>
                </div>
                <?php if($invoice->sent_at): ?>
                <div class="d-flex gap-2 align-items-start">
                    <div style="width:8px;height:8px;background:#2563eb;border-radius:50%;margin-top:5px;flex-shrink:0;"></div>
                    <div>
                        <div class="fw-500">Sent to client</div>
                        <div class="text-muted" style="font-size:0.75rem;"><?php echo e($invoice->sent_at->format('d/m/Y H:i')); ?></div>
                    </div>
                </div>
                <?php endif; ?>
                <?php if($invoice->viewed_at): ?>
                <div class="d-flex gap-2 align-items-start">
                    <div style="width:8px;height:8px;background:#7c3aed;border-radius:50%;margin-top:5px;flex-shrink:0;"></div>
                    <div>
                        <div class="fw-500">Viewed by client</div>
                        <div class="text-muted" style="font-size:0.75rem;"><?php echo e($invoice->viewed_at->format('d/m/Y H:i')); ?></div>
                    </div>
                </div>
                <?php endif; ?>
                <?php if($invoice->paid_at): ?>
                <div class="d-flex gap-2 align-items-start">
                    <div style="width:8px;height:8px;background:#16a34a;border-radius:50%;margin-top:5px;flex-shrink:0;"></div>
                    <div>
                        <div class="fw-500 text-success">Payment received</div>
                        <div class="text-muted" style="font-size:0.75rem;"><?php echo e($invoice->paid_at->format('d/m/Y H:i')); ?></div>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>

        
        <?php if($invoice->payments->isNotEmpty()): ?>
        <div class="card table-card p-3">
            <div class="form-section-title mb-2" style="font-size:0.72rem;font-weight:700;text-transform:uppercase;letter-spacing:0.07em;color:#94a3b8;">
                <i class="bi bi-credit-card me-1"></i>Payments
            </div>
            <?php $__currentLoopData = $invoice->payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="d-flex justify-content-between align-items-center p-2 rounded mb-1" style="background:#f0fdf4;">
                <div>
                    <div class="fw-600 text-success small">₦<?php echo e(number_format($payment->amount, 2)); ?></div>
                    <div class="text-muted" style="font-size:0.72rem;"><?php echo e($payment->method_label); ?> · <?php echo e($payment->paid_at->format('d/m/Y')); ?></div>
                </div>
                <i class="bi bi-check-circle-fill text-success"></i>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
        <?php endif; ?>
    </div>
</div>

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

<?php $__env->startPush('scripts'); ?>
<script>
function copyPublicLink() {
    const input = document.getElementById('publicLinkInput');
    navigator.clipboard.writeText(input.value).then(() => {
        Toast.fire({ icon: 'success', title: 'Payment link copied!' });
    });
}
</script>
<?php $__env->stopPush(); ?>

<?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/show.blade.php ENDPATH**/ ?>