

<?php $__env->startSection('title', 'Merchant Dashboard'); ?>
<?php $__env->startSection('page-title', 'Merchant Dashboard'); ?>
<?php $__env->startSection('page-subtitle', 'Track assigned tenants, referral links, onboarding, and commissions'); ?>

<?php $__env->startSection('content'); ?>
<?php
    $statusClass = match ($agent->status) {
        \App\Models\Agent::STATUS_ACTIVE => 'text-bg-success',
        \App\Models\Agent::STATUS_PENDING => 'text-bg-warning',
        \App\Models\Agent::STATUS_SUSPENDED => 'text-bg-secondary',
        default => 'text-bg-light',
    };
    $kycClass = match ($agent->kyc_status) {
        \App\Models\Agent::KYC_VERIFIED => 'text-bg-success',
        \App\Models\Agent::KYC_SUBMITTED => 'text-bg-info',
        \App\Models\Agent::KYC_REJECTED => 'text-bg-danger',
        default => 'text-bg-warning',
    };
    $maxCommission = \App\Models\Agent::MAX_COMMISSION_RATE;
?>

<?php if($agent->status !== \App\Models\Agent::STATUS_ACTIVE): ?>
    <div class="alert alert-warning border-0 shadow-sm">
        <div class="fw-semibold">Your merchant profile is <?php echo e(strtolower($agent->statusLabel())); ?>.</div>
        <div>Links are ready, but commission earning starts when the super admin activates your profile.</div>
    </div>
<?php endif; ?>

<div class="merchant-dashboard-hero mb-4">
    <div>
        <span class="merchant-eyebrow">Merchant growth program</span>
        <h2>Earn <?php echo e($currentSelfRate); ?>% at your current level and grow up to <?php echo e($maxCommission); ?>%.</h2>
        <p>Track self-recruited tenants, assigned onboarding work, referrals, bonus eligibility, awards, wins, and gifts from one merchant portal.</p>
        <div class="d-flex flex-wrap gap-2">
            <?php if($agent->isActive()): ?>
                <?php if($agent->canOnboard()): ?>
                    <a class="btn btn-light" href="<?php echo e($agent->tenantSignupUrl()); ?>" target="_blank" rel="noopener">
                        <i class="bi bi-building-add me-1"></i> Share onboarding link
                    </a>
                <?php endif; ?>
                <a class="btn btn-outline-light" href="<?php echo e($agent->referralUrl()); ?>" target="_blank" rel="noopener">
                    <i class="bi bi-globe2 me-1"></i> Open landing page
                </a>
            <?php else: ?>
                <button class="btn btn-outline-light" disabled><i class="bi bi-hourglass-split me-1"></i> Awaiting approval</button>
            <?php endif; ?>
        </div>
    </div>
    <div class="merchant-level-panel">
        <div class="d-flex justify-content-between align-items-start gap-3">
            <div>
                <span>Current level</span>
                <strong><?php echo e($currentLevel['name']); ?></strong>
                <em><?php echo e($currentLevel['rate']); ?></em>
            </div>
            <i class="bi bi-award"></i>
        </div>
        <div class="merchant-progress">
            <div class="d-flex justify-content-between small fw-semibold mb-1">
                <span><?php echo e($activeTenantCount); ?> active companies</span>
                <span><?php echo e($nextLevel ? $nextLevel['name'].' at '.$nextLevel['target'] : 'Top level'); ?></span>
            </div>
            <div class="progress" role="progressbar" aria-valuenow="<?php echo e($incentiveProgress); ?>" aria-valuemin="0" aria-valuemax="100">
                <div class="progress-bar" style="width: <?php echo e($incentiveProgress); ?>%"></div>
            </div>
        </div>
        <div class="merchant-level-perk">
            <i class="bi bi-gift"></i>
            <span><?php echo e($currentLevel['gift']); ?></span>
        </div>
    </div>
</div>

