`; w.document.open();w.document.write(html);w.document.close();} async function refresh(silent=false){if(S.busy)return;S.busy=true;try{const r=await api('dashboard',{},true);S.data=r.data;frame();if(!silent)notify('تم تحديث السجلات')}catch(err){if(/الجلسة|الدخول/.test(err.message)){S.token='';localSession.remove();loginView()}else{notify(err.message,true);if(!S.data)loginView()}}finally{S.busy=false}} async function logout(){try{await api('logout')}catch(_){}localSession.remove();S.token='';S.data=null;loginView()} async function publicVerify(code){E('root').innerHTML=`
ORDRAT

التحقق من شهادة الوكيل

`;try{const r=await api('verify',{code},false);const d=r.data||{},valid=d.status==='active';E('root').innerHTML=`
ORDRAT

التحقق من شهادة الوكيل

${valid?'شهادة سارية وفق سجل أوردرات':'الشهادة غير سارية حالياً'}
الحالة: ${esc(statLabel[d.status]||d.status)}
رقم الشهادة${esc(d.certificate)}
البرنامج${esc(d.program)}
الوكيل${esc(d.partner)}
الدول${esc((d.countries||[]).join(', '))}

الصلاحية: ${date(d.start)} — ${date(d.end)}

هذه صفحة تحقق خاصة بتفويض أوردرات التسويقي وليست دليلاً على قيد حكومي.
`}catch(err){E('root').innerHTML=`

تعذر التحقق من الشهادة

${esc(err.message)}

`}} const code=new URLSearchParams(location.search).get('verify');if(code){publicVerify(code)}else if(S.token){refresh()}else{loginView()} })();