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

<?php
    $canRecordPayment = auth()->user()?->can('create', \App\Models\Payment::class)
        && $invoice->outstanding_balance > 0
        && ! in_array($invoice->status, [\App\Enums\InvoiceStatus::Draft, \App\Enums\InvoiceStatus::Void], true);
    $payments = $invoice->payments->sortByDesc(fn ($payment) => $payment->payment_date?->format('Y-m-d').'-'.$payment->id);
?>

<?php $__env->startSection('content'); ?>
    <?php if (isset($component)) { $__componentOriginal360d002b1b676b6f84d43220f22129e2 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal360d002b1b676b6f84d43220f22129e2 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.breadcrumbs','data' => ['items' => [
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Invoices', 'url' => route('invoices.index')],
        ['label' => $invoice->invoice_number],
    ]]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('breadcrumbs'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['items' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute([
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Invoices', 'url' => route('invoices.index')],
        ['label' => $invoice->invoice_number],
    ])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal360d002b1b676b6f84d43220f22129e2)): ?>
<?php $attributes = $__attributesOriginal360d002b1b676b6f84d43220f22129e2; ?>
<?php unset($__attributesOriginal360d002b1b676b6f84d43220f22129e2); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal360d002b1b676b6f84d43220f22129e2)): ?>
<?php $component = $__componentOriginal360d002b1b676b6f84d43220f22129e2; ?>
<?php unset($__componentOriginal360d002b1b676b6f84d43220f22129e2); ?>
<?php endif; ?>

    <?php if (isset($component)) { $__componentOriginalf8d4ea307ab1e58d4e472a43c8548d8e = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalf8d4ea307ab1e58d4e472a43c8548d8e = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.page-header','data' => ['title' => $invoice->invoice_number,'subtitle' => 'Invoice']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('page-header'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->invoice_number),'subtitle' => 'Invoice']); ?>
        <div class="d-flex flex-wrap gap-2">
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update', $invoice)): ?>
                <a href="<?php echo e(route('invoices.edit', $invoice)); ?>" class="btn btn-outline-primary btn-sm">
                    <i class="bi bi-pencil-square me-1"></i> Edit Invoice
                </a>
            <?php endif; ?>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('create', \App\Models\Quotation::class)): ?>
                <form method="POST" action="<?php echo e(route('invoices.quotation.create', $invoice)); ?>" class="d-inline">
                    <?php echo csrf_field(); ?>
                    <button type="submit" class="btn btn-outline-secondary btn-sm">Convert to Quotation</button>
                </form>
            <?php endif; ?>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('issue', $invoice)): ?>
                <?php if($invoice->status === \App\Enums\InvoiceStatus::Draft): ?>
                    <form method="POST" action="<?php echo e(route('invoices.issue', $invoice)); ?>" class="d-inline">
                        <?php echo csrf_field(); ?>
                        <button type="submit" class="btn btn-primary btn-sm">Issue</button>
                    </form>
                <?php endif; ?>
            <?php endif; ?>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('void', $invoice)): ?>
                <?php if($invoice->isIssued() && $invoice->status !== \App\Enums\InvoiceStatus::Void): ?>
                    <button type="button" class="btn btn-outline-danger btn-sm" data-bs-toggle="modal" data-bs-target="#voidInvoiceModal">Void</button>
                <?php endif; ?>
            <?php endif; ?>
            <a href="<?php echo e(route('invoices.pdf', $invoice)); ?>" class="btn btn-primary btn-sm">
                <i class="bi bi-download me-1"></i> Download PDF
            </a>
            <a href="<?php echo e(route('invoices.print', $invoice)); ?>" class="btn btn-outline-secondary btn-sm" target="_blank">Print</a>
        </div>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalf8d4ea307ab1e58d4e472a43c8548d8e)): ?>
