/* ANWAAR RETURN REQUEST — native store form, all devices. */ (function(){'use strict';if(!/page-653883572(?:\/|$)/.test(location.pathname))return;function mount(){if(document.getElementById('anwaar-return-request'))return;const content=document.querySelector('.content-entry');if(!content)return;const host=document.createElement('section');host.id='anwaar-return-request';host.setAttribute('aria-label','نموذج طلب استرجاع أو استبدال');host.style.cssText='max-width:1024px;margin:24px auto 12px;border:1px solid #e1e7ec;border-radius:12px;background:#f8f9fb;scroll-margin-top:100px';const heading=document.createElement('h2');heading.textContent='↶ نموذج طلب استرجاع';heading.style.cssText='padding:14px 18px;margin:0;background:#183044;color:white;border-radius:12px 12px 0 0;font-size:17px';host.appendChild(heading);const app=document.createElement('div');host.appendChild(app);content.appendChild(host);const root=app.attachShadow({mode:'open'});root.innerHTML="
أكمل البيانات التالية وسيتابع فريقنا طلبك بعد الإرسال.
'+escapeHTML(v)+'
✓ اكتمل رفع '+media.length+' مرفقات. جاهزة لإرسال الطلب.
';} async function ensureUploads(){await session(values());for(let i=0;iنرفع المرفقات الآن حتى يكون إرسال طلبك أسرع في الخطوة الأخيرة.
';await ensureUploads();}catch(e){fileList();fail(e.message+' يمكنك الضغط على التالي لاستكمال الرفع.');}finally{lock(false);render();}} document.getElementById('files').onchange=e=>add(e.target.files);document.getElementById('drop').ondragover=e=>e.preventDefault();document.getElementById('drop').ondrop=e=>{e.preventDefault();void add(e.dataTransfer.files);}; async function session(v){const key=v.order+'|'+v.phone;if(token&&sessionKey===key)return;const s=await rpc('publicReturnBegin',{order:v.order,phone:v.phone,website:v.website});token=s.token;sessionKey=key;media.forEach(m=>{delete m.upload;});} async function upload(m,index){if(!m.upload)m.upload=await rpc('publicReturnMediaBegin',{token,name:m.name,mimeType:m.mimeType,size:m.blob.size});const state=m.upload;while(state.uploadedرفع المرفق '+(index+1)+' من '+media.length+' · '+Math.round(state.uploaded/m.blob.size*100)+'٪
';}} document.getElementById('back').onclick=()=>{if(busy)return;error.hidden=true;step=Math.max(0,step-1);render();if(step===0)returnBridgePost("ANWAAR_RETURN_BACK");}; function showWelcome(order){document.getElementById('welcome-order').textContent=order;document.getElementById('welcome').showModal();document.getElementById('welcome-close').onclick=()=>document.getElementById('welcome').close();} document.getElementById('next').onclick=async()=>{if(busy||!valid())return;error.hidden=true; if(step<4){if(step===0&&token&&sessionKey!==values().order+'|'+values().phone){token='';sessionKey='';media.forEach(m=>delete m.upload);document.getElementById('upload-status').innerHTML='';}if(step===2&&!allMediaReady()){lock(true);document.getElementById('next').textContent='جارٍ استكمال رفع المرفقات…';try{await ensureUploads();}catch(e){fail(e.message);return;}finally{lock(false);render();}}step++;render();return;} if(!minimumMedia()){step=2;render();fail('المرفقات إلزامية: أرفق صورتين للمنتج وفيديو واحدًا على الأقل.');return;} if(!allMediaReady()){step=2;render();fail('يلزم إكمال رفع المرفقات قبل إرسال الطلب. اضغط التالي لاستكمال الرفع.');return;} const v=values();lock(true);const button=document.getElementById('next');button.textContent='جارٍ تأكيد الطلب…';let waitTimer=setTimeout(()=>{document.getElementById('upload-status').innerHTML='جارٍ انتظار تأكيد الحفظ. يرجى إبقاء الصفحة مفتوحة لتجنب تكرار الطلب.
';},5000); try{const result=await rpc('publicReturnSubmit',{...v,token,mediaTokens:media.map(m=>m.upload.mediaToken)});clearTimeout(waitTimer);media.forEach(m=>URL.revokeObjectURL(m.url));form.innerHTML='رقم الطلب: '+escapeHTML(result.order)+'
شكرًا لاختيارك شركة أنوار الثريا. سيتواصل معك فريقنا لمتابعة طلبك.
العودة إلى المتجر