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

<?php $__env->startSection('content'); ?>
<div class="space-y-6" x-data="{ components: [{ payment_method: 'cash', amount: '<?php echo e($invoice->balance_due); ?>', transaction_reference: '' }] }">
    <div class="flex flex-col lg:flex-row lg:items-center justify-between gap-4">
        <div>
            <a href="<?php echo e(route('app.billing.invoices.index')); ?>" class="text-xs font-bold text-sky-600">← Back to invoices</a>
            <h1 class="text-2xl font-extrabold text-slate-950 dark:text-white mt-1"><?php echo e($invoice->invoice_number); ?></h1>
            <p class="text-sm text-slate-500">Issued <?php echo e($invoice->invoice_date->format('d M Y')); ?> · <?php echo e($invoice->customer?->full_name_en ?? $invoice->company?->name_en ?? 'General account'); ?></p>
        </div>
        <span class="self-start rounded-full bg-slate-900 px-4 py-2 text-xs font-bold uppercase text-white"><?php echo e(str_replace('_', ' ', $invoice->status)); ?></span>
    </div>

    <div class="grid grid-cols-2 lg:grid-cols-4 gap-4">
        <?php $__currentLoopData = [
            ['Subtotal', $invoice->subtotal, 'text-slate-950'],
            ['VAT', $invoice->vat_amount, 'text-violet-600'],
            ['Paid', $invoice->paid_amount, 'text-emerald-600'],
            ['Balance', $invoice->balance_due, 'text-rose-600'],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $amount, $color]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="rounded-2xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 p-4">
                <p class="text-[10px] font-bold uppercase tracking-wider text-slate-400"><?php echo e($label); ?></p>
                <p class="mt-1 text-xl font-extrabold <?php echo e($color); ?> dark:text-white">AED <?php echo e(number_format((float) $amount, 2)); ?></p>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <div class="grid grid-cols-1 xl:grid-cols-[1fr_390px] gap-6">
        <div class="space-y-6">
            <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700 overflow-hidden shadow-sm">
                <div class="p-5 border-b border-slate-200 dark:border-slate-700"><h2 class="font-bold text-slate-900 dark:text-white">Invoice fee classification</h2><p class="text-xs text-slate-500">Government/pass-through money is separated from company revenue and VAT.</p></div>
                <div class="overflow-x-auto">
                    <table class="w-full text-sm">
                        <thead class="bg-slate-50 dark:bg-slate-900/50 text-[11px] uppercase text-slate-500"><tr><th class="p-4 text-left">Description</th><th class="p-4 text-left">Classification</th><th class="p-4 text-right">Amount</th></tr></thead>
                        <tbody class="divide-y divide-slate-100 dark:divide-slate-700">
                            <?php $__currentLoopData = $invoice->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr><td class="p-4"><p class="font-semibold"><?php echo e($item->description); ?></p><p class="text-[11px] text-slate-400"><?php echo e(str_replace('_', ' ', $item->fee_type)); ?></p></td><td class="p-4"><span class="rounded-full px-2.5 py-1 text-[10px] font-bold uppercase <?php echo e($item->revenue_classification === 'government_clearing' ? 'bg-amber-100 text-amber-800' : ($item->revenue_classification === 'vat_liability' ? 'bg-violet-100 text-violet-800' : 'bg-emerald-100 text-emerald-800')); ?>"><?php echo e(str_replace('_', ' ', $item->revenue_classification)); ?></span></td><td class="p-4 text-right font-bold">AED <?php echo e(number_format((float) $item->total_amount, 2)); ?></td></tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php if((float) $invoice->discount_amount > 0): ?><tr class="bg-rose-50"><td class="p-4 font-semibold text-rose-700" colspan="2">Approved service-revenue discount</td><td class="p-4 text-right font-bold text-rose-700">− AED <?php echo e(number_format((float) $invoice->discount_amount, 2)); ?></td></tr><?php endif; ?>
                            <tr class="bg-slate-950 text-white"><td class="p-4 font-extrabold" colspan="2">Invoice total</td><td class="p-4 text-right text-lg font-extrabold">AED <?php echo e(number_format((float) $invoice->total_amount, 2)); ?></td></tr>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700 p-5 shadow-sm">
                <h2 class="font-bold text-slate-900 dark:text-white">Payment history</h2>
                <div class="mt-4 space-y-3">
                    <?php $__empty_1 = true; $__currentLoopData = $invoice->payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="rounded-2xl border border-slate-200 dark:border-slate-700 p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3">
                            <div><p class="font-bold text-sm"><?php echo e($payment->payment_number); ?></p><p class="text-xs text-slate-400"><?php echo e($payment->created_at->format('d M Y, H:i')); ?> · <?php echo e($payment->components->pluck('payment_method')->map(fn($v) => str_replace('_', ' ', $v))->join(' + ')); ?></p></div>
                            <div class="text-right"><p class="font-extrabold text-emerald-600">AED <?php echo e(number_format((float) $payment->amount, 2)); ?></p><?php if($payment->receipt): ?><a href="<?php echo e(route('app.billing.receipts.show', $payment->receipt->id)); ?>" class="text-xs font-bold text-sky-600">Receipt <?php echo e($payment->receipt->receipt_number); ?></a><?php endif; ?></div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <div class="rounded-2xl border border-dashed border-slate-200 p-8 text-center text-xs text-slate-400">No payments collected yet.</div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <aside class="bg-white dark:bg-slate-800 rounded-3xl border border-slate-200 dark:border-slate-700 p-5 shadow-sm h-fit">
            <div class="flex items-center justify-between"><div><p class="text-[10px] font-bold uppercase tracking-[0.18em] text-sky-600">Secure collection</p><h2 class="font-extrabold text-slate-950 dark:text-white">Collect payment</h2></div><span class="text-xs font-bold text-rose-600">Due AED <?php echo e(number_format((float) $invoice->balance_due, 2)); ?></span></div>

            <?php if(!in_array($invoice->status, ['cancelled','refunded'])): ?>
                <form method="POST" action="<?php echo e(route('app.billing.invoices.payments.store', $invoice->id)); ?>" class="mt-5 space-y-3">
                    <?php echo csrf_field(); ?>
                    <template x-for="(component, index) in components" :key="index">
                        <div class="rounded-2xl bg-slate-50 dark:bg-slate-900/50 border border-slate-200 dark:border-slate-700 p-3 space-y-2">
                            <div class="flex items-center justify-between"><span class="text-[10px] font-bold uppercase text-slate-400" x-text="`Tender ${index + 1}`"></span><button x-show="components.length > 1" type="button" @click="components.splice(index, 1)" class="text-xs font-bold text-rose-500">Remove</button></div>
                            <select x-model="component.payment_method" :name="`components[${index}][payment_method]`" class="w-full rounded-xl border-slate-200 bg-white text-sm">
                                <option value="cash">Cash</option><option value="card">Card</option><option value="bank_transfer">Bank transfer</option><option value="payment_link">Payment link</option><option value="cheque">Cheque</option><option value="wallet">Wallet</option><?php if($invoice->company_id): ?><option value="corporate_credit">Corporate credit</option><?php endif; ?>
                            </select>
                            <input x-model="component.amount" :name="`components[${index}][amount]`" type="number" step="0.01" min="0.01" placeholder="Amount" class="w-full rounded-xl border-slate-200 bg-white text-sm">
                            <input x-show="!['cash','corporate_credit'].includes(component.payment_method)" x-model="component.transaction_reference" :name="`components[${index}][transaction_reference]`" placeholder="Transaction reference" class="w-full rounded-xl border-slate-200 bg-white text-sm">
                        </div>
                    </template>
                    <button type="button" @click="components.push({ payment_method: 'card', amount: '', transaction_reference: '' })" class="w-full rounded-xl border border-dashed border-sky-300 py-2 text-xs font-bold text-sky-700">+ Add split tender</button>
                    <div class="rounded-xl bg-slate-950 text-white px-4 py-3 flex justify-between"><span class="text-xs font-bold">Payment total</span><span class="font-extrabold" x-text="`AED ${components.reduce((sum, item) => sum + (parseFloat(item.amount) || 0), 0).toFixed(2)}`"></span></div>
                    <button class="w-full rounded-xl bg-emerald-600 hover:bg-emerald-700 py-3 text-xs font-extrabold text-white">Record payment & issue receipt</button>
                </form>
            <?php else: ?>
                <div class="mt-5 rounded-2xl bg-rose-50 p-5 text-center text-xs text-rose-700">This invoice cannot receive payments.</div>
            <?php endif; ?>
        </aside>
    </div>
</div>
<?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\typingcenter\resources\views/tenant/billing/invoices/show.blade.php ENDPATH**/ ?>