<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <div class="portal-container">
        <?php if(session('status')): ?>
            <div class="alert alert-success"><?php echo e(session('status')); ?></div>
        <?php endif; ?>

        <?php if(session('error')): ?>
            <div class="alert alert-error"><?php echo e(session('error')); ?></div>
        <?php endif; ?>

        <?php
            $displayInvoiceNumber = function ($invoice) {
                if ($invoice->whmcs_invoice_id) {
                    return (string) $invoice->whmcs_invoice_id;
                }

                $digits = preg_replace('/\D+/', '', (string) $invoice->invoice_number);
                return $digits !== '' ? $digits : (string) $invoice->invoice_number;
            };

            $displayMoney = function ($invoice) {
                $amount = number_format((float) $invoice->total, 2);
                return strtoupper((string) $invoice->currency) === 'USD'
                    ? '$'.$amount.' USD'
                    : strtoupper((string) $invoice->currency).' '.$amount;
            };

            $invoiceStatusLabel = function ($status) {
                $key = strtolower(str_replace(' ', '_', trim((string) $status)));
                return [
                    'payment_pending_whmcs' => 'Payment Processing',
                    'payment_received' => 'Payment Received',
                    'whmcs_sync_failed' => 'Processing',
                    'sync_failed' => 'Processing',
                    'manual_review' => 'Under Review',
                ][$key] ?? ucwords(str_replace('_', ' ', $key ?: 'pending'));
            };

            $displayDate = function ($value, $fallback = null) {
                try {
                    if ($value) {
                        return \Illuminate\Support\Carbon::parse($value)->format('l, F jS, Y');
                    }
                } catch (\Throwable) {
                    // Fall back below.
                }

                return $fallback ? $fallback->format('l, F jS, Y') : '-';
            };
        ?>

        <div class="page-head compact-page-head">
            <div>
                <span class="eyebrow">Billing</span>
                <h1 class="page-title">My Invoices</h1>
                <p class="page-subtitle">View invoice history and pay any pending invoice securely.</p>
            </div>
            <form method="POST" action="<?php echo e(route('client.invoices.refresh')); ?>">
                <?php echo csrf_field(); ?>
                <button class="secondary-btn" type="submit">Refresh</button>
            </form>
        </div>

        <div class="card" style="overflow-x:auto;">
            <table class="client-clean-table">
                <thead>
                    <tr>
                        <th>Invoice #</th>
                        <th>Invoice Date</th>
                        <th>Due Date</th>
                        <th>Total</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $invoices; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invoice): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $status = strtolower(str_replace(' ', '_', (string) $invoice->status));
                            $statusLabel = $invoiceStatusLabel($status);
                            $canPay = $invoice->whmcs_invoice_id && ! in_array($status, ['paid', 'cancelled', 'refunded', 'payment_received', 'payment_pending_whmcs'], true);
                            $invoiceDate = data_get($invoice->whmcs_payload, 'date')
                                ?: data_get($invoice->whmcs_payload, 'datecreated')
                                ?: data_get($invoice->whmcs_payload, 'created_at');
                        ?>
                        <tr>
                            <td><strong><?php echo e($displayInvoiceNumber($invoice)); ?></strong></td>
                            <td><?php echo e($displayDate($invoiceDate, $invoice->created_at)); ?></td>
                            <td><?php echo e($displayDate($invoice->due_date)); ?></td>
                            <td><strong><?php echo e($displayMoney($invoice)); ?></strong></td>
                            <td><span class="status-pill <?php echo e($status); ?>"><?php echo e($statusLabel); ?></span></td>
                            <td>
                                <?php if($canPay): ?>
                                    <a class="primary-btn" href="<?php echo e(route('client.invoices.show', $invoice)); ?>" style="text-decoration:none; display:inline-flex;">Pay Now</a>
                                <?php else: ?>
                                    <span class="service-muted"><?php echo e($status === 'paid' ? 'Paid' : '-'); ?></span>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="6">No invoices yet.</td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
            <div style="margin-top:18px;"><?php echo e($invoices->links()); ?></div>
        </div>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH /home/ovbopdha/public_html/ztcart.eagale.xyz/resources/views/client/invoices.blade.php ENDPATH**/ ?>