File size: 5,575 Bytes
329a622 d5d97b9 329a622 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | // Enhanced Client Data with more details
const clients = [
{
name: "Chanda Mumba",
service: "Netflix Premium",
expiry: "Expires in 2 days",
theme: "netflix-theme",
color: "#E50914",
price: "ZMW 120",
paymentMethod: "Airtel Money",
lastRenewal: "2 weeks ago",
avatar: "http://static.photos/people/200x200/1"
},
{
name: "John Banda",
service: "Spotify Duo",
expiry: "Expires Tomorrow",
theme: "spotify-theme",
color: "#1DB954",
price: "ZMW 80",
paymentMethod: "MTN Money",
lastRenewal: "3 weeks ago",
avatar: "http://static.photos/people/200x200/2"
},
{
name: "Sarah Lungu",
service: "Apple Music",
expiry: "Expires Today",
theme: "spotify-theme",
color: "#FC3C44",
price: "ZMW 60",
paymentMethod: "Zanaco",
lastRenewal: "4 weeks ago",
avatar: "http://static.photos/people/200x200/3"
},
];
let activeIndex = clients.length - 1;
function renderCards() {
const stack = document.getElementById('cardStack');
stack.innerHTML = '';
clients.forEach((client, index) => {
const card = document.createElement('div');
card.className = `card ${client.theme}`;
let scale = 1 - (clients.length - 1 - index) * 0.04;
let translateY = (clients.length - 1 - index) * 8;
let zIndex = index;
card.style.zIndex = zIndex;
card.style.transform = `scale(${scale}) translateY(-${translateY}px)`;
card.style.backgroundImage = `url(${client.avatar})`;
card.style.backgroundSize = 'cover';
card.style.backgroundPosition = 'center';
card.style.backgroundBlendMode = 'overlay';
card.innerHTML = `
<div class="service-badge" style="border-color:${client.color}; color:${client.color}; background: rgba(0,0,0,0.5)">
<span>β</span> ${client.service}
</div>
<div class="client-info" style="background: rgba(0,0,0,0.5); padding: 15px; border-radius: 10px;">
<h2>${client.name}</h2>
<p>${client.service} β’ ${client.price} β’ ${client.paymentMethod}</p>
<span class="expiry-warning">${client.expiry}</span>
<p style="margin-top: 10px; font-size: 12px;">Last renewal: ${client.lastRenewal}</p>
</div>
`;
stack.appendChild(card);
});
}
// Enhanced Swipe Functions with API simulation
async function swipeRight() {
if(activeIndex < 0) return;
const cards = document.querySelectorAll('.card');
const topCard = cards[activeIndex];
const client = clients[activeIndex];
topCard.classList.add('swipe-right');
// Simulate API call
try {
topCard.innerHTML = '<div style="height:100%; display:flex; justify-content:center; align-items:center; font-size:18px;" class="loading">Processing renewal...</div>';
// Simulate network delay
await new Promise(resolve => setTimeout(resolve, 1500));
// Success case
topCard.innerHTML = `
<div style="height:100%; display:flex; flex-direction:column; justify-content:center; align-items:center; text-align:center; padding:20px;">
<span style="font-size:48px;">β
</span>
<h3 style="margin:10px 0;">Success!</h3>
<p>${client.service} renewed for ${client.name}</p>
</div>
`;
setTimeout(() => {
activeIndex--;
if(activeIndex >= 0) renderCards();
else stack.innerHTML = '<div style="height:100%; display:flex; justify-content:center; align-items:center; font-size:18px;">All clients processed</div>';
}, 1000);
} catch {
// Error case
topCard.innerHTML = `
<div style="height:100%; display:flex; flex-direction:column; justify-content:center; align-items:center; text-align:center; padding:20px;">
<span style="font-size:48px;">β</span>
<h3 style="margin:10px 0; color:#ff4b4b;">Error</h3>
<p>Could not process renewal</p>
<button onclick="window.location.reload()" style="margin-top:15px; background:#333; color:white; border:none; padding:8px 16px; border-radius:20px;">Retry</button>
</div>
`;
}
}
async function swipeLeft() {
if(activeIndex < 0) return;
const cards = document.querySelectorAll('.card');
const topCard = cards[activeIndex];
const client = clients[activeIndex];
topCard.classList.add('swipe-left');
// Simulate WhatsApp opening
await new Promise(resolve => setTimeout(resolve, 500));
const whatsappUrl = `https://wa.me/260960000000?text=Hi%20${encodeURIComponent(client.name.split(' ')[0])},%20your%20${encodeURIComponent(client.service)}%20subscription%20is%20about%20to%20expire!`;
window.open(whatsappUrl, '_blank');
setTimeout(() => {
activeIndex--;
if(activeIndex >= 0) renderCards();
}, 300);
}
// Initialize on load
document.addEventListener('DOMContentLoaded', () => {
renderCards();
// Add hover effects to bottom nav
document.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', function() {
document.querySelector('.nav-item.active')?.classList.remove('active');
this.classList.add('active');
});
});
}); |