<?php $__env->startSection('title', $customer->name_en); ?>

<?php $__env->startSection('content'); ?>
<div class="page-head">
    <div>
        <div class="d-flex align-items-center gap-2">
            <h1><?php echo e($customer->name_en); ?></h1>
            <span class="badge status-<?php echo e($customer->status); ?>"><?php echo e(strtoupper($customer->status)); ?></span>
        </div>
        <p><?php echo e($customer->customer_code); ?> <?php if($customer->name_ar): ?> · <span dir="rtl"><?php echo e($customer->name_ar); ?></span> <?php endif; ?></p>
    </div>
    <div class="d-flex gap-2">
        <a href="<?php echo e(route('customers.index')); ?>" class="btn btn-light border btn-dense"><i class="bi bi-arrow-left me-1"></i>Customers</a>
        <a href="<?php echo e(route('customers.statement', $customer)); ?>" class="btn btn-light border btn-dense"><i class="bi bi-journal-text me-1"></i>Statement</a>
        <?php if(auth()->user()->hasPermission('customers.edit')): ?>
            <a href="<?php echo e(route('customers.edit', $customer)); ?>" class="btn btn-light border btn-dense"><i class="bi bi-pencil me-1"></i>Edit</a>
        <?php endif; ?>
        <?php if(auth()->user()->hasPermission('sales.create')): ?>
            <a href="<?php echo e(route('sales.create', ['customer_id' => $customer->id])); ?>" class="btn btn-primary btn-dense"><i class="bi bi-plus-lg me-1"></i>New invoice</a>
        <?php endif; ?>
    </div>
</div>

<div class="row g-2 mb-3">
    <div class="col-6 col-xl">
        <div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label">Finalized invoices</div><div class="value"><?php echo e(number_format((int) $salesSummary->invoice_count)); ?></div></div><div class="icon"><i class="bi bi-receipt"></i></div></div></div>
    </div>
    <div class="col-6 col-xl">
        <div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label">Total sales</div><div class="value">SAR <?php echo e(number_format((float) $salesSummary->total_sales, 2)); ?></div></div><div class="icon"><i class="bi bi-graph-up-arrow"></i></div></div></div>
    </div>
    <div class="col-6 col-xl">
        <div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label">Total paid</div><div class="value text-success">SAR <?php echo e(number_format((float) $salesSummary->total_paid, 2)); ?></div></div><div class="icon"><i class="bi bi-cash-coin"></i></div></div></div>
    </div>
    <div class="col-6 col-xl">
        <div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label">Pending invoices</div><div class="value <?php echo e((float) $salesSummary->pending_amount > 0 ? 'text-danger' : ''); ?>">SAR <?php echo e(number_format((float) $salesSummary->pending_amount, 2)); ?></div></div><div class="icon"><i class="bi bi-hourglass-split"></i></div></div></div>
    </div>
    <div class="col-12 col-xl">
        <div class="card-erp stat-card h-100"><div class="d-flex justify-content-between"><div><div class="label">Account balance</div><div class="value text-accent">SAR <?php echo e(number_format((float) $customer->outstanding_balance, 2)); ?></div></div><div class="icon"><i class="bi bi-wallet2"></i></div></div></div>
    </div>
</div>

<div class="row g-3">
    <div class="col-lg-3">
        <div class="card-erp">
            <div class="card-erp-header">Customer details</div>
            <div class="card-erp-body">
                <div class="detail-row"><span>Type</span><strong><?php echo e(ucfirst($customer->customer_type)); ?></strong></div>
                <div class="detail-row"><span>Mobile</span><strong><?php echo e($customer->mobile ?: $customer->phone ?: '—'); ?></strong></div>
                <div class="detail-row"><span>Email</span><strong><?php echo e($customer->email ?: '—'); ?></strong></div>
                <div class="detail-row"><span>City</span><strong><?php echo e($customer->city_en ?: '—'); ?></strong></div>
                <div class="detail-row"><span>VAT number</span><strong><?php echo e($customer->vat_number ?: 'Not registered'); ?></strong></div>
                <div class="detail-row"><span>Credit limit</span><strong>SAR <?php echo e(number_format((float) $customer->credit_limit, 2)); ?></strong></div>
                <div class="detail-row"><span>Credit days</span><strong><?php echo e((int) $customer->credit_days); ?></strong></div>
                <div class="detail-row"><span>Last invoice</span><strong><?php echo e($salesSummary->last_invoice_date ? date('d M Y', strtotime($salesSummary->last_invoice_date)) : '—'); ?></strong></div>
            </div>
        </div>
    </div>

    <div class="col-lg-9">
        <div class="card-erp">
            <div class="card-erp-header"><span>Sales invoices</span><small class="text-muted">Draft and finalized invoices</small></div>
            <div class="table-responsive">
                <table class="table table-dense">
                    <thead><tr><th>Invoice</th><th>Date</th><th>Type</th><th>Warehouse</th><th>Payment</th><th class="text-end">Total</th><th class="text-end">Paid</th><th class="text-end">Pending</th><th>Status</th><th></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; ?>
                        <tr>
                            <td><a href="<?php echo e(route('sales.show', $invoice)); ?>" class="fw-bold text-accent text-decoration-none"><?php echo e($invoice->invoice_no); ?></a></td>
                            <td><?php echo e($invoice->invoice_date->format('d M Y')); ?></td>
                            <td><?php echo e(ucwords(str_replace('_', ' ', $invoice->invoice_type))); ?></td>
                            <td><?php echo e($invoice->warehouse?->code ?: '—'); ?></td>
                            <td><?php echo e(ucfirst($invoice->payment_type)); ?></td>
                            <td class="text-end fw-semibold"><?php echo e(number_format((float) $invoice->grand_total, 2)); ?></td>
                            <td class="text-end text-success"><?php echo e(number_format((float) $invoice->paid_total, 2)); ?></td>
                            <td class="text-end <?php echo e((float) $invoice->balance_total > 0 ? 'text-danger fw-semibold' : ''); ?>"><?php echo e(number_format((float) $invoice->balance_total, 2)); ?></td>
                            <td><span class="badge status-<?php echo e($invoice->status); ?>"><?php echo e(strtoupper($invoice->status)); ?></span></td>
                            <td class="text-end"><a href="<?php echo e(route('sales.show', $invoice)); ?>" class="btn btn-light border btn-dense">Open</a></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="10" class="text-center text-muted py-5">No sales invoices for this customer.</td></tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
            <?php if($invoices->hasPages()): ?><div class="card-erp-body border-top"><?php echo e($invoices->links()); ?></div><?php endif; ?>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
<style>
.detail-row{display:flex;justify-content:space-between;gap:12px;padding:7px 0;border-bottom:1px solid var(--line);font-size:11px}.detail-row:last-child{border-bottom:0}.detail-row span{color:var(--muted)}.detail-row strong{text-align:right;overflow-wrap:anywhere}.stat-card .value{font-size:16px}
</style>
<?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\saudi\resources\views/customers/show.blade.php ENDPATH**/ ?>