<?php $__env->startSection('title', 'Referrals & Rewards'); ?>

<?php $__env->startSection('content'); ?>
<div x-data="{ adjust: false }">
    <div class="mb-5 flex items-center justify-between">
        <div>
            <h1 class="text-xl font-extrabold text-slate-900 lg:text-2xl">Referrals & rewards</h1>
            <p class="text-sm text-slate-500">Loyalty engine — referrals, points earned and redemptions.</p>
        </div>
        <button @click="adjust = true" class="rounded-xl bg-indigo-600 px-4 py-2.5 text-sm font-bold text-white shadow-lg shadow-indigo-600/25 hover:bg-indigo-700">± Adjust points</button>
    </div>

    <div class="mb-5 grid grid-cols-2 gap-3 sm:grid-cols-4">
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Referrals</p><p class="mt-1 text-2xl font-extrabold text-slate-900"><?php echo e($summary['total']); ?></p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Rewarded</p><p class="mt-1 text-2xl font-extrabold text-emerald-600"><?php echo e($summary['rewarded']); ?></p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Points issued</p><p class="mt-1 text-2xl font-extrabold text-violet-600"><?php echo e(number_format($summary['points_issued'])); ?></p></div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200"><p class="text-xs font-bold uppercase text-slate-400">Points redeemed</p><p class="mt-1 text-2xl font-extrabold text-rose-600"><?php echo e(number_format($summary['points_redeemed'])); ?></p></div>
    </div>

    <div class="grid gap-5 lg:grid-cols-2">
        <div class="rounded-2xl bg-white p-5 shadow-sm ring-1 ring-slate-200">
            <h2 class="mb-3 font-bold text-slate-900">Referral log</h2>
            <div class="divide-y divide-slate-100">
                <?php $__empty_1 = true; $__currentLoopData = $referrals; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $referral): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="flex items-center justify-between py-2.5 text-sm">
                        <div>
                            <p class="font-semibold text-slate-800"><?php echo e($referral->referrer->name ?? '—'); ?> → <?php echo e($referral->referred->name ?? '—'); ?></p>
                            <p class="text-xs text-slate-400">Code <?php echo e($referral->code_used); ?> · <?php echo e($referral->created_at->format('j M Y')); ?></p>
                        </div>
                        <span class="font-bold text-violet-600">+<?php echo e($referral->reward_points); ?> pts</span>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="py-6 text-center text-sm text-slate-400">No referrals recorded yet.</p>
                <?php endif; ?>
            </div>
            <div class="mt-3"><?php echo e($referrals->links()); ?></div>
        </div>

        <div class="rounded-2xl bg-white p-5 shadow-sm ring-1 ring-slate-200">
            <h2 class="mb-3 font-bold text-slate-900">Reward transactions</h2>
            <div class="divide-y divide-slate-100">
                <?php $__empty_1 = true; $__currentLoopData = $rewards; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tx): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <div class="flex items-center justify-between py-2.5 text-sm">
                        <div>
                            <p class="font-semibold text-slate-800"><?php echo e($tx->customer->name ?? '—'); ?></p>
                            <p class="text-xs text-slate-400"><?php echo e($tx->description); ?> · <?php echo e(ucfirst($tx->type)); ?> · <?php echo e($tx->created_at->format('j M Y')); ?></p>
                        </div>
                        <span class="font-bold <?php echo e($tx->points > 0 ? 'text-emerald-600' : 'text-rose-500'); ?>"><?php echo e($tx->points > 0 ? '+' : ''); ?><?php echo e($tx->points); ?></span>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <p class="py-6 text-center text-sm text-slate-400">No reward activity yet.</p>
                <?php endif; ?>
            </div>
            <div class="mt-3"><?php echo e($rewards->links()); ?></div>
        </div>
    </div>

    
    <div x-cloak x-show="adjust" class="fixed inset-0 z-50 flex items-end justify-center sm:items-center">
        <div class="absolute inset-0 bg-slate-900/50 backdrop-blur-sm" @click="adjust = false"></div>
        <div x-show="adjust" x-transition class="relative w-full max-w-md rounded-t-3xl bg-white p-6 shadow-2xl sm:rounded-3xl">
            <h2 class="mb-4 text-lg font-extrabold">Adjust reward points</h2>
            <form method="POST" action="<?php echo e(route('epelcon.rewards.adjust')); ?>" class="space-y-4"><?php echo csrf_field(); ?>
                <label class="block"><span class="mb-1 block text-xs font-bold uppercase text-slate-500">Customer</span>
                    <select name="customer_id" required class="w-full rounded-xl border-slate-200 text-sm">
                        <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $customer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($customer->id); ?>"><?php echo e($customer->name); ?> (<?php echo e($customer->reward_points); ?> pts)</option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select></label>
                <div class="grid grid-cols-2 gap-4">
                    <label><span class="mb-1 block text-xs font-bold uppercase text-slate-500">Action</span>
                        <select name="type" class="w-full rounded-xl border-slate-200 text-sm">
                            <option value="earn">Add points</option><option value="redeem">Redeem points</option><option value="adjustment">Adjustment</option>
                        </select></label>
                    <label><span class="mb-1 block text-xs font-bold uppercase text-slate-500">Points</span>
                        <input type="number" name="points" required class="w-full rounded-xl border-slate-200 text-sm"></label>
                </div>
                <label class="block"><span class="mb-1 block text-xs font-bold uppercase text-slate-500">Reason</span>
                    <input name="description" required placeholder="e.g. Redeemed for dinner voucher" class="w-full rounded-xl border-slate-200 text-sm"></label>
                <div class="flex justify-end gap-2">
                    <button type="button" @click="adjust = false" class="rounded-xl px-4 py-2.5 text-sm font-bold text-slate-500">Cancel</button>
                    <button class="rounded-xl bg-indigo-600 px-5 py-2.5 text-sm font-bold text-white">Apply</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.epelcon', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\hms\resources\views/epelcon/memberships/referrals.blade.php ENDPATH**/ ?>