<div class="card border-0 shadow-sm mb-4">
    <div class="card-body">
        <div class="d-flex flex-column flex-lg-row justify-content-between gap-3 align-items-lg-center">
            <div>
                <div class="d-flex flex-wrap align-items-center gap-2 mb-1">
                    <h2 class="h4 mb-0"><?php echo e($agent->displayName()); ?></h2>
                    <span class="badge <?php echo e($statusClass); ?>"><?php echo e($agent->statusLabel()); ?></span>
                    <span class="badge <?php echo e($kycClass); ?>">KYC: <?php echo e($agent->kycStatusLabel()); ?></span>
                    <span class="badge text-bg-info"><?php echo e($agent->merchantTypeLabel()); ?></span>
                    <span class="badge text-bg-primary"><?php echo e($currentSelfRate); ?>% self-recruited</span>
                    <span class="badge text-bg-warning"><?php echo e(\App\Models\Agent::ASSIGNED_ONBOARDING_COMMISSION_RATE); ?>% assigned</span>
                    <span class="badge text-bg-dark"><?php echo e(\App\Models\Agent::REFERRAL_COMMISSION_RATE); ?>% referral</span>
                </div>
                <div class="text-muted">Merchant code: <?php echo e($agent->code); ?></div>
            </div>
            <div class="d-flex flex-wrap gap-2">
                <?php if($agent->isActive()): ?>
                    <a class="btn btn-outline-primary" href="<?php echo e($agent->referralUrl()); ?>" target="_blank" rel="noopener">
                        <i class="bi bi-globe2 me-1"></i> Open landing page
                    </a>
                    <?php if($agent->canOnboard()): ?>
                        <a class="btn btn-primary" href="<?php echo e($agent->tenantSignupUrl()); ?>" target="_blank" rel="noopener">
                            <i class="bi bi-building-add me-1"></i> Onboarding link
                        </a>
                    <?php endif; ?>
                    <?php if($agent->canRefer()): ?>
                        <a class="btn btn-dark" href="<?php echo e($agent->referralSignupUrl()); ?>" target="_blank" rel="noopener">
                            <i class="bi bi-link-45deg me-1"></i> Referral link
                        </a>
                    <?php endif; ?>
                <?php else: ?>
                    <button class="btn btn-outline-secondary" disabled><i class="bi bi-hourglass-split me-1"></i> Links activate after approval</button>
                <?php endif; ?>
            </div>
        </div>
        <div class="row g-2 mt-3">
            <div class="col-lg-6">
                <label class="form-label small text-muted">Public landing page</label>
                <input class="form-control" value="<?php echo e($agent->referralUrl()); ?>" readonly onclick="this.select()">
            </div>
            <?php if($agent->canOnboard()): ?>
                <div class="col-lg-6">
                    <label class="form-label small text-muted">Onboarding signup link</label>
                    <input class="form-control" value="<?php echo e($agent->tenantSignupUrl()); ?>" readonly onclick="this.select()">
                </div>
            <?php endif; ?>
            <?php if($agent->canRefer()): ?>
                <div class="col-lg-6">
                    <label class="form-label small text-muted">Referral-only signup link</label>
                    <input class="form-control" value="<?php echo e($agent->referralSignupUrl()); ?>" readonly onclick="this.select()">
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<?php if($softwareProducts->isNotEmpty()): ?>
    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <div class="d-flex flex-column flex-lg-row justify-content-between gap-2 align-items-lg-center mb-3">
                <div>
                    <div class="text-muted small fw-semibold text-uppercase">All software brands</div>
                    <h3 class="h5 mb-1">Sell more than microfinance from this portal</h3>
                    <p class="text-muted mb-0">Use one merchant dashboard to share links for POS, hotel, HR, hospital, school, and other software products.</p>
                </div>
                <a class="btn btn-outline-primary btn-sm" href="<?php echo e(route('merchant.software-products.index')); ?>">
                    <i class="bi bi-grid-1x2 me-1"></i> View all products
                </a>
            </div>
            <div class="row g-3">
                <?php $__currentLoopData = $softwareProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $product): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="col-md-6 col-xl-3">
                        <div class="border rounded p-3 h-100">
                            <div class="d-flex justify-content-between gap-2 mb-2">
                                <div class="rounded d-grid place-items-center text-white" style="width:38px;height:38px;background:<?php echo e($product->color); ?>;">
                                    <i class="bi <?php echo e($product->displayIcon()); ?>"></i>
                                </div>
                                <span class="badge text-bg-light align-self-start"><?php echo e($product->onboarding_commission_rate); ?>%</span>
                            </div>
                            <div class="fw-semibold"><?php echo e($product->name); ?></div>
                            <div class="text-muted small"><?php echo e($product->categoryLabel()); ?></div>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </div>
    </div>
