

<?php $__env->startSection('title', $customer->fullName()); ?>
<?php $__env->startSection('page-title', $customer->fullName()); ?>
<?php $__env->startSection('page-subtitle', $customer->account_number); ?>

<?php $__env->startSection('content'); ?>
<?php
    $currency = $customer->tenant->settings['currency'] ?? 'NGN';
    $overview = $accountOverview;
    $notificationChannels = \App\Services\MemberNotificationAutomationService::channels();
    $notificationPreferences = $customer->notificationPreferences();
    $selectedNotificationChannels = old('notification_channels', array_keys(array_filter($notificationPreferences)));
?>

<?php if(session('kyc_url')): ?>
    <div class="alert alert-info border-0 shadow-sm d-flex flex-column flex-lg-row justify-content-between gap-2">
        <div>
            <div class="fw-semibold">Didit KYC link is ready</div>
            <div class="small"><?php echo e(session('kyc_url')); ?></div>
        </div>
        <a class="btn btn-primary btn-sm align-self-lg-center" target="_blank" rel="noopener" href="<?php echo e(session('kyc_url')); ?>">Open verification</a>
    </div>
<?php endif; ?>

<div class="row g-4">
    <div class="col-xl-4">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <div class="d-flex align-items-start gap-3">
                    <?php if($customer->photo_path): ?>
                        <img src="<?php echo e(asset('uploads/'.$customer->photo_path)); ?>" class="rounded object-fit-cover" style="width:88px;height:88px" alt="<?php echo e($customer->fullName()); ?>">
                    <?php else: ?>
                        <div class="rounded bg-info-subtle text-info-emphasis d-grid place-items-center fw-bold" style="width:88px;height:88px"><?php echo e(strtoupper(substr($customer->first_name, 0, 1).substr($customer->last_name, 0, 1))); ?></div>
                    <?php endif; ?>
                    <div class="min-w-0">
                        <h2 class="h5 mb-1"><?php echo e($customer->fullName()); ?></h2>
                        <div class="text-muted"><?php echo e($customer->phone); ?></div>
                        <div class="mt-2">
                            <span class="badge text-bg-info"><?php echo e(ucfirst($customer->kyc_status)); ?></span>
                            <span class="badge text-bg-secondary"><?php echo e(ucfirst($customer->status)); ?></span>
                            <?php if($customer->identityFieldsLocked()): ?>
                                <span class="badge text-bg-success">Identity locked</span>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>

                <div class="row g-3 mt-3">
                    <div class="col-6">
                        <div class="text-muted small">Savings</div>
                        <div class="fw-bold"><?php echo e($currency); ?> <?php echo e(number_format($overview['savings_balance'], 2)); ?></div>
                    </div>
                    <div class="col-6">
                        <div class="text-muted small">Loan balance</div>
                        <div class="fw-bold"><?php echo e($currency); ?> <?php echo e(number_format($overview['loan_balance'], 2)); ?></div>
                    </div>
                    <div class="col-6">
                        <div class="text-muted small">Due now</div>
                        <div class="fw-bold"><?php echo e($currency); ?> <?php echo e(number_format($overview['due_amount'], 2)); ?></div>
                    </div>
                    <div class="col-6">
                        <div class="text-muted small">Next due</div>
                        <div class="fw-bold"><?php echo e(app_date($overview['next_due_date']) ?? '-'); ?></div>
                    </div>
                </div>

                <hr>
                <dl class="row small mb-0">
                    <dt class="col-5 text-muted">DOB / age</dt>
                    <dd class="col-7"><?php echo e(app_date($customer->date_of_birth) ?? '-'); ?> <?php echo e($customer->age() !== null ? '('.$customer->age().' years)' : ''); ?></dd>
                    <dt class="col-5 text-muted">Account officer</dt>
                    <dd class="col-7"><?php echo e($customer->accountOfficer?->name ?? 'Unassigned'); ?></dd>
                    <dt class="col-5 text-muted">Member group</dt>
                    <dd class="col-7"><?php echo e($customer->customerGroup?->name ?? 'Ungrouped'); ?></dd>
                    <dt class="col-5 text-muted">BVN</dt>
                    <dd class="col-7"><?php echo e($customer->maskedBvn()); ?> <?php if($customer->bvn_verified_at): ?><span class="badge text-bg-success">Verified</span><?php endif; ?></dd>
                    <dt class="col-5 text-muted">NIN</dt>
                    <dd class="col-7"><?php echo e($customer->maskedNin()); ?> <?php if($customer->nin_verified_at): ?><span class="badge text-bg-success">Verified</span><?php endif; ?></dd>
                    <dt class="col-5 text-muted">KYC provider</dt>
                    <dd class="col-7"><?php echo e(ucfirst($customer->kyc_provider ?: ($customer->tenant->settings['kyc_provider'] ?? 'local'))); ?></dd>
                    <dt class="col-5 text-muted">KYC status</dt>
                    <dd class="col-7"><?php echo e($customer->kyc_provider_status ?: (app_datetime($customer->kyc_verified_at) ?? '-')); ?></dd>
                    <dt class="col-5 text-muted">Address</dt>
                    <dd class="col-7"><?php echo e($customer->address ?: '-'); ?></dd>
                </dl>

                <?php if(auth()->user()->hasPermission('customers.manage')): ?>
                    <div class="d-flex flex-wrap gap-2 mt-3">
                        <a href="<?php echo e(route('tenant.customers.edit', $customer)); ?>" class="btn btn-outline-primary btn-sm">Edit profile</a>
                        <form method="POST" action="<?php echo e(route('tenant.customers.kyc.verify', $customer)); ?>">
                            <?php echo csrf_field(); ?>
                            <button class="btn btn-primary btn-sm" type="submit"><i class="bi bi-shield-check me-1"></i> Verify KYC</button>
                        </form>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <div class="card border-0 shadow-sm mt-4">
            <div class="card-body">
                <div class="member-section-title mb-3">
                    <h3>Notification preferences</h3>
                    <p>Choose the channels this member has agreed to receive. SMS and WhatsApp may attract gateway charges.</p>
                </div>

                <?php if(auth()->user()->hasPermission('customers.manage')): ?>
                    <form method="POST" action="<?php echo e(route('tenant.customers.notification-preferences.update', $customer)); ?>" class="vstack gap-3">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('PATCH'); ?>
                        <div class="notification-preference-grid">
                            <?php $__currentLoopData = $notificationChannels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $channelKey => $channel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <label class="notification-preference-option">
                                    <input class="form-check-input" type="checkbox" name="notification_channels[]" value="<?php echo e($channelKey); ?>" <?php if(in_array($channelKey, $selectedNotificationChannels, true)): echo 'checked'; endif; ?>>
                                    <span>
                                        <i class="bi <?php echo e($channel['icon']); ?>"></i>
                                        <strong><?php echo e($channel['label']); ?></strong>
                                        <small><?php echo e(in_array($channelKey, ['sms', 'whatsapp'], true) ? 'Paid channel' : 'Standard channel'); ?></small>
                                    </span>
                                </label>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                        <button class="btn btn-primary btn-sm align-self-start" type="submit"><i class="bi bi-save me-1"></i> Save preferences</button>
                    </form>
                <?php else: ?>
                    <div class="notification-preference-grid">
                        <?php $__currentLoopData = $notificationChannels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $channelKey => $channel): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="notification-preference-option <?php echo e(($notificationPreferences[$channelKey] ?? false) ? '' : 'muted'); ?>">
                                <span>
                                    <i class="bi <?php echo e($channel['icon']); ?>"></i>
                                    <strong><?php echo e($channel['label']); ?></strong>
                                    <small><?php echo e(($notificationPreferences[$channelKey] ?? false) ? 'Allowed' : 'Opted out'); ?></small>
                                </span>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <div class="col-xl-8">
        <div class="row g-3 mb-4">
            <div class="col-md-4"><div class="card metric-card"><div class="card-body"><div class="text-muted small">Savings accounts</div><div class="h4 mb-0"><?php echo e($customer->savingsAccounts->count()); ?></div></div></div></div>
            <div class="col-md-4"><div class="card metric-card"><div class="card-body"><div class="text-muted small">Loans</div><div class="h4 mb-0"><?php echo e($customer->loans->count()); ?></div></div></div></div>
            <div class="col-md-4"><div class="card metric-card"><div class="card-body"><div class="text-muted small">Transactions</div><div class="h4 mb-0"><?php echo e($overview['transactions']->count()); ?></div></div></div></div>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white">
                <ul class="nav nav-tabs card-header-tabs" role="tablist">
                    <li class="nav-item" role="presentation"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#overview-pane" type="button">Overview</button></li>
                    <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#savings-pane" type="button">Savings</button></li>
                    <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#loans-pane" type="button">Loans</button></li>
                    <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#transactions-pane" type="button">Transactions</button></li>
                    <li class="nav-item" role="presentation"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#audit-pane" type="button">Audit trail</button></li>
                </ul>
            </div>
            <div class="card-body p-0">
                <div class="tab-content">
                    <div class="tab-pane fade show active p-3" id="overview-pane">
                        <div class="row g-3">
                            <div class="col-md-6">
                                <div class="border rounded p-3 h-100">
                                    <div class="fw-semibold mb-2">Virtual account</div>
                                    <?php if($customer->hasActiveVirtualAccount()): ?>
                                        <div class="text-muted small">Bank</div>
                                        <div><?php echo e($customer->virtual_account_bank_name ?: '-'); ?></div>
                                        <div class="text-muted small mt-2">Account number</div>
                                        <div class="h4 mb-0"><?php echo e($customer->virtual_account_number); ?></div>
                                        <div class="text-muted small mt-2">Account name</div>
                                        <div><?php echo e($customer->virtual_account_name ?: $customer->fullName()); ?></div>
                                    <?php else: ?>
                                        <div class="text-muted small mb-3">Create a dedicated virtual account so bank transfers can fund this member's savings automatically after the gateway webhook is configured.</div>
                                        <?php if(auth()->user()->hasPermission('customers.manage')): ?>
                                            <form method="POST" action="<?php echo e(route('tenant.customers.virtual-account.store', $customer)); ?>">
                                                <?php echo csrf_field(); ?>
                                                <button class="btn btn-primary btn-sm"><i class="bi bi-bank me-1"></i> Create virtual account</button>
                                            </form>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="border rounded p-3 h-100">
                                    <div class="fw-semibold mb-2">Guarantor</div>
                                    <div><?php echo e($customer->guarantor_name ?: '-'); ?></div>
                                    <div class="text-muted"><?php echo e($customer->guarantor_phone ?: '-'); ?></div>
                                    <div class="small mt-2"><?php echo e($customer->guarantor_relationship ?: '-'); ?></div>
                                    <div class="small text-muted mt-2"><?php echo e($customer->guarantor_address ?: '-'); ?></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="savings-pane">
                        <div class="table-responsive">
                            <table class="table mb-0">
                                <thead><tr><th>Account</th><th>Product</th><th class="text-end">Balance</th><th></th></tr></thead>
                                <tbody>
                                    <?php $__empty_1 = true; $__currentLoopData = $customer->savingsAccounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <tr>
                                            <td><?php echo e($account->account_number); ?></td>
                                            <td><?php echo e($account->product_name); ?></td>
                                            <td class="text-end"><?php echo e($currency); ?> <?php echo e(number_format($account->balance, 2)); ?></td>
                                            <td><a href="<?php echo e(route('tenant.savings.show', $account)); ?>" class="btn btn-sm btn-outline-secondary">Statement</a></td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr><td colspan="4" class="text-center text-muted py-4">No savings accounts yet.</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="loans-pane">
                        <div class="table-responsive">
                            <table class="table mb-0">
                                <thead><tr><th>Loan</th><th>Product</th><th>Status</th><th class="text-end">Principal</th><th class="text-end">Balance</th></tr></thead>
                                <tbody>
                                    <?php $__empty_1 = true; $__currentLoopData = $customer->loans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $loan): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <tr>
                                            <td><a href="<?php echo e(route('tenant.loans.show', $loan)); ?>"><?php echo e($loan->loan_number); ?></a></td>
                                            <td><?php echo e($loan->product?->name ?? '-'); ?></td>
                                            <td><?php echo e(ucfirst(str_replace('_', ' ', $loan->status))); ?></td>
                                            <td class="text-end"><?php echo e($currency); ?> <?php echo e(number_format($loan->principal, 2)); ?></td>
                                            <td class="text-end"><?php echo e($currency); ?> <?php echo e(number_format($loan->balance, 2)); ?></td>
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr><td colspan="5" class="text-center text-muted py-4">No loans yet.</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <div class="tab-pane fade" id="transactions-pane">
                        <?php echo $__env->make('tenant.partials.member-transaction-history', ['transactions' => $overview['transactions'], 'currency' => $currency], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>

                    <div class="tab-pane fade" id="audit-pane">
                        <?php echo $__env->make('tenant.partials.member-audit-trail', ['auditLogs' => $overview['audit_logs']], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </div>
                </div>
            </div>
        </div>
    </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:\Users\Polite hp\Documents\Codex\2026-05-08\build-a-complete-production-ready-saas\microfinance-saas\resources\views\tenant\customers\show.blade.php ENDPATH**/ ?>