1import{_ as ie}from"./wJ3MJVaq.js";import le from"./B08wmbEg.js";import{_ as de}from"./DShznV_W.js";import{au as me,ae as ue,ap as ce,a$ as c,b0 as n,b1 as m,b2 as A,bc as pe,aw as w,u as p,av as fe,aZ as _e,r as V,b as he,c as y,aj as D,aX as f,b3 as ve}from"./BgyyoJFU.js";import{c as k,u as ge,e as be,r as I,s as ye}from"./CW2cRH-Y.js";import{u as we}from"./14NLtPOk.js";import{f as ke,u as $e,a as Ce,p as Ae,h as Ve,_ as xe}from"#entry";import{u as Be}from"./MbP0dzYY.js";import{u as Re}from"./DybYR4UZ.js";import{n as Ee}from"./BJU5byv3.js";import"./7pzNZKbI.js";const Me={class:"redeem container"},Pe={class:"redeem__container"},Se={key:0,class:"redeem__heading"},Te={class:"h1 redeem__title"},je={class:"redeem__text"},qe={class:"w100"},Fe={class:"payment-promocode__input-box"},Ue={key:0,class:"payment-input__hint"},Ne={key:0,class:"payment-promocode__success"},De={class:"payment-promocode__success-text"},Ie={class:"redeem__not-working"},Oe={class:"form__field custom-field"},Ze={class:"redeem__text"},Le={class:"flex flex-column gap-16 w100"},We=["href"],ze={class:"redeem__submit form__field submit-field"},He={key:0,class:"btn btn-stretch btn-primary btn-md"},Xe=["disabled"],Ge={key:2,class:"redeem__success-wrapper"},Je={key:3,class:"redeem__error-wrapper"},O=1500,Ke=me({__name:"redeem",setup(Qe){const{data:S}=ke(),{applyAuthToken:Z}=Be(),{$api:L}=ue(),{t:a,locale:W}=$e(),{openChat:T}=Re(),j=e=>new Promise(t=>setTimeout(t,e)),z=e=>{const t=e;return t.data?.data??t.data},H=e=>{const t=z(e),r=t?.errors;return Array.isArray(r)?r.join(", "):typeof r=="string"?r:r&&typeof r=="object"?Object.values(r).flatMap(u=>Array.isArray(u)?u:[u]).filter(Boolean).join(", "):t?.message},_=V("idle"),x=V(""),C=V(""),X=e=>{const t=H(e);C.value=t?`${a("common.labels.error")}: ${t}`:a("page.auth.error-occurred")},{isPartnerMode:B}=Ce();ce({title:()=>B.value?a("page.redeem.title"):a("page.redeem.seo.title"),meta:()=>B.value?[]:[{name:"description",content:a("page.redeem.subtitle")}],bodyAttrs:{class:"page-subscribe"}});const s=he({isBlock:!1,email:"",redemptionCode:"",oferta:!0}),G=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,J=k.regex(G),K=y(()=>({redemptionCode:{required:k.withMessage(a("common.validation.required"),I)},oferta:{mustBeTrue:k.withMessage(a("common.validation.required"),ye(!0))},email:S.value?{}:{required:k.withMessage(a("common.validation.required"),I),email:k.withMessage(a("common.validation.incorrect-email"),be),emailRegex:k.withMessage(a("common.validation.incorrect-email"),J)}})),v=ge(K,s),R=e=>{const t=v.value[e],r=t?.$error?t.$errors[0]?.$message:void 0;return r!==void 0?p(r):void 0},Q=y(()=>s.redemptionCode),Y=V(0),{isValidating:q,validationResult:E,error:F}=we(Q,Y,3),ee=y(()=>F.value||R("redemptionCode")),te=y(()=>R("email")),re=y(()=>R("oferta")),U=y(()=>!q.value&&!F.value&&E.value?.valid===!0),oe=/^(.+)\s+(\d+)\s+(day|days|week|weeks|month|months|year|years)$/i,ae=e=>{if(e===0)return"many";const t=e>10&&e<20,r=e%10===1;return!t&&r?"one":!t&&e%10>=2&&e%10<=4?"few":"many"},se=(e,t)=>{if(W.value==="ru"){const u=ae(e);return a(`page.redeem.durationForms.${t}.${u}`,{count:e})}return a(`page.redeem.durationForms.${t}.${e===1?"one":"other"}`,{count:e})},N=y(()=>{const e=E.value;if(!e?.valid)return"";const{subscription:t,amount:r,type:u}=e;if(t==null&&r!==0&&u===2)return a("page.redeem.reward.balance",{amount:r});const i=typeof t=="string"?t.trim():"";if(!i)return"";const o=i.match(oe);if(!o)return i;const h=o[1],b=o[2],g=o[3];if(!h||!b||!g)return i;const M=Number(b),l=g.toLowerCase();let d=null;if(l==="day"||l==="days"?d="day":l==="week"||l==="weeks"?d="week":l==="month"||l==="months"?d="month":(l==="year"||l==="years")&&(d="year"),!d)return i;const P=se(M,d);if(h.startsWith("ÐÑенда ")){const $=h.replace(/^ÐÑенда\s+/,"");return a("page.redeem.reward.rental",{name:$,duration:P})}if(h.startsWith("ÐкÑиваÑÐ¸Ñ ")){const $=h.replace(/^ÐкÑиваÑиÑ\s+/,"");return a("page.redeem.reward.activation",{name:$,duration:P})}if(/^(Basic|Premium)\b/i.test(h)){const $=h.trim();return a("page.redeem.reward.subscription",{plan:$,duration:P})}return i});async function ne(){if(!U.value||(_.value="idle",x.value="",C.value="",!await v.value.$validate()))return;s.isBlock=!0;const{redemptionCode:t,email:r,oferta:u}=s;try{const i=await L("/api/payment/redeem",{method:"POST",body:{redemption_code:t,email:r||void 0,oferta:u}}),{data:o}=i;if(o.user_registered&&o.token&&await Z(o.token),x.value=a("page.redeem.text.success-message"),_.value="success",await j(O),o.url){o.url==="/"?await Ee(o.url):await D(o.url,{external:!0});return}v.value.$reset(),s.email="",s.redemptionCode="",s.oferta=!0,_.value="idle"}catch(i){const{status:o,code:h,errors:b}=Ae(i);if(h===401){const d=Ve()({path:"/auth/login",query:{reason:"email-exists",email:s.email}});await D(d?.fullPath??`/auth/login?reason=email-exists&email=${encodeURIComponent(s.email)}`);return}const g=b&&typeof b=="object"&&!Array.isArray(b)?b:void 0,M=!!(o===422&&g&&Object.keys(g).length>0);o===422&&g&&Object.keys(g).forEach(l=>{if(v.value[l]){const d=g[l];v.value[l].$setCustomError(Array.isArray(d)?d[0]:d)}}),M?(_.value="idle",C.value=""):(X(i),_.value="error",await j(O),_.value="idle")}finally{s.isBlock=!1}}return(e,t)=>{const r=ie,u=le,i=de;return f(),c("section",Me,[n("div",Pe,[_.value==="idle"?(f(),c("hgroup",Se,[n("h1",Te,m(e.$t("page.redeem.title")),1),n("p",je,m(e.$t("page.redeem.subtitle")),1)])):A("",!0),_.value==="idle"?(f(),c("form",{key:1,class:"form redeem__form",onSubmit:pe(ne,["prevent"])},[n("div",qe,[n("div",Fe,[w(r,{modelValue:s.redemptionCode,"onUpdate:modelValue":t[0]||(t[0]=o=>s.redemptionCode=o),type:"text","html-for":"redemption-code",error:ee.value,stretch:"",label:e.$t("page.redeem.labels.code"),placeholder:e.$t("page.redeem.placeholders.code"),onBlur:p(v).redemptionCode.$touch},null,8,["modelValue","error","label","placeholder","onBlur"]),p(q)?(f(),c("span",Ue,m(e.$t("page.subscription.form.labels.checking-coupon")),1)):A("",!0)]),p(E)?.valid&&N.value?(f(),c("div",Ne,[n("span",De,m(N.value),1)])):A("",!0)]),n("div",Ie,[n("span",null,m(e.$t("page.redeem.text.code-not-working")),1),n("button",{type:"button",class:"redeem__support-button",onClick:t[1]||(t[1]=(...o)=>p(T)&&p(T)(...o))},m(e.$t("page.redeem.text.write-to-support")),1)]),p(S)?A("",!0):(f(),c(fe,{key:0},[n("div",Oe,[n("p",Ze,[n("span",null,m(e.$t("page.redeem.text.unauth-email")),1)])]),w(r,{modelValue:s.email,"onUpdate:modelValue":t[2]||(t[2]=o=>s.email=o),type:"email",label:e.$t("page.redeem.labels.email"),placeholder:e.$t("page.redeem.placeholders.email"),error:te.value,"html-for":"redeem-email",stretch:"",onBlur:p(v).email.$touch},null,8,["modelValue","label","placeholder","error","onBlur"])],64)),n("div",Le,[w(r,{modelValue:s.oferta,"onUpdate:modelValue":[t[3]||(t[3]=o=>s.oferta=o),p(v).oferta.$touch],type:"checkbox","html-for":"redeem-oferta",error:re.value},{default:_e(()=>[ve(m(e.$t("page.subscription.form.labels.oferta-text"))+" ",1),n("a",{class:"red-link",href:p(B)?"/docs/partner/oferta.pdf":"/docs/oferta.pdf",target:"_blank"},m(e.$t("page.subscription.form.labels.oferta-link")),9,We)]),_:1},8,["modelValue","error","onUpdate:modelValue"])]),n("div",ze,[s.isBlock?(f(),c("div",He,[w(u,{size:"25px","stroke-width":8})])):(f(),c("button",{key:1,class:"btn btn-stretch btn-primary btn-md",type:"submit",disabled:!U.value},m(e.$t("page.redeem.button")),9,Xe))])],32)):_.value==="success"?(f(),c("div",Ge,[w(i,{name:"check-outline"}),n("h2",null,m(x.value),1)])):(f(),c("div",Je,[w(i,{name:"close-outline"}),n("h2",null,m(C.value),1)]))])])}}}),mt=xe(Ke,[["__scopeId","data-v-0b71a9af"]]);export{mt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.