<?php endif; ?>

<div class="card border-0 shadow-sm mb-4 merchant-kyc-card">
    <div class="card-body">
        <div class="d-flex flex-column flex-lg-row justify-content-between gap-3 mb-3">
            <div>
                <div class="text-muted small fw-semibold text-uppercase">Merchant verification</div>
                <h3 class="h5 mb-1">Complete your KYC profile</h3>
                <p class="text-muted mb-0">Fill this once after signup. Super admin will review it before your merchant profile is fully verified.</p>
            </div>
            <span class="badge <?php echo e($kycClass); ?> align-self-start"><?php echo e($agent->kycStatusLabel()); ?></span>
        </div>

        <?php if($agent->kyc_status === \App\Models\Agent::KYC_REJECTED && filled($agent->kyc_rejected_reason)): ?>
            <div class="alert alert-danger border-0">
                <strong>Review note:</strong> <?php echo e($agent->kyc_rejected_reason); ?>

            </div>
        <?php endif; ?>

        <?php if($agent->kyc_status === \App\Models\Agent::KYC_VERIFIED): ?>
            <div class="merchant-kyc-verified">
                <i class="bi bi-shield-check"></i>
                <div>
                    <strong>KYC verified</strong>
                    <span>Your merchant verification was approved <?php echo e($agent->kyc_verified_at?->diffForHumans()); ?>. Verified fields are locked.</span>
                </div>
            </div>
        <?php else: ?>
            <form method="POST" action="<?php echo e(route('merchant.kyc.update')); ?>" enctype="multipart/form-data" class="row g-3">
                <?php echo csrf_field(); ?>
                <?php echo method_field('PATCH'); ?>
                <div class="col-md-4">
                    <label class="form-label">Date of birth</label>
                    <input name="date_of_birth" type="date" value="<?php echo e(old('date_of_birth', $agent->date_of_birth?->format('Y-m-d'))); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Country</label>
                    <input name="country" value="<?php echo e(old('country', $agent->country ?: 'Nigeria')); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">State</label>
                    <input name="state" value="<?php echo e(old('state', $agent->state)); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">City / Town</label>
                    <input name="city" value="<?php echo e(old('city', $agent->city)); ?>" class="form-control" required>
                </div>
                <div class="col-md-8">
                    <label class="form-label">Full address</label>
                    <input name="residential_address" value="<?php echo e(old('residential_address', $agent->residential_address)); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Coverage area</label>
                    <input name="coverage_area" value="<?php echo e(old('coverage_area', $agent->coverage_area)); ?>" class="form-control" placeholder="e.g. Lagos Mainland" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">ID type</label>
                    <select name="id_type" class="form-select" required>
                        <?php $__currentLoopData = ['national_id' => 'National ID', 'voters_card' => "Voter's Card", 'drivers_license' => "Driver's License", 'passport' => 'International Passport']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($value); ?>" <?php if(old('id_type', $agent->id_type) === $value): echo 'selected'; endif; ?>><?php echo e($label); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-4">
                    <label class="form-label">ID number</label>
                    <input name="id_number" value="<?php echo e(old('id_number', $agent->id_number)); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Years of experience</label>
                    <input name="years_experience" type="number" min="0" max="80" value="<?php echo e(old('years_experience', $agent->years_experience)); ?>" class="form-control">
                </div>
                <div class="col-md-4">
                    <label class="form-label">BVN</label>
                    <input name="bvn" value="<?php echo e(old('bvn', $agent->bvn)); ?>" class="form-control" maxlength="11">
                </div>
                <div class="col-md-4">
                    <label class="form-label">NIN</label>
                    <input name="nin" value="<?php echo e(old('nin', $agent->nin)); ?>" class="form-control" maxlength="11">
                </div>
                <div class="col-md-4">
                    <label class="form-label">Business registration no.</label>
                    <input name="business_registration_number" value="<?php echo e(old('business_registration_number', $agent->business_registration_number)); ?>" class="form-control">
                </div>
                <div class="col-md-4">
                    <label class="form-label">Bank name</label>
                    <input name="bank_name" value="<?php echo e(old('bank_name', $agent->bank_name)); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Account name</label>
                    <input name="account_name" value="<?php echo e(old('account_name', $agent->account_name)); ?>" class="form-control" required>
                </div>
                <div class="col-md-4">
                    <label class="form-label">Account number</label>
                    <input name="account_number" value="<?php echo e(old('account_number', $agent->account_number)); ?>" class="form-control" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label">Referee name</label>
                    <input name="referee_name" value="<?php echo e(old('referee_name', $agent->referee_name)); ?>" class="form-control" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label">Referee phone</label>
                    <input name="referee_phone" value="<?php echo e(old('referee_phone', $agent->referee_phone)); ?>" class="form-control" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label">Passport photo</label>
                    <input name="passport_photo" type="file" accept="image/*" class="form-control">
                    <?php if($agent->passport_photo_path): ?>
                        <a class="small d-inline-block mt-1" href="<?php echo e(asset('uploads/'.$agent->passport_photo_path)); ?>" target="_blank" rel="noopener">View uploaded photo</a>
                    <?php endif; ?>
                </div>
                <div class="col-md-6">
                    <label class="form-label">ID document</label>
                    <input name="id_document" type="file" accept="image/*,.pdf" class="form-control">
                    <?php if($agent->id_document_path): ?>
                        <a class="small d-inline-block mt-1" href="<?php echo e(asset('uploads/'.$agent->id_document_path)); ?>" target="_blank" rel="noopener">View uploaded ID</a>
                    <?php endif; ?>
                </div>
                <div class="col-12 d-flex flex-wrap justify-content-between align-items-center gap-2">
                    <div class="text-muted small">Accepted files: JPG, PNG, or PDF. Existing uploads remain if you do not choose new files.</div>
                    <button class="btn btn-primary"><i class="bi bi-shield-check me-1"></i> Submit KYC for review</button>
                </div>
            </form>
        <?php endif; ?>
    </div>