<?php $attributes = $__attributesOriginalf8d4ea307ab1e58d4e472a43c8548d8e; ?>
<?php unset($__attributesOriginalf8d4ea307ab1e58d4e472a43c8548d8e); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalf8d4ea307ab1e58d4e472a43c8548d8e)): ?>
<?php $component = $__componentOriginalf8d4ea307ab1e58d4e472a43c8548d8e; ?>
<?php unset($__componentOriginalf8d4ea307ab1e58d4e472a43c8548d8e); ?>
<?php endif; ?>

    <div class="row g-3">
        <div class="col-lg-8">
            <?php echo $__env->make('partials.document-show-sections', ['document' => $invoice], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

            <div class="mt-3">
                <?php if (isset($component)) { $__componentOriginal27272fa58b14bd2a656b44955fdc374a = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal27272fa58b14bd2a656b44955fdc374a = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.attachments-panel','data' => ['attachable' => $invoice]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('attachments-panel'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['attachable' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal27272fa58b14bd2a656b44955fdc374a)): ?>
<?php $attributes = $__attributesOriginal27272fa58b14bd2a656b44955fdc374a; ?>
<?php unset($__attributesOriginal27272fa58b14bd2a656b44955fdc374a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal27272fa58b14bd2a656b44955fdc374a)): ?>
<?php $component = $__componentOriginal27272fa58b14bd2a656b44955fdc374a; ?>
<?php unset($__componentOriginal27272fa58b14bd2a656b44955fdc374a); ?>
<?php endif; ?>
            </div>
        </div>

        <div class="col-lg-4">
            
            <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => ['title' => 'Invoice Status','subtitle' => 'Update the current status']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Invoice Status','subtitle' => 'Update the current status']); ?>
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('updateStatus', $invoice)): ?>
                    <?php if($statusOptions === []): ?>
                        <div class="d-flex align-items-center justify-content-between">
                            <span class="text-muted small">Current status</span>
                            <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['status' => $invoice->status->value,'label' => $invoice->status->label()]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('badge'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['status' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->status->value),'label' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->status->label())]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $attributes = $__attributesOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $component = $__componentOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__componentOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
                        </div>
                        <?php if($invoice->isDraft()): ?>
                            <p class="small text-muted mb-0 mt-2">Issue the invoice before changing status here.</p>
                        <?php endif; ?>
                    <?php else: ?>
                        <form method="POST" action="<?php echo e(route('invoices.status', $invoice)); ?>" x-data="{ status: '<?php echo e(old('status', $invoice->status->value)); ?>' }">
                            <?php echo csrf_field(); ?>
                            <div class="mb-3">
                                <label class="form-label" for="invoice_status">Status</label>
                                <select name="status" id="invoice_status" class="form-select" required x-model="status">
                                    <?php $__currentLoopData = $statusOptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($value); ?>" <?php if(old('status', $invoice->status->value) === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <?php
                                    $postedPaymentCount = $invoice->payments->filter(
                                        fn ($payment) => $payment->status === \App\Enums\PaymentStatus::Posted
                                    )->count();
                                ?>
                                <?php if($postedPaymentCount > 0): ?>
                                    <div class="form-text">
                                        <?php if((float) $invoice->outstanding_balance > 0.009): ?>
                                            Payments recorded with a balance due — status is Partially Paid; only Refunded can be selected.
                                        <?php else: ?>
                                            Fully paid — status is Paid; only Refunded can be selected.
                                        <?php endif; ?>
                                    </div>
                                <?php else: ?>
                                    <div class="form-text">No payments yet — choose Issued, Overdue, or Void.</div>
                                <?php endif; ?>
                            </div>
                            <div class="mb-3" x-show="status === 'void'" x-cloak>
                                <label class="form-label" for="status_reason">Void reason</label>
                                <textarea name="reason" id="status_reason" class="form-control" rows="2" x-bind:required="status === 'void'"><?php echo e(old('reason')); ?></textarea>
                            </div>
                            <button type="submit" class="btn btn-primary btn-sm w-100">Update Status</button>
                        </form>
                    <?php endif; ?>
                <?php else: ?>
                    <div class="d-flex align-items-center justify-content-between">
                        <span class="text-muted small">Current status</span>
                        <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['status' => $invoice->status->value,'label' => $invoice->status->label()]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('badge'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['status' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->status->value),'label' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->status->label())]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $attributes = $__attributesOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $component = $__componentOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__componentOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
                    </div>
                <?php endif; ?>
             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $attributes = $__attributesOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__attributesOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $component = $__componentOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__componentOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>

            
            <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => ['title' => 'Payments','subtitle' => 'Paid '.number_format((float) $invoice->amount_paid, 2).' · Due '.number_format((float) $invoice->outstanding_balance, 2)]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Payments','subtitle' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute('Paid '.number_format((float) $invoice->amount_paid, 2).' · Due '.number_format((float) $invoice->outstanding_balance, 2))]); ?>
                <div class="invoice-payment-summary">
                    <div class="stat">
                        <div class="stat-label">Paid</div>
                        <div class="stat-value"><?php if (isset($component)) { $__componentOriginal3c51c5b308d311657bfae6be692a1470 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal3c51c5b308d311657bfae6be692a1470 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.money','data' => ['amount' => $invoice->amount_paid,'currency' => $invoice->currency]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('money'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['amount' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->amount_paid),'currency' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->currency)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $attributes = $__attributesOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__attributesOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $component = $__componentOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__componentOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?></div>
                    </div>
                    <div class="stat">
                        <div class="stat-label">Outstanding</div>
                        <div class="stat-value"><?php if (isset($component)) { $__componentOriginal3c51c5b308d311657bfae6be692a1470 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal3c51c5b308d311657bfae6be692a1470 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.money','data' => ['amount' => $invoice->outstanding_balance,'currency' => $invoice->currency]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('money'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['amount' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->outstanding_balance),'currency' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->currency)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $attributes = $__attributesOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__attributesOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $component = $__componentOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__componentOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?></div>
                    </div>
                </div>

                <?php if($canRecordPayment): ?>
                    <div class="border rounded-3 p-3 mb-3 bg-light-subtle">
                        <div class="fw-semibold mb-2">Record payment</div>
                        <form method="POST" action="<?php echo e(route('payments.store')); ?>">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="invoice_id" value="<?php echo e($invoice->id); ?>">
                            <input type="hidden" name="return_to_invoice" value="1">
                            <div class="mb-2">
                                <label class="form-label small text-muted mb-1" for="payment_date">Date</label>
                                <input type="date" name="payment_date" id="payment_date" class="form-control form-control-sm"
                                       value="<?php echo e(old('payment_date', now()->toDateString())); ?>" required>
                            </div>
                            <div class="mb-2">
                                <label class="form-label small text-muted mb-1" for="amount">Amount</label>
                                <input type="number" step="0.01" min="0.01" name="amount" id="amount" class="form-control form-control-sm"
                                       value="<?php echo e(old('amount', $invoice->outstanding_balance)); ?>" required>
                            </div>
                            <div class="mb-2">
                                <label class="form-label small text-muted mb-1" for="payment_method">Method</label>
                                <select name="payment_method" id="payment_method" class="form-select form-select-sm" required>
                                    <?php $__currentLoopData = $paymentMethods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($value); ?>" <?php if(old('payment_method', 'bank_transfer') === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                            <div class="mb-2">
                                <label class="form-label small text-muted mb-1" for="transaction_reference">Reference</label>
                                <input type="text" name="transaction_reference" id="transaction_reference" class="form-control form-control-sm"
                                       value="<?php echo e(old('transaction_reference')); ?>" maxlength="255" placeholder="Optional">
                            </div>
                            <div class="mb-3">
                                <label class="form-label small text-muted mb-1" for="notes">Notes</label>
                                <textarea name="notes" id="notes" class="form-control form-control-sm" rows="2" maxlength="2000"><?php echo e(old('notes')); ?></textarea>
                            </div>
                            <button type="submit" class="btn btn-success btn-sm w-100">
                                <i class="bi bi-cash-coin me-1"></i> Save Payment
                            </button>
                        </form>
                    </div>
                <?php elseif($invoice->status === \App\Enums\InvoiceStatus::Draft): ?>
                    <p class="small text-muted mb-3">Issue the invoice before recording payments.</p>
                <?php elseif($invoice->status === \App\Enums\InvoiceStatus::Void): ?>
                    <p class="small text-muted mb-3">Payments cannot be recorded on a void invoice.</p>
                <?php elseif($invoice->outstanding_balance <= 0): ?>
                    <p class="small text-success mb-3">This invoice is fully paid.</p>
                <?php endif; ?>

                <div class="fw-semibold mb-2">Payment history</div>
                <?php if($payments->isEmpty()): ?>
                    <p class="text-muted small mb-0">No payments recorded yet.</p>
                <?php else: ?>
                    <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="payment-history-item">
                            <div class="d-flex justify-content-between align-items-start gap-2 mb-1">
                                <div>
                                    <a href="<?php echo e(route('payments.show', $payment)); ?>" class="fw-semibold text-decoration-none"><?php echo e($payment->payment_number); ?></a>
                                    <div class="small text-muted">
                                        <?php if (isset($component)) { $__componentOriginal8319e42702f02703b9e1bc5b0dc5413c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal8319e42702f02703b9e1bc5b0dc5413c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.datetime','data' => ['value' => $payment->payment_date]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('datetime'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['value' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($payment->payment_date)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal8319e42702f02703b9e1bc5b0dc5413c)): ?>
<?php $attributes = $__attributesOriginal8319e42702f02703b9e1bc5b0dc5413c; ?>
<?php unset($__attributesOriginal8319e42702f02703b9e1bc5b0dc5413c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal8319e42702f02703b9e1bc5b0dc5413c)): ?>
<?php $component = $__componentOriginal8319e42702f02703b9e1bc5b0dc5413c; ?>
<?php unset($__componentOriginal8319e42702f02703b9e1bc5b0dc5413c); ?>
<?php endif; ?>
                                        · <?php echo e($payment->payment_method->label()); ?>

                                    </div>
                                </div>
                                <div class="text-end">
                                    <div class="fw-semibold"><?php if (isset($component)) { $__componentOriginal3c51c5b308d311657bfae6be692a1470 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal3c51c5b308d311657bfae6be692a1470 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.money','data' => ['amount' => $payment->amount,'currency' => $invoice->currency]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('money'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['amount' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($payment->amount),'currency' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($invoice->currency)]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $attributes = $__attributesOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__attributesOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal3c51c5b308d311657bfae6be692a1470)): ?>
<?php $component = $__componentOriginal3c51c5b308d311657bfae6be692a1470; ?>
<?php unset($__componentOriginal3c51c5b308d311657bfae6be692a1470); ?>
<?php endif; ?></div>
                                    <?php if (isset($component)) { $__componentOriginal2ddbc40e602c342e508ac696e52f8719 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2ddbc40e602c342e508ac696e52f8719 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.badge','data' => ['status' => $payment->status->value,'label' => $payment->status->label()]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('badge'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['status' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($payment->status->value),'label' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($payment->status->label())]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $attributes = $__attributesOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__attributesOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2ddbc40e602c342e508ac696e52f8719)): ?>
<?php $component = $__componentOriginal2ddbc40e602c342e508ac696e52f8719; ?>
<?php unset($__componentOriginal2ddbc40e602c342e508ac696e52f8719); ?>
<?php endif; ?>
                                </div>
                            </div>
                            <?php if($payment->transaction_reference): ?>
                                <div class="small text-muted mb-1">Ref: <?php echo e($payment->transaction_reference); ?></div>
                            <?php endif; ?>
                            <?php if($payment->notes): ?>
                                <div class="small text-muted mb-2"><?php echo e($payment->notes); ?></div>
                            <?php endif; ?>
                            <div class="d-flex flex-wrap gap-1">
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update', $payment)): ?>
                                    <button type="button" class="btn btn-outline-primary btn-sm"
                                            data-bs-toggle="modal" data-bs-target="#editPaymentModal<?php echo e($payment->id); ?>">
                                        <i class="bi bi-pencil me-1"></i> Edit
                                    </button>
                                <?php endif; ?>
                                <a href="<?php echo e(route('payments.show', $payment)); ?>" class="btn btn-outline-secondary btn-sm">View</a>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <?php endif; ?>
             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $attributes = $__attributesOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__attributesOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $component = $__componentOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__componentOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
        </div>
    </div>

    <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update', $payment)): ?>
            <div class="modal fade" id="editPaymentModal<?php echo e($payment->id); ?>" tabindex="-1" aria-labelledby="editPaymentModalLabel<?php echo e($payment->id); ?>" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <form method="POST" action="<?php echo e(route('payments.update', $payment)); ?>">
                            <?php echo csrf_field(); ?>
                            <?php echo method_field('PUT'); ?>
                            <input type="hidden" name="return_to_invoice" value="1">
                            <div class="modal-header">
                                <h5 class="modal-title" id="editPaymentModalLabel<?php echo e($payment->id); ?>">Edit <?php echo e($payment->payment_number); ?></h5>
                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                            </div>
                            <div class="modal-body">
                                <div class="mb-3">
                                    <label class="form-label" for="edit_payment_date_<?php echo e($payment->id); ?>">Payment date</label>
                                    <input type="date" name="payment_date" id="edit_payment_date_<?php echo e($payment->id); ?>" class="form-control"
                                           value="<?php echo e($payment->payment_date?->format('Y-m-d')); ?>" required>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="edit_amount_<?php echo e($payment->id); ?>">Amount</label>
                                    <input type="number" step="0.01" min="0.01" name="amount" id="edit_amount_<?php echo e($payment->id); ?>" class="form-control"
                                           value="<?php echo e($payment->amount); ?>" required>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="edit_method_<?php echo e($payment->id); ?>">Method</label>
                                    <select name="payment_method" id="edit_method_<?php echo e($payment->id); ?>" class="form-select" required>
                                        <?php $__currentLoopData = $paymentMethods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($value); ?>" <?php if($payment->payment_method->value === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label" for="edit_ref_<?php echo e($payment->id); ?>">Reference</label>
                                    <input type="text" name="transaction_reference" id="edit_ref_<?php echo e($payment->id); ?>" class="form-control"
                                           value="<?php echo e($payment->transaction_reference); ?>" maxlength="255">
                                </div>
                                <div class="mb-0">
                                    <label class="form-label" for="edit_notes_<?php echo e($payment->id); ?>">Notes</label>
                                    <textarea name="notes" id="edit_notes_<?php echo e($payment->id); ?>" class="form-control" rows="2" maxlength="2000"><?php echo e($payment->notes); ?></textarea>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
                                <button type="submit" class="btn btn-primary">Save changes</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('void', $invoice)): ?>
        <div class="modal fade" id="voidInvoiceModal" tabindex="-1" aria-labelledby="voidInvoiceModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form method="POST" action="<?php echo e(route('invoices.void', $invoice)); ?>">
                        <?php echo csrf_field(); ?>
                        <div class="modal-header">
                            <h5 class="modal-title" id="voidInvoiceModalLabel">Void Invoice</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <?php if (isset($component)) { $__componentOriginalcd97a59301ba78d56b3ed60dd41409ab = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalcd97a59301ba78d56b3ed60dd41409ab = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.form.textarea','data' => ['label' => 'Reason','name' => 'reason','rows' => '3','required' => true]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('form.textarea'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['label' => 'Reason','name' => 'reason','rows' => '3','required' => true]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalcd97a59301ba78d56b3ed60dd41409ab)): ?>
<?php $attributes = $__attributesOriginalcd97a59301ba78d56b3ed60dd41409ab; ?>
<?php unset($__attributesOriginalcd97a59301ba78d56b3ed60dd41409ab); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalcd97a59301ba78d56b3ed60dd41409ab)): ?>
<?php $component = $__componentOriginalcd97a59301ba78d56b3ed60dd41409ab; ?>
<?php unset($__componentOriginalcd97a59301ba78d56b3ed60dd41409ab); ?>
<?php endif; ?>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
                            <button type="submit" class="btn btn-danger">Void Invoice</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\hotelplus\consol\resources\views/invoices/show.blade.php ENDPATH**/ ?>