/* All assets and UI behavior are local. No CDN or financial data in persistent browser storage. */ (() => { 'use strict'; let toast; function status(text){if(!toast){toast=document.createElement('div');toast.className='pay-copy-status';toast.setAttribute('role','status');document.body.append(toast);}toast.textContent=text;toast.hidden=false;setTimeout(()=>{toast.hidden=true;},3000);} async function copy(text){ try{await navigator.clipboard.writeText(text);status('کپی شد');return true;} catch{ const dialog=document.createElement('dialog');dialog.className='pay-manual-copy';dialog.setAttribute('aria-label','کپی اطلاعات'); const title=document.createElement('h2');title.textContent='متن را انتخاب و کپی کنید';const area=document.createElement('textarea');area.readOnly=true;area.value=text; const select=document.createElement('button');select.className='pay-button';select.textContent='انتخاب متن';select.onclick=()=>{area.focus();area.select();}; const close=document.createElement('button');close.className='pay-button secondary';close.textContent='بستن';close.onclick=()=>dialog.close();dialog.append(title,area,select,close);document.body.append(dialog);dialog.addEventListener('close',()=>dialog.remove());dialog.showModal();area.focus();area.select(); return false; } } document.querySelectorAll('[data-copy]').forEach(button=>button.addEventListener('click',()=>copy(button.dataset.copy))); document.querySelectorAll('[data-notice-sms]').forEach(form=>form.addEventListener('submit',event=>{ if(form.dataset.sending==='true'){event.preventDefault();return;} form.dataset.sending='true';const button=form.querySelector('button');button.disabled=true;button.textContent='در حال ثبت درخواست ارسال…'; })); document.querySelectorAll('[data-share-link]').forEach(form=>{ const button=form.querySelector('button'),label=button.querySelector('span'),originalLabel=label.textContent; const feedback=form.querySelector('[role="status"]'); form.addEventListener('submit',async event=>{ event.preventDefault(); // This AJAX form owns its button state; keep the generic navigation submit handler out. event.stopPropagation(); if(button.disabled)return; button.disabled=true;button.setAttribute('aria-busy','true');label.textContent='در حال آماده‌سازی لینک…';feedback.textContent='در حال آماده‌سازی لینک…'; try{ const response=await fetch(form.action,{method:'POST',body:new FormData(form),credentials:'same-origin',cache:'no-store',headers:{'Accept':'application/json'}}); if(!response.ok || !response.headers.get('Content-Type')?.includes('application/json'))throw new Error('share unavailable'); const data=await response.json(); const copied=await copy(data.url); label.textContent=copied?'لینک کپی شد؛ کپی دوباره':originalLabel; feedback.textContent=copied?'لینک کوتاه کپی شد؛ می‌توانید آن را برای دیگران ارسال کنید.':'لینک آماده است؛ کپی خودکار ممکن نشد. متن را از پنجرهٔ بازشده انتخاب و کپی کنید.'; }catch{label.textContent=originalLabel;feedback.textContent='دریافت لینک ممکن نشد. دوباره تلاش کنید یا لینک پرداخت دریافتی را باز کنید.';} finally{button.disabled=false;button.removeAttribute('aria-busy');} }); }); const identifiers=document.querySelector('#identifier-accounts'),account=document.querySelector('#id_account'),deposit=document.querySelector('#id_deposit_id'); if(identifiers && account && deposit){const ids=JSON.parse(identifiers.textContent).map(String);function update(){deposit.required=ids.includes(account.value);document.querySelector('#identifier-help').textContent=deposit.required?'این حساب شناسه‌دار است؛ شناسه واریز مشتری الزامی است.':'شناسه واریز در صورت اعلام بانک وارد شود.';}account.addEventListener('change',update);update();} const badge=document.querySelector('[data-payment-count]'); if(badge){const update=async()=>{if(document.hidden)return;try{const response=await fetch(badge.dataset.countUrl,{credentials:'same-origin',cache:'no-store'});if(!response.ok)return;const data=await response.json();document.querySelectorAll('[data-payment-count]').forEach(node=>{node.textContent=String(data.pending_receipts);});}catch{}};document.addEventListener('visibilitychange',update);setInterval(update,60000);} })();