</div>

<div class="row g-3 mb-4">
    <div class="col-xl-7">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-body">
                <div class="d-flex flex-column flex-lg-row justify-content-between gap-2 mb-3">
                    <div>
                        <div class="text-muted small fw-semibold text-uppercase">Commission policy</div>
                        <h3 class="h5 mb-1">How your merchant commission is calculated</h3>
                        <p class="text-muted mb-0">This breakdown is only shown inside your merchant portal.</p>
                    </div>
                    <span class="badge text-bg-success align-self-start">Up to <?php echo e($maxCommission); ?>%</span>
                </div>
                <div class="merchant-rule-grid">
                    <?php $__currentLoopData = $commissionRules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rule): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="merchant-rule-card">
                            <i class="bi <?php echo e($rule['icon']); ?>"></i>
                            <span><?php echo e($rule['name']); ?></span>
                            <strong><?php echo e($rule['rate']); ?></strong>
                            <small><?php echo e($rule['description']); ?></small>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="col-xl-5">
        <div class="card border-0 shadow-sm h-100 merchant-bonus-card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-start gap-3 mb-3">
                    <div>
                        <div class="text-muted small fw-semibold text-uppercase">Rewards checklist</div>
                        <h3 class="h5 mb-1"><?php echo e($qualifiesForBonus ? 'Reward profile complete' : 'Complete your reward profile'); ?></h3>
                        <p class="text-muted mb-0">These items help qualify you for bonuses, awards, wins, gifts, and priority support.</p>
                    </div>
                    <i class="bi <?php echo e($qualifiesForBonus ? 'bi-stars' : 'bi-lock'); ?>"></i>
                </div>
                <div class="merchant-bonus-checklist">
                    <?php $__currentLoopData = $bonusChecklist; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php ($progress = (int) min(100, round(($item['current'] / max(1, $item['target'])) * 100))); ?>
                        <div class="<?php echo \Illuminate\Support\Arr::toCssClasses(['complete' => $item['complete']]); ?>">
                            <span><i class="bi <?php echo e($item['complete'] ? 'bi-check-circle-fill' : 'bi-circle'); ?>"></i><?php echo e($item['label']); ?></span>
                            <strong><?php echo e($item['complete'] ? 'Done' : $item['current'].' / '.$item['target']); ?></strong>
                            <div class="progress" role="progressbar" aria-valuenow="<?php echo e($progress); ?>" aria-valuemin="0" aria-valuemax="100">
                                <div class="progress-bar" style="width: <?php echo e($progress); ?>%"></div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row g-3 mb-4">
    <?php $__currentLoopData = [
        ['Merchant tenants', $tenantCount, 'bi-buildings', 'text-info'],
        ['Active tenants', $activeTenantCount, 'bi-building-check', 'text-success'],
        ['Self-recruited active', $selfOnboardedActiveCount, 'bi-building-add', 'text-primary'],
        ['Trial tenants', $trialTenantCount, 'bi-hourglass-split', 'text-warning'],
        ['This month commission', number_format($monthlyCommission, 2), 'bi-cash-coin', 'text-primary'],
        ['Pending commission', number_format($pendingCommission, 2), 'bi-wallet2', 'text-danger'],
        ['Paid commission', number_format($paidCommission, 2), 'bi-check2-circle', 'text-success'],
    ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $icon, $color]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="col-md-6 col-xl-3">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body d-flex justify-content-between gap-3">
                    <div>
                        <div class="text-muted small"><?php echo e($label); ?></div>
                        <div class="h4 mb-0"><?php echo e($value); ?></div>
                    </div>
                    <i class="bi <?php echo e($icon); ?> fs-3 <?php echo e($color); ?>"></i>
                </div>
            </div>
        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>

