var _FlexpaLink=function(a){"use strict";var _=Object.defineProperty;var o=(a,r,I)=>r in a?_(a,r,{enumerable:!0,configurable:!0,writable:!0,value:I}):a[r]=I;var t=(a,r,I)=>o(a,typeof r!="symbol"?r+"":r,I);class r{constructor(){t(this,"iframe");t(this,"publishableKey");t(this,"user");t(this,"endpoint");t(this,"targetUrl");t(this,"strict",!0);t(this,"autoExit",!0);t(this,"skipExplainer",!1);t(this,"skipSyncing",!1);t(this,"requestedResources");t(this,"usage");t(this,"onSuccess");t(this,"onSyncing");t(this,"onExit");t(this,"onLoad");t(this,"onIframeCreated");t(this,"boundListenEvent");t(this,"_ial2Mode");t(this,"_chatbotMode");t(this,"redirectUrl");t(this,"lineOfBusiness");t(this,"hasStateParam",!1);t(this,"_experimentalResumeContext");this.boundListenEvent=this.listen.bind(this),this.checkForResumeParam()}decodeBase64Url(e){const i=e.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(e.length/4)*4,"=");return JSON.parse(atob(i))}checkForResumeParam(){if(typeof window>"u")return;const e=new URLSearchParams(window.location.search),i=e.get("resume_context");if(i){try{const n=this.decodeBase64Url(i);this.handleResumeContext(n)}catch{throw new Error("Invalid resume_context parameter")}e.delete("resume_context"),history.replaceState({},"",window.location.pathname+(e.toString()?"?"+e.toString():"")+window.location.hash)}}getStateParam(){return typeof window<"u"?new URLSearchParams(window.location.search).get("flexpaLinkState"):null}decodeStateParam(e){if(!e)return null;try{return JSON.parse(atob(e))}catch{return null}}listen(e){e.origin==="https://link.flexpa.com"&&this.handleLinkMessageEvent(e.data)}handleLinkMessageEvent(e){switch(e.type){case"SUCCESS":this.close(),this.onSuccess&&this.onSuccess(e.payload);break;case"SYNCING":this.onSyncing&&this.onSyncing(e.payload);break;case"LOADED":this.onLoad&&this.onLoad();break;case"CLOSED":this.close(),this.onExit&&this.onExit(e.payload);break}}create(e){if(Object.entries(e).forEach(([i,n])=>{this[i]=n}),this.targetUrl=this.buildTargetUrl(),e._experimentalResumeContext)if(typeof e._experimentalResumeContext=="string")try{const i=this.decodeBase64Url(e._experimentalResumeContext);this.handleResumeContext(i)}catch{throw new Error("Invalid resume_context parameter")}else this.handleResumeContext(e._experimentalResumeContext);if(this._experimentalResumeContext&&!this.iframe){this.open();return}}open(e){if(!this.publishableKey)throw new Error("You must call `FlexpaLink.create(config)` before calling `FlexpaLink.open()`");if(!this.iframe){this.iframe=document.createElement("iframe");const i=this.onIframeCreated?` position: relative; width: 100%; height: 100%; border: none; margin: 0; padding: 0; overflow: hidden;`:` position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; border: none; margin: 0; padding: 0; overflow: hidden; z-index: 999999;`;this.iframe.id="flexpa-link-iframe",this.iframe.style.cssText=i,this.iframe.allow="clipboard-write https://link.flexpa.com",this.iframe.src=this.buildTargetUrl(e==null?void 0:e.endpoint).toString(),this.iframe.title="Flexpa Link",this.onIframeCreated?this.onIframeCreated(this.iframe):document.body.appendChild(this.iframe),window.addEventListener("message",this.boundListenEvent)}}exit(){this.close(),this.onExit&&this.onExit()}close(){this.iframe&&(this.iframe.parentElement&&this.iframe.parentElement.removeChild(this.iframe),this.iframe=void 0,window.removeEventListener("message",this.boundListenEvent))}buildTargetUrl(e){if(!this.publishableKey)throw new Error("publishableKey required");if(!this.onSuccess&&!this._experimentalResumeContext)throw new Error("onSuccess required");const i=new URL("https://link.flexpa.com");if(i.searchParams.append("publishableKey",this.publishableKey),i.searchParams.append("openerUrl",window.location.href),i.searchParams.append("strict",this.strict?"true":"false"),i.searchParams.append("autoExit",this.autoExit?"true":"false"),i.searchParams.append("skipSyncing",this.skipSyncing?"true":"false"),i.searchParams.append("skipExplainer",this.skipExplainer?"true":"false"),this.user&&i.searchParams.append("user",JSON.stringify(this.user)),this.requestedResources&&i.searchParams.append("requestedResources",encodeURIComponent(this.requestedResources.join(","))),e?i.searchParams.append("endpoint",e):this.endpoint&&i.searchParams.append("endpoint",this.endpoint),this.usage&&i.searchParams.append("usage",this.usage),this._ial2Mode&&i.searchParams.append("_ial2Mode",this._ial2Mode?"true":"false"),this._chatbotMode&&i.searchParams.append("_chatbotMode",this._chatbotMode?"true":"false"),this.redirectUrl&&i.searchParams.append("redirectUrl",this.redirectUrl),this.lineOfBusiness&&["EMPLOYER","OFF_EXCHANGE","MEDICARE_ADV","ON_EXCHANGE","MEDICAID"].includes(this.lineOfBusiness)&&i.searchParams.append("lineOfBusiness",this.lineOfBusiness),this.onIframeCreated&&i.searchParams.append("displayMode","inline"),this._experimentalResumeContext&&typeof this._experimentalResumeContext!="string"){const{payload:n}=this._experimentalResumeContext;n!=null&&n.sessionToken&&i.searchParams.append("sessionToken",n.sessionToken),n!=null&&n.patientAuthorizationId&&i.searchParams.append("patientAuthorizationId",n.patientAuthorizationId)}return i}handleResumeContext(e){this._experimentalResumeContext=e}}var I=(s=>(s.MISSING_MFA_METHODS="MISSING_MFA_METHODS",s.INVALID_MFA_CODE="INVALID_MFA_CODE",s.INVALID_MFA_METHOD="INVALID_MFA_METHOD",s.INVALID_CREDENTIALS="INVALID_CREDENTIALS",s.INVALID_STEP="INVALID_STEP",s.INVALID_AUTH_STATE="INVALID_AUTH_STATE",s.DATA_FETCH_FAILED="DATA_FETCH_FAILED",s.INVALID_SESSION="INVALID_SESSION",s.INVALID_PATIENT_AUTHORIZATION="INVALID_PATIENT_AUTHORIZATION",s.INVALID_ENDPOINT="INVALID_ENDPOINT",s.RATE_LIMIT_EXCEEDED="RATE_LIMIT_EXCEEDED",s.UNKNOWN_ERROR="UNKNOWN_ERROR",s.CONNECTION_TIMEOUT="CONNECTION_TIMEOUT",s.CONNECTION_ERROR="CONNECTION_ERROR",s.INVALID_EVENT="INVALID_EVENT",s.INVALID_AUTH_HEADER="INVALID_AUTH_HEADER",s.INVALID_PATIENT_ID="INVALID_PATIENT_ID",s.TERMS_OF_USE_NOT_ACCEPTED="TERMS_OF_USE_NOT_ACCEPTED",s.SERVER_ERROR="SERVER_ERROR",s.UNSUPPORTED_PLAN_SELECTION="UNSUPPORTED_PLAN_SELECTION",s))(I||{});const l=new r;typeof window<"u"&&(window.FlexpaLink=l);const h=Object.values(I),E=["API_DOWN","MISSING_PAT","MISSING_PAT_ID","MISSING_PATIENT_ID","MISSING_ENDPOINT","MISSING_SMART_CONFIG","MISSING_APPLICATION","MISSING_SESSION_TOKEN","INVALID_ENDPOINT","INVALID_ENDPOINT_MODE","INVALID_STATE","INVALID_REQUEST","INVALID_SESSION_TOKEN","INVALID_PUBLISHABLE_KEY","INVALID_REDIRECT_URL","INVALID_USER","INVALID_USAGE","INVALID_TYPE","QUERY_REJECTED","QUERY_TIMEOUT","QUERY_INELIGIBLE","QUERY_UNKNOWN","QUERY_SERVER_ERROR","QUERY_INVALID_CONFIG","QUERY_INVALID_SCOPE","AUTHORIZATION_CODE_EXCHANGE","SYNC_FAILED",...h];return a.AuthenticatorErrorCodes=I,a.CredentialsFailureTypes=h,a.FailureTypes=E,a.default=l,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),a}({});