import{i as I,I as N,w as r,r as $,t as B,b as S,O as i,J as O,K as L,c as g,e as x,D as y,d as V,a as M,g as _,f as k,P as D,H as E,z as R,A as h,u as l,L as T,j as U}from"./index--aiJRDg4.js";import{_ as j,a as z,b as C}from"./AuthLayout.vue_vue_type_script_setup_true_lang-Bbht7KM7.js";import"./ThemeToggle.vue_vue_type_script_setup_true_lang-MhHgjOGX.js";const H={key:0,class:"mb-4 rounded-xl border border-brand-500/40 bg-brand-500/10 px-4 py-3 text-sm text-brand-700 dark:text-brand-500"},J={key:1,class:"mb-4 rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-400"},K={key:2,class:"mt-4 text-center text-sm text-muted"},W=I({__name:"VerifyOtpView",setup(P){const s=O(),o=L(),d=N(),m=g(()=>U()==="admin"||s.meta.adminAuth===!0),u=g(()=>String(s.query.mobile??"")),c=g(()=>s.query.devCode),p=r(c.value??""),v=r(!1),f=r(!1),a=r(""),n=r(Number(s.query.expires)||120);let b=null;$(()=>{if(!u.value){o.replace({name:m.value?"admin-login":"login"});return}b=setInterval(()=>{n.value>0&&(n.value-=1)},1e3)}),B(()=>{b&&clearInterval(b)});async function q(){a.value="",v.value=!0;try{const e=await T(u.value,p.value.trim());if(d.setSession(e.accessToken,e.user),m.value){if(!d.isAdmin){d.logout(),a.value="دسترسی ادمین ندارید.";return}await o.replace({name:"admin-home"});return}await o.replace({name:"app-home"})}catch(e){a.value=e instanceof h?e.message:"کد نامعتبر است. دوباره تلاش کنید."}finally{v.value=!1}}async function A(){a.value="",f.value=!0;try{const e=await R(u.value);n.value=e.expiresInSeconds,e.otpCode&&await o.replace({query:{...s.query,devCode:e.otpCode,expires:String(e.expiresInSeconds)}})}catch(e){a.value=e instanceof h?e.message:"ارسال مجدد ناموفق بود."}finally{f.value=!1}}return(e,t)=>(l(),S(j,{title:"کد تأیید",subtitle:`کد ارسال‌شده به ${u.value}`},{default:i(()=>[c.value?(l(),x("p",H," حالت توسعه — کد: "+y(c.value),1)):V("",!0),a.value?(l(),x("p",J,y(a.value),1)):V("",!0),M("form",{class:"space-y-4",onSubmit:D(q,["prevent"])},[_(z,{id:"code",modelValue:p.value,"onUpdate:modelValue":t[0]||(t[0]=w=>p.value=w),label:"کد ۶ رقمی",type:"text",inputmode:"numeric",maxlength:"8",placeholder:"123456",autocomplete:"one-time-code",ltr:"",required:""},null,8,["modelValue"]),_(C,{type:"submit",loading:v.value},{default:i(()=>[...t[2]||(t[2]=[k("ورود",-1)])]),_:1},8,["loading"])],32),n.value>0?(l(),x("p",K," ارسال مجدد تا "+y(n.value)+" ثانیه ",1)):(l(),S(C,{key:3,variant:"ghost",class:"mt-2",loading:f.value,onClick:A},{default:i(()=>[...t[3]||(t[3]=[k(" ارسال مجدد کد ",-1)])]),_:1},8,["loading"])),_(C,{variant:"ghost",class:"mt-2",onClick:t[1]||(t[1]=w=>E(o).push({name:m.value?"admin-login":"login"}))},{default:i(()=>[...t[4]||(t[4]=[k(" تغییر شماره موبایل ",-1)])]),_:1})]),_:1},8,["subtitle"]))}});export{W as default};