<div class="row g-4 mb-4">
    <div class="col-xl-5">
        <div class="card border-0 shadow-sm h-100 merchant-target-card">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-start gap-3 mb-3">
                    <div>
                        <div class="text-muted small fw-semibold text-uppercase">Monthly target</div>
                        <h3 class="h5 mb-1">Self-recruit <?php echo e($monthlyTarget); ?> companies</h3>
                        <p class="text-muted mb-0">Hit this target to qualify for bonus review and special merchant wins.</p>
                    </div>
                    <i class="bi bi-bullseye"></i>
                </div>
                <div class="d-flex justify-content-between fw-semibold small mb-1">
                    <span><?php echo e($selfOnboardedMonthlyCount); ?> self-recruited this month</span>
                    <span><?php echo e($monthlyTargetProgress); ?>%</span>
                </div>
                <div class="progress merchant-target-progress" role="progressbar" aria-valuenow="<?php echo e($monthlyTargetProgress); ?>" aria-valuemin="0" aria-valuemax="100">
                    <div class="progress-bar" style="width: <?php echo e($monthlyTargetProgress); ?>%"></div>
                </div>
                <div class="merchant-target-note">
                    <?php echo e(max(0, $monthlyTarget - $selfOnboardedMonthlyCount)); ?> more compan<?php echo e(max(0, $monthlyTarget - $selfOnboardedMonthlyCount) === 1 ? 'y' : 'ies'); ?> to complete this month target.
                </div>
            </div>
        </div>
    </div>
    <div class="col-xl-7">
        <div class="merchant-incentive-grid">
            <?php $__currentLoopData = $incentives; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $incentive): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="merchant-incentive-card">
                    <i class="bi <?php echo e($incentive['icon']); ?>"></i>
                    <strong><?php echo e($incentive['name']); ?></strong>
                    <span><?php echo e($incentive['target']); ?></span>
                    <em><?php echo e($incentive['status']); ?></em>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>

