Loading
function(l,t,d){d.d(t,{Ni:()=>e.n,ET:()=>N,lv:()=>e.t,noOpFlowModuleMachine:()=>b}),d(209688);var i=d(588233);d(171251),d(886421),d(799201),d(401959);var c=d(64755),e=d(711177);function a(l){return l.flow?.flowId}function s(l,t){let d=l.homeScreen?.visible===!0,i=t||d,c=void 0!==l.steps?l.steps.length+ +!!i:void 0;if(d)return{key:"0:HOME",module:"HOME",payload:{moduleIndex:0,totalModules:c}};if(void 0===l.currentStep||""===l.currentStep)return;let e=void 0!==l.currentStepIndex?l.currentStepIndex+ +!!i:void 0;return{key:`${e??-1}:${l.currentStep}`,module:l.currentStep,payload:{moduleIndex:e,totalModules:c}}}let Z=(0,c.i)(({sendBack:l,input:t})=>{let{machine:d,config:i}=t;if(!d)return()=>{};let e=(0,c.s)(d,{input:{config:i}}),a=e.subscribe({complete:()=>{l({type:"MODULE_COMPLETE"})},error:t=>{l({type:"MODULE_ERROR",error:t})}});return e.start(),()=>{a.unsubscribe(),e.stop()}});var n=d(266561);let b=(0,c.t)({}).createMachine({id:"noOpFlowModule",initial:"finished",states:{finished:{type:"final"}}});function m(l,t){let d={...l?.configuration,ds:t?.ds};return l?.key==="ID"||l?.key==="TUTORIAL_ID"||l?.key==="SECOND_ID"||l?.key==="SELFIE"?{...d,ageAssurance:d.ageAssurance??t?.ageAssurance}:d}function o(l,t){return{flow:void 0,error:void 0,errorCode:void 0,steps:[],currentStepIndex:-1,currentStep:void 0,config:void 0,getFlow:l.getFlow,registeredModules:l.registeredModules,lazyRegisteredModules:l.lazyRegisteredModules,currentModuleMachine:void 0,getFinishStatus:l.getFinishStatus,enableHome:l.enableHome,finishStatus:void 0,isHomeContinueLoading:t}}(0,c.t)({types:{context:{},events:{},input:{}},actors:{fetchFlow:(0,c.a)(async({input:l,signal:t})=>l.getFlow(t))},actions:{resetContext:(0,c.r)(({context:l})=>({flow:void 0,error:void 0,steps:[],currentStepIndex:-1,currentStep:void 0,config:void 0,getFlow:l.getFlow})),setFlowData:(0,c.r)(({event:l})=>{let t=l.output;return{flow:t,steps:(t.flowModules??[]).map(l=>l.key),currentStepIndex:(t.flowModules??[]).length>0?0:-1,currentStep:t.flowModules?.[0]?.key,config:t.flowModules?.[0]?.configuration}}),setError:(0,c.r)(({event:l})=>({error:String(l.error)})),incrementStep:(0,c.r)(({context:l})=>{let t=l.currentStepIndex+1,d=l.flow?.flowModules?.[t];return{currentStepIndex:t,currentStep:d?.key,config:d?.configuration}}),decrementStep:(0,c.r)(({context:l})=>{let t=l.currentStepIndex-1,d=l.flow?.flowModules?.[t];return{currentStepIndex:t,currentStep:d?.key,config:d?.configuration}})},guards:{isLastStep:({context:l})=>l.currentStepIndex>=0&&l.currentStepIndex===l.steps.length-1,canGoNext:({context:l})=>l.currentStepIndex>=0&&l.currentStepIndex<l.steps.length-1,canGoPrev:({context:l})=>l.currentStepIndex>0}}).createMachine({id:"flow",initial:"idle",context:({input:l})=>({flow:void 0,error:void 0,steps:[],currentStepIndex:-1,currentStep:void 0,config:void 0,getFlow:l.getFlow}),states:{idle:{on:{LOAD:{target:"loading",actions:"resetContext"}}},loading:{invoke:{id:"fetchFlow",src:"fetchFlow",input:({context:l})=>({getFlow:l.getFlow}),onDone:{target:"ready",actions:"setFlowData"},onError:{target:"error",actions:"setError"}},on:{CANCEL:{target:"idle",actions:"resetContext"}}},ready:{on:{NEXT_STEP:[{target:"finished",guard:"isLastStep"},{target:"ready",guard:"canGoNext",actions:"incrementStep"}],PREV_STEP:{target:"ready",guard:"canGoPrev",actions:"decrementStep"},RESET:{target:"idle",actions:"resetContext"}}},finished:{on:{RESET:{target:"idle",actions:"resetContext"}}},error:{on:{RESET:{target:"idle",actions:"resetContext"}}}}});let u=new WeakSet,h={HOME_CONTINUE:{actions:"setHomeContinueLoading"}},W=(0,c.t)({types:{context:{},events:{},input:{}},actors:{fetchFlow:(0,c.a)(async({input:l,signal:t})=>l.getFlow(t)),notifyBackend:(0,c.a)(async({input:l,signal:t})=>await l.getFinishStatus(l.flowId,t)),runChildModule:Z,resolveCurrentModuleMachine:(0,c.a)(async({input:l})=>{if(!l.moduleKey)return;let t=l.modules[l.moduleKey];if(t)return t;let d=l.lazyModules[l.moduleKey];if(!d)return;let i=await d();return i&&"object"==typeof i&&"default"in i&&i.default?i.default:i})},actions:{resetContext:(0,c.r)(({context:l})=>o(l,!1)),resetContextForLoad:(0,c.r)(({context:l})=>o(l,l.isHomeContinueLoading)),setHomeContinueLoading:(0,c.r)({isHomeContinueLoading:!0}),clearHomeContinueLoading:(0,c.r)({isHomeContinueLoading:!1}),setFlowData:(0,c.r)(({event:l})=>{let t=l.output,d=t.flowModules??[],i=d[0],c=m(i,t);return{flow:t,steps:d.map(l=>l.key),currentStepIndex:d.length>0?0:-1,currentStep:i?.key,config:c,currentModuleMachine:void 0}}),setError:(0,c.r)(({event:l})=>{let t=l.error;return{error:t?.message??String(t),errorCode:t?.status}}),incrementStep:(0,c.r)(({context:l})=>{let t=l.currentStepIndex+1,d=l.flow?.flowModules?.[t],i=m(d,l.flow);return{currentStepIndex:t,currentStep:d?.key,config:i,currentModuleMachine:void 0}}),setCurrentModuleMachine:(0,c.r)(({event:l})=>({currentModuleMachine:l.output})),prefetchNextModule:({context:l})=>{!function(l){let t=l.steps[l.currentStepIndex+1];if(!t)return;let d=l.lazyRegisteredModules[t];!d||u.has(d)||(u.add(d),d().catch(()=>{u.delete(d)}))}(l)},setFinishStatus:(0,c.r)(({event:l})=>({finishStatus:l.output}))},guards:{isLastStep:({context:l})=>l.currentStepIndex>=0&&l.currentStepIndex===l.steps.length-1,canGoNext:({context:l})=>l.currentStepIndex>=0&&l.currentStepIndex<l.steps.length-1,shouldEnterHome:({context:l})=>(function(l){if(!0!==l.enableHome||l.flow?.disableLaunchScreen===!0||!0===l.isHomeContinueLoading)return!1;let t=+("REDIRECT_TO_MOBILE"===l.steps[0]);return l.currentStepIndex===t})(l),hasModule:({context:l,event:t})=>{if(!("output"in t))return!1;let d=t.output.flowModules?.[0]?.key;return!!d&&(null!=l.registeredModules[d]||null!=l.lazyRegisteredModules[d])},hasCurrentModuleMachine:({event:l})=>"output"in l&&null!=l.output}}).createMachine({id:"orchestratedFlow",initial:"idle",context:({input:l})=>o({getFlow:l.getFlow,registeredModules:l.modules??{},lazyRegisteredModules:l.lazyModules??{},getFinishStatus:l.getFinishStatus??n.t,enableHome:!0===l.enableHome},!1),states:{idle:{on:{LOAD:{target:"loading",actions:"resetContextForLoad"},...h}},loading:{invoke:{id:"fetchFlow",src:"fetchFlow",input:({context:l})=>({getFlow:l.getFlow}),onDone:[{target:"resolvingModule",guard:"hasModule",actions:"setFlowData"},{target:"error",actions:(0,c.r)({error:({event:l})=>{let t=l.output.flowModules?.[0]?.key;return t?`No registered module found for: ${t}`:"No registered module found: flow has no modules"}})}],onError:{target:"error",actions:"setError"}},on:{CANCEL:{target:"idle",actions:"resetContext"},...h}},resolvingModule:{invoke:{id:"resolveCurrentModuleMachine",src:"resolveCurrentModuleMachine",input:({context:l})=>({moduleKey:l.currentStep,modules:l.registeredModules,lazyModules:l.lazyRegisteredModules}),onDone:[{target:"home",guard:"shouldEnterHome",actions:["setCurrentModuleMachine"]},{target:"runningModule",guard:"hasCurrentModuleMachine",actions:["setCurrentModuleMachine","prefetchNextModule"]},{target:"error",actions:(0,c.r)(({context:l})=>({error:l.currentStep?`No registered module found for: ${l.currentStep}`:"No registered module found: flow has no modules"}))}],onError:{target:"error",actions:"setError"}},on:{RESET:{target:"idle",actions:"resetContext"},...h}},home:{on:{HOME_CONTINUE:{target:"runningModule",actions:["clearHomeContinueLoading","prefetchNextModule"]},RESET:{target:"idle",actions:"resetContext"}}},runningModule:{entry:"clearHomeContinueLoading",invoke:{id:"currentModule",src:"runChildModule",input:({context:l})=>{if(!l.currentStep)throw Error("No current step");return{machine:l.currentModuleMachine,config:l.config}},onDone:[{target:"completing",guard:"isLastStep"},{target:"resolvingModule",actions:"incrementStep"}],onError:{target:"error",actions:"setError"}},on:{MODULE_COMPLETE:[{target:"completing",guard:"isLastStep"},{target:"resolvingModule",actions:"incrementStep"}],MODULE_ERROR:{target:"error",actions:(0,c.r)(({event:l})=>({error:String(l.error)}))},COMPLETE_FLOW:{target:"completing"},RESET:{target:"idle",actions:"resetContext"}}},completing:{invoke:{id:"notifyBackend",src:"notifyBackend",input:({context:l})=>({getFinishStatus:l.getFinishStatus,flowId:l.flow?.flowId}),onDone:{target:"finished",actions:"setFinishStatus"},onError:{target:"error",actions:"setError"}},on:{RESET:{target:"idle",actions:"resetContext"}}},finished:{on:{RESET:{target:"idle",actions:"resetContext"}}},error:{entry:"clearHomeContinueLoading",on:{RESET:{target:"idle",actions:"resetContext"}}}}});function G(l,t){let{value:d,context:i}=l,c=function(l){let{value:t}=l;return"idle"===t?"idle":"loading"===t||"resolvingModule"===t||"completing"===t||"object"==typeof t?"loading":"finished"===t?"finished":"error"===t?"error":"ready"}(l),e=function(l,t,d,i){let{enableHome:c}=i,e=l.context.flow?.disableLaunchScreen===!0,a=!0===c&&!1===e,s="finished"===t||"error"===t,Z="completing"===l.value,n=+("REDIRECT_TO_MOBILE"===l.context.steps[0]),b=l.context.currentStepIndex===n,m="resolvingModule"===l.value&&a&&b,o=d||m,u=!1===s&&a&&!1===Z,h=!!u&&o,W="ready"===t&&!1===h?l.context.currentStep:void 0,G=u&&!1===l.context.isHomeContinueLoading&&o;return{homeScreen:{visible:h,isContinueLoading:!s&&l.context.isHomeContinueLoading},presentation:{isAwaitingReady:"idle"===t||"loading"===t,lazyModuleKey:W,shouldPrefetchHome:G}}}(l,c,"home"===d,t);if("idle"===c)return{status:"idle",homeScreen:e.homeScreen,presentation:e.presentation};if("loading"===c)return{status:"loading",homeScreen:e.homeScreen,presentation:e.presentation};if("finished"===c)return{status:"finished",flow:i.flow??{},finishStatus:i.finishStatus??{redirectionUrl:"",action:"none",scoreStatus:"UNKNOWN"},homeScreen:e.homeScreen,presentation:e.presentation};if("error"===c)return{status:"error",error:i.error??"Unknown error",errorCode:i.errorCode,homeScreen:e.homeScreen,presentation:e.presentation};let a="runningModule"===d?l.children.currentModule?.getSnapshot():null;return{status:"ready",flow:i.flow??{},steps:i.steps,currentStepIndex:i.currentStepIndex,currentStep:i.currentStep,config:i.config,moduleState:a??null,homeScreen:e.homeScreen,presentation:e.presentation}}function p(l,t,d){return new Promise((i,c)=>{let e=t(l.getSnapshot());if(d(e))return void i();if("error"===e.status)return void c(Error(e.error));if("finished"===e.status)return void c(Error("Flow finished"));let a=l.subscribe(()=>{let e=t(l.getSnapshot());d(e)?(a.unsubscribe(),i()):"error"===e.status?(a.unsubscribe(),c(Error(e.error))):"finished"===e.status&&(a.unsubscribe(),c(Error("Flow finished")))})})}function N(l){let t=(0,c.s)(W,{input:{getFlow:l.getFlow??e.t,modules:l.modules,lazyModules:l.lazyModules,getFinishStatus:l.getFinishStatus,enableHome:l.enableHome}}).start(),d=!0===l.enableHome,Z={enableHome:d};return function(l,t={}){let d,c,e={clear:(c=(0,i.b)()).clear,emit(l){c.emit({...l,timestamp:(0,i.x)()})},subscribe:c.subscribe},Z=!1,n=!1,b=!1,m=!1,o=!1,u=!1,h=new Set;function W(l){void 0===d||h.has(d.key)||(h.add(d.key),e.emit({type:"flow.module.completed",interviewId:t.interviewId,flowId:a(l),module:d.module,payload:d.payload}))}let G=l.subscribe(function(l){if("idle"===l.status)return void(Z=!1,n=!1,b=!1,m=!1,o=!1,u=!1,d=void 0,h=new Set);if("loading"===l.status&&!1===Z){Z=!0,e.emit({type:"flow.started",interviewId:t.interviewId});return}let i=l.flow;if("ready"===l.status&&void 0!==i){let c,Z={...l,flow:i},b=s(Z,u);if(void 0!==d&&void 0!==b&&d.key!==b.key&&W(Z),!1===n){let l;n=!0,e.emit({type:"flow.ready",interviewId:t.interviewId,flowId:a(Z),payload:(l={flow:Z.flow,steps:Z.steps??[],currentStepIndex:Z.currentStepIndex??-1},void 0===Z.currentStep?l:{...l,currentStep:Z.currentStep})})}Z.homeScreen?.visible===!0&&(u=!0),void 0===(c=s(Z,u))||c.key!==d?.key&&(d=c,e.emit({type:"flow.module.started",interviewId:t.interviewId,flowId:a(Z),module:c.module,payload:c.payload}));return}if("finished"===l.status&&!1===b){W(l);let d=l.finishStatus;b=!0,e.emit({type:"flow.completed",interviewId:t.interviewId,flowId:a(l),...void 0!==d?{payload:d}:{}});return}if("error"===l.status&&!1===m){m=!0,e.emit({type:"flow.error",interviewId:t.interviewId,flowId:a(l),error:l.error??"Unknown error"});return}"closed"===l.status&&!1===o&&(o=!0,e.emit({type:"flow.closed",interviewId:t.interviewId,flowId:a(l)}))}),p=l.stop.bind(l),N=!1;return Object.defineProperty(l,"subscribeFlowEvent",{configurable:!0,enumerable:!0,value:e.subscribe,writable:!0}),Object.defineProperty(l,"stop",{configurable:!0,enumerable:!0,value(){N||(N=!0,G(),p())},writable:!0}),l}((0,c.c)({actor:t,mapState:l=>G(l,Z),createApi:l=>(function({actor:l,getSnapshot:t,trackElementClicked:d},i){let{enableHome:c}=i;function e(){return G(t(),{enableHome:c})}return{load(){l.send({type:"LOAD"})},cancel(){d?.("cancel"),l.send({type:"CANCEL"})},reset(){l.send({type:"RESET"})},completeModule(){d?.("completeModule"),l.send({type:"MODULE_COMPLETE"})},completeFlow(){d?.("completeFlow"),l.send({type:"COMPLETE_FLOW"})},errorModule(t){l.send({type:"MODULE_ERROR",error:t})},send(t){l.send(t)},get canNext(){return function(){let l=t(),{currentStepIndex:d,steps:i}=l.context;return"runningModule"===l.value&&d>=0&&d<i.length-1}()},getModuleConfig:function(l){let d=t();if("runningModule"===d.value)return d.context.flow?.flowModules.find(t=>t.key===l)?.configuration},isModuleEnabled:function(l){let d=t();return"runningModule"===d.value&&!!d.context.flow?.flowModules.some(t=>t.key===l)},isAwaitingOrchestratorReady:()=>e().presentation.isAwaitingReady,waitForReady:async()=>p(l,l=>G(l,{enableHome:c}),l=>"ready"===l.status&&!1===l.presentation.isAwaitingReady),getLazyModuleKey:()=>e().presentation.lazyModuleKey,shouldRenderHomeScreen:()=>e().homeScreen.visible,async continueFromHome(){let t=e();if(t.homeScreen.visible){if("ready"===t.status){d?.("homeContinue"),l.send({type:"HOME_CONTINUE"});return}if(t.presentation.isAwaitingReady){d?.("homeContinue"),l.send({type:"HOME_CONTINUE"});try{await p(l,l=>G(l,{enableHome:c}),l=>"ready"===l.status&&!1===l.homeScreen.visible)}catch{return}}}}}})(l,{enableHome:d})}))}}