/* Fußball Manager Backflash – Public Donation */
(() => {
  const cfg=window.BACKFLASH_PUBLIC_CONFIG||{};
  const DONATION_URL=String(cfg.donationUrl||'').trim();
  function initDonation(){
    const btn=document.getElementById('donateBtn');
    const modal=document.getElementById('donationModal');
    const close=document.getElementById('donationClose');
    const open=document.getElementById('donationOpenLink');
    if(!btn||!modal)return;
    const hide=()=>{modal.hidden=true;document.body.classList.remove('donation-open');};
    const show=()=>{modal.hidden=false;document.body.classList.add('donation-open');};
    btn.addEventListener('click',show);
    close?.addEventListener('click',hide);
    modal.addEventListener('click',e=>{if(e.target===modal)hide();});
    document.addEventListener('keydown',e=>{if(e.key==='Escape'&&!modal.hidden)hide();});
    open?.addEventListener('click',()=>{
      if(!DONATION_URL){
        alert('Der öffentliche Support-Link ist noch nicht konfiguriert. Trage ihn in public-config.js ein.');
        return;
      }
      window.open(DONATION_URL,'_blank','noopener,noreferrer');
    });
  }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',initDonation); else initDonation();
  window.BackflashDonation={get url(){return DONATION_URL;}};
})();