<div class="card border-0 shadow-sm mb-4">
    <div class="card-body">
        <div class="d-flex flex-column flex-lg-row justify-content-between gap-3 align-items-lg-center mb-3">
            <div>
                <h3 class="h5 mb-1">Merchant levels</h3>
                <div class="text-muted small">Levels are based on active companies and control the self-recruited commission rate. Assigned onboarding remains <?php echo e(\App\Models\Agent::ASSIGNED_ONBOARDING_COMMISSION_RATE); ?>%, while referral remains <?php echo e(\App\Models\Agent::REFERRAL_COMMISSION_RATE); ?>%.</div>
            </div>
            <span class="badge text-bg-warning">Top rate: up to <?php echo e($maxCommission); ?>%</span>
        </div>
        <div class="merchant-dashboard-levels">
            <?php $__currentLoopData = $incentiveLevels; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $level): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <div class="<?php echo \Illuminate\Support\Arr::toCssClasses([$level['class'], 'active' => $currentLevel['name'] === $level['name']]); ?>">
                    <span><?php echo e($level['name']); ?></span>
                    <strong><?php echo e($level['rate']); ?></strong>
                    <small><?php echo e($level['target']); ?>+ active companies</small>
                </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>

<div class="row g-4">
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white fw-semibold">Recent merchant tenants</div>
            <div class="table-responsive">
                <table class="table mb-0 align-middle">
                    <thead><tr><th>Company</th><th>Plan</th><th>Commission</th><th>Status</th><th>Assigned</th></tr></thead>
                    <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $tenants; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tenant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <div class="fw-semibold"><?php echo e($tenant->name); ?></div>
                                <small class="text-muted"><?php echo e($tenant->owner_name); ?></small>
                            </td>
                            <td><?php echo e($tenant->plan?->name ?? '-'); ?></td>
                            <td><?php echo e(\App\Models\Agent::commissionTypeLabel($tenant->agent_commission_type)); ?></td>
                            <td><span class="badge text-bg-light"><?php echo e($tenant->isOnTrial() ? 'Trial' : ucfirst($tenant->status)); ?></span></td>
                            <td><?php echo e($tenant->agent_assigned_at?->diffForHumans() ?? '-'); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="5" class="text-center text-muted py-4">No tenants assigned yet.</td></tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-white fw-semibold">Commission history</div>
            <div class="table-responsive">
                <table class="table mb-0 align-middle">
                    <thead><tr><th>Tenant</th><th>Type</th><th>Cycle</th><th>Amount</th><th>Status</th></tr></thead>
                    <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $commissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $commission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td>
                                <div class="fw-semibold"><?php echo e($commission->tenant?->name ?? 'Tenant'); ?></div>
                                <small class="text-muted"><?php echo e(app_date($commission->earned_at)); ?></small>
                            </td>
                            <td><?php echo e(\App\Models\Agent::commissionTypeLabel($commission->commission_type)); ?></td>
                            <td><?php echo e(ucfirst($commission->billing_cycle)); ?></td>
                            <td><?php echo e(number_format($commission->commission_amount, 2)); ?></td>
                            <td>
                                <span class="badge <?php echo e($commission->status === \App\Models\AgentCommission::STATUS_PAID ? 'text-bg-success' : 'text-bg-warning'); ?>">
                                    <?php echo e($commission->statusLabel()); ?>

                                </span>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="5" class="text-center text-muted py-4">No commissions yet.</td></tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </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\agent\dashboard.blade.php ENDPATH**/ ?>