import{d as r}from"./p-fe259235.js";import{c as t}from"./p-4528e464.js";import{g as s}from"./p-6f78ea17.js";import{A as a}from"./p-bc71b894.js";import{m as e}from"./p-9bfc5cec.js";import{s as o,n as i,d as S}from"./p-a7724efa.js";import{g as n}from"./p-f4d2e8f3.js";import{g as m,c as E,s as R}from"./p-a53c9466.js";import{a as _}from"./p-1bab3be7.js";const p="INIT_CURRENT_USER_REQUEST",u="INIT_CURRENT_USER_SUCCESS",f="INIT_CURRENT_USER_ERROR",c="SIGN_IN_REQUEST",l="SIGN_IN_SUCCESS",T="SIGN_IN_ERROR",U="SIGN_UP_REQUEST",O="SIGN_UP_SUCCESS",g="SIGN_UP_ERROR",A="FORGOT_PASSWORD_REQUEST",y="FORGOT_PASSWORD_SUCCESS",N="FORGOT_PASSWORD_ERROR",h="FORGOT_PASSWORD_SUBMIT_REQUEST",P="FORGOT_PASSWORD_SUBMIT_SUCCESS",C="FORGOT_PASSWORD_SUBMIT_ERROR",G="LOGOUT_REQUEST",I="LOGOUT_SUCCESS",D="LOGOUT_ERROR",d="UPDATE_PASSWORD_REQUEST",b="UPDATE_PASSWORD_SUCCESS",w="UPDATE_PASSWORD_ERROR",x="GET_USER_TOKEN_REQUEST",j="GET_USER_TOKEN_SUCCESS",Q="GET_USER_TOKEN_ERROR";let W,F;const B=new o.Entity("userAuth",{},{idAttribute:"name"});class K{static isNotEmptyString(r){return null!=r&&""!==r&&"string"==typeof r}static isNotEmpty(r){return null!=r}static isEmptyArray(r){return r instanceof Array&&0===r.length}static isAppropriateNumber(r){return!(!this.isNotEmpty(r)||isNaN(r))}static getDateFromString(r){return K.dateArray[r]||(K.dateArray[r]=new Date(e(r).format())),K.dateArray[r]}static getHumanDateString(r){return e(r).utcOffset(r).format("MM/DD/YYYY hh:mm A")}static getTimestampByUtcOffset(r){return 1e3*e().utc(!1).add(r,"minutes").unix()}static isEmptyHtml(r){if(this.isNotEmptyString(r)){let t=r.replace(/<script[^>]*>(?:[^<]+|<(\/script>))+/g,"");return t=t.replace(/<[^>]*>/g,""),t=t.replace(/\[(.*?)\]/g,""),t=t.replace(/\[[a-zA-Z0-9]*]/g,""),t=t.replace(/\s\s/g,""),t=t.replace(/(?=lt;)(.*)(?=gt)/g,""),t=t.replace(/\&/g,""),t=t.replace(/amp/g,""),t=t.replace(/gt\;/g,""),t=t.replace(/lt\;/g,""),t=t.replace(/(\.+)/g,""),!this.isNotEmptyString(t)}return!0}static fixLinksInText(r){let t=r.match('<a href="(.*?)"[^>]*>');for(;null!=t;){const s=t.value[0].replace(/"/g,"'").replace("href=","target='_blank' href=").replace(/\\\'/g,"");t=(r=r.replace(t.value[0],s)).match('<a href="(.*?)"[^>]*>')}return r}static orderTShirtsBySize(r){const t=["xs","s","m","l","xl","xxl","xxxl"];return r.sort((r,s)=>t.indexOf(r.value)>t.indexOf(s.value)?1:-1)}}K.dateArray=[];const L=r("mvu:auth"),M=()=>{const r=n().getState();return Promise.resolve(r.isAuthenticated)},k=()=>{const r=n().getState(),t=S(r.userId,_,r.entities);return Promise.resolve(t)},Y=()=>Amplify.Auth.currentUserInfo(),v=()=>{const r=n();return(()=>{const r=n().getState(),t=a.injector();try{return t.tokenService.userAuthToken=r.content.userAuth.data.accessToken,t.tokenService.userAuthTokenExpirationDate=K.getDateFromString(r.content.userAuth.data.expiresAt),t.tokenService.userRefreshToken=r.content.userAuth.data.refreshToken,!t.tokenService.userAuthToken||new Date>t.tokenService.userAuthTokenExpirationDate?Promise.reject(!1):Promise.resolve(!0)}catch(s){return Promise.resolve(!1)}})().then(()=>m()).then(t=>r.getState().isAuthenticated?Promise.resolve(t):Promise.reject("no auth")).catch(()=>Promise.reject("no auth"))},z=r=>{const s=n();return s.dispatch(t("GET_USER_TOKEN_REQUEST")()),R(r.email,r.password,r.recaptcha).then(r=>{if(!r||!r.getUserToken)throw{errors:[{inputName:"form_error",errors:["Password incorrect, please try again"]}],formData:"",formPath:""};const e=r.getUserToken,o=i(e,{data:[B]}),S=a.injector();return S.tokenService.userAuthToken=e.accessToken,S.tokenService.userAuthTokenExpirationDate=K.getDateFromString(e.expiresAt),S.tokenService.userRefreshToken=e.refreshToken,s.dispatch((r=>t("GET_USER_TOKEN_SUCCESS")(r))(o)),r}).catch(r=>{if(s.dispatch((r=>t("GET_USER_TOKEN_ERROR")(r))(r)),"string"==typeof r)throw{code:"amplifyError",message:r,name:"amplifyError"};throw r})},H=r=>Amplify.Auth.signIn(r.email,r.password).then(()=>E(r.email)).then(r=>(Amplify.API.graphql(Amplify.graphqlOperation(s)).then(r=>r.data.getForumAuthToken.authtoken).then(r=>{F=r,W=document.createElement("img"),W.src="https://mvu.discussion.community/register/dologin?authtoken="+F,W.setAttribute("border","0"),W.setAttribute("width","1"),W.setAttribute("border","1"),W.setAttribute("alt",""),document.body.appendChild(W)}).catch(r=>{L("forum authenticate error",r)}),r)).catch(r=>{if("string"==typeof r)throw{code:"amplifyError",message:r,name:"amplifyError"};throw r}),q=r=>Amplify.Auth.signUp({username:r.email,password:r.password}).then(()=>null),Z=r=>Amplify.Auth.forgotPassword(r).then(()=>null),J=(r,t,s)=>Amplify.Auth.forgotPasswordSubmit(r,t,s).then(()=>null),V=()=>{const r=a.injector();return r.tokenService.userAuthToken=null,r.tokenService.userAuthTokenExpirationDate=null,r.tokenService.userRefreshToken=null,Promise.resolve(!0)},X=r=>{const t=Amplify.Auth;return t.currentAuthenticatedUser().then(s=>t.changePassword(s,r.currentPassword,r.newPassword))};export{M as A,k as B,Y as C,A as F,j as G,p as I,G as L,U as S,d as U,u as a,f as b,I as c,D as d,y as e,Z as f,N as g,O as h,v as i,g as j,c as k,V as l,H as m,l as n,T as o,z as p,b as q,w as r,q as s,h as t,X as u,J as v,P as w,C as x,x as y,Q as z}