document.addEventListener('DOMContentLoaded',()=>{const base=window.APP_BASE||'',wallets={BTC:'bc1qvd9krn00g96wft44g8uk0tx773k4v48e22xn6e',ETH:'0xb5A72107341d1a88296d2aA0bEb6a89B0269610a',USDT:'TWPKoRJxcaqZWcpJj5MDkscja1zbtq8rdF'},ids={BTC:'bitcoin',ETH:'ethereum',USDT:'tether'};let prices={};const asset=document.getElementById('cryptoType'),amount=document.getElementById('usdAmount'),wallet=document.getElementById('walletAddress'),crypto=document.getElementById('cryptoAmount'),box=document.getElementById('depositAlert');const message=(text,good=false)=>box.innerHTML=`<div class="notice" style="${good?'background:#ecfdf5;border-color:#a7f3d0;color:#047857':'background:#fef2f2;border-color:#fecaca;color:#b91c1c'}">${text}</div>`;fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum,tether&vs_currencies=gbp').then(r=>r.json()).then(d=>prices={BTC:d.bitcoin.gbp,ETH:d.ethereum.gbp,USDT:d.tether.gbp}).catch(()=>{});function quote(){wallet.value=wallets[asset.value]||'';const rate=prices[asset.value],value=Number(amount.value);crypto.value=rate&&value>0?`${(value/rate).toFixed(8)} ${asset.value}`:''}asset.addEventListener('change',quote);amount.addEventListener('input',quote);document.getElementById('depositForm').addEventListener('submit',async e=>{e.preventDefault();if(!asset.value||!crypto.value){message('Select an asset and enter a valid amount. A current GBP price quote is required.');return}const btn=document.getElementById('submitDepositBtn');btn.disabled=true;btn.textContent='Submitting…';try{const r=await fetch(`${base}/submit-deposit.php`,{method:'POST',body:new FormData(e.currentTarget)}),d=await r.json();message(d.message,!!d.success);if(d.success)e.currentTarget.reset()}catch{message('Unable to submit your deposit request. Please try again.')}finally{btn.disabled=false;btn.textContent='Submit for review'}})});