const ajaxurl = "https://icf8live.com/wp-admin/admin-ajax.php";

function loadUsers(){

fetch(ajaxurl,{
method:"POST",
headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'icf_get_all_users'
})
})
.then(r=>r.json())
.then(res=>{

let box = document.getElementById("walletBox");
box.innerHTML="";

if(!res.success){
box.innerHTML="Error loading users";
return;
}

res.data.forEach(u=>{

let statusColor = (u.status === 'blocked') ? '#ff4444' : '#00ff88';

box.innerHTML += `
<div style="display:flex;gap:10px;margin-bottom:10px;align-items:center;background:#000;padding:10px;border-radius:8px">

<div style="flex:1">
<b>${u.username}</b><br>
<span style="color:${statusColor};font-size:12px">${u.status}</span>
</div>

<div>₱${u.balance}</div>

<input id="amt_${u.id}" placeholder="Amount" style="width:80px;padding:5px;background:#222;color:#fff;border:none">

<button onclick="addBal(${u.id})">+</button>
<button onclick="subBal(${u.id})">-</button>

</div>
`;

});

});
}

/* 🔥 ADD BALANCE */
function addBal(id){

let amt = document.getElementById("amt_"+id).value;

if(!amt || amt <= 0){
alert("Enter amount");
return;
}

fetch(ajaxurl,{
method:"POST",
headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'icf_add_balance',
user:id,
amount:amt
})
})
.then(r=>r.json())
.then(res=>{
if(!res.success){
alert(res.data);
return;
}
loadUsers();
});

}

/* 🔥 SUB BALANCE */
function subBal(id){

let amt = document.getElementById("amt_"+id).value;

if(!amt || amt <= 0){
alert("Enter amount");
return;
}

fetch(ajaxurl,{
method:"POST",
headers:{'Content-Type':'application/x-www-form-urlencoded'},
body:new URLSearchParams({
action:'icf_sub_balance',
user:id,
amount:amt
})
})
.then(r=>r.json())
.then(res=>{
if(!res.success){
alert(res.data);
return;
}
loadUsers();
});

}

loadUsers();<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://icf8live.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://icf8live.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://icf8live.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://icf8live.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://icf8live.com/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
