import{r as t,h as s}from"./p-1a7a8b00.js";import{a as e,S as i,_ as o,m as n,O as h,u as a,b as r,c as u,l as c,d as l,f as S}from"./p-a44cd541.js";import{d}from"./p-487241b6.js";import{s as p}from"./p-b4467cc2.js";const R=class{constructor(s){t(this,s),this.handleSubscriptions=()=>{this.storeUnsubscribe&&this.storeUnsubscribe(),p.mapDispatchToProps(this,{saveQuestionSet:e,updateErrors:i,removeActiveAnswerId:o,switchActiveQuestionSet:n}),this.storeUnsubscribe=p.mapStateToProps(this,this.mapStateToProps)},this.mapStateToProps=t=>({activeQuestionSet:h(t),config:a(t),questionSets:r(t),queue:t.queues.answers.queue,answersResourceState:u(t),applicationFormResourceState:c(t),questionPoolResourceState:l(t),questionSetResourceState:S(t)}),this.activeQuestionSet=void 0,this.config=void 0,this.buttonDisabled=!1,this.questionSets=[],this.queue=void 0,this.answersResourceState=void 0,this.applicationFormResourceState=void 0,this.questionPoolResourceState=void 0,this.questionSetResourceState=void 0,this.shouldHideForFirstQuestionSet=!1,this.useExternal=!1,this.canSave=!0,this.areResourcesReady=!0,this.isReady=!0,this.isFirstRun=!0,this.isFirstQnSet=!0,this.isDisabled=!1}resetState(){}componentWillLoad(){this.useExternal=!!customElements.get("bp-sdk-external-back-button-container"),customElements.whenDefined("bp-sdk-external-back-button-container").then((()=>{this.useExternal=!0})),this.handleSubscriptions(),this.onQuestionSetsChange(this.questionSets),this.onActiveQuestionSetChange(this.activeQuestionSet),this.onIsReady(this.isReady),this.onAnswersResourcesStateChange(this.answersResourceState),this.onApplicationFormResourceStateChange(this.applicationFormResourceState),this.onIsFirstRun(this.isFirstRun),this.onIsReady(this.isReady),this.onQuestionPoolResourcesStateChange(this.questionPoolResourceState),this.onQuestionSetResourcesStateChange(this.questionSetResourceState),this.onQueueChange(this.queue)}onIsReady(t){this.updateAreResourcesReady(this.isFirstRun,t)}updateAreResourcesReady(t,s){this.areResourcesReady=t||s}onAnswersResourcesStateChange(t){this.isReady=this.calculateResourcesReady({answers:t,applicationForm:this.applicationFormResourceState,questionPools:this.questionPoolResourceState,questionSets:this.questionSetResourceState})}onApplicationFormResourceStateChange(t){this.isFirstRun&&t===d.Loaded&&(this.isFirstRun=!1),this.isReady=this.calculateResourcesReady({answers:this.answersResourceState,applicationForm:t,questionPools:this.questionPoolResourceState,questionSets:this.questionSetResourceState})}onQuestionPoolResourcesStateChange(t){this.isReady=this.calculateResourcesReady({answers:this.answersResourceState,applicationForm:this.applicationFormResourceState,questionPools:t,questionSets:this.questionSetResourceState})}onQuestionSetResourcesStateChange(t){this.isReady=this.calculateResourcesReady({answers:this.answersResourceState,applicationForm:this.applicationFormResourceState,questionPools:this.questionPoolResourceState,questionSets:t})}calculateResourcesReady(t={}){return!(!t||t.applicationForm!==d.Loaded||t.answers===d.Loading||t.questionPools===d.Loading||t.questionSets===d.Loading)}onActiveQuestionSetChange(t){this.updateIsFirstQnSet(this.questionSets,t)}onIsFirstRun(t){this.updateAreResourcesReady(t,this.isReady)}onQuestionSetsChange(t){this.updateIsFirstQnSet(t,this.activeQuestionSet)}updateIsFirstQnSet(t,s){var e;this.isFirstQnSet=(null===(e=t[0])||void 0===e?void 0:e.question_set_id)===(null==s?void 0:s.question_set_id)}onQueueChange(t){this.canSave=!(null==t?void 0:t.length)}shouldRender(){return!this.isFirstQnSet||!this.shouldHideForFirstQuestionSet}render(){if(this.shouldRender())return[this.useExternal&&this.renderExternal(),!this.useExternal&&this.renderInternal()]}renderExternal(){return s("bp-sdk-external-back-button-container",{activeQuestionSet:this.activeQuestionSet,answersResourceState:this.answersResourceState,applicationFormResourceState:this.applicationFormResourceState,buttonDisabled:this.buttonDisabled,config:this.config,questionPoolResourceState:this.questionPoolResourceState,questionSetResourceState:this.questionSetResourceState,questionSets:this.questionSets,queue:this.queue})}handleNavigateBack(){this.switchActiveQuestionSet("backward")}renderInternal(){return s("bp-sdk-back-button",{buttonDisabled:this.buttonDisabled||!this.areResourcesReady||!this.canSave||this.isFirstQnSet,cssClasses:this.areResourcesReady&&this.canSave?"not-loading":"loading"})}static get watchers(){return{isReady:["onIsReady"],answersResourceState:["onAnswersResourcesStateChange"],applicationFormResourceState:["onApplicationFormResourceStateChange"],questionPoolResourceState:["onQuestionPoolResourcesStateChange"],questionSetResourceState:["onQuestionSetResourcesStateChange"],activeQuestionSet:["onActiveQuestionSetChange"],isFirstRun:["onIsFirstRun"],questionSets:["onQuestionSetsChange"],queue:["onQueueChange"]}}};R.style="";export{R as bp_sdk_back_button_container}