import{r as t,c as s,h as i,g as e}from"./p-1a7a8b00.js";import{z as n}from"./p-19cd3f24.js";const a=class{constructor(i){t(this,i),this.activeIdUpdate=s(this,"activeIdUpdate",7),this.updateQuestionSetId=t=>()=>{this.isNavigationEnabled&&(this.activeId=t,this.activeIdUpdate.emit(t))},this.onKeyDown=t=>{"ArrowUp"!==t.key&&"ArrowDown"!==t.key||t.preventDefault()},this.onKeyUp=t=>{var s;const i=+(null!==(s=this.el.querySelector(":focus").parentElement.getAttribute("aria-posinset"))&&void 0!==s?s:-1);let e=this.getPosition(i,t.key);null!=e&&this.el.querySelector(`[aria-posinset='${e}'] > button`).focus()},this.questionSets=[],this.isNavigationEnabled=!0,this.activeId=void 0,this.useExternal=!1}resetState(){}connectedCallback(){this.resetState()}componentWillLoad(){this.useExternal=!!customElements.get("bp-sdk-external-question-set-navigation"),customElements.whenDefined("bp-sdk-external-question-set-navigation").then((()=>{this.useExternal=!0}))}render(){return[this.useExternal&&this.renderExternal(),!this.useExternal&&this.renderInternal()]}renderExternal(){return i("bp-sdk-external-question-set-navigation",{activeId:this.activeId,isNavigationEnabled:this.isNavigationEnabled,questionSets:this.questionSets})}test(){}renderInternal(){return i("nav",{class:"bp-sdk-question-set-navigation__container","aria-label":"Question Sets",role:"navigation",onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp},i("ul",{tabindex:"0",role:"list",class:"bp-sdk-question-set-navigation__list"},this.questionSets.filter((t=>t.is_active&&t.answers.length>0)).map(((t,s)=>{var e;return i("li",{class:n("bp-sdk-question-set-navigation__list-item",{"bp-sdk-question-set-navigation__list-item--active":t.question_set_id===this.activeId||(null===(e=this.questionSets.find((t=>t.question_set_id===this.activeId)))||void 0===e?void 0:e.parentQuestionSetId)===t.id,"bp-sdk-question-set-navigation__list-item--completed":t.is_completed,"bp-sdk-question-set-navigation__list-item--parent":t.isParent,"bp-sdk-question-set-navigation__list-item--child":t.isChild}),"aria-setsize":this.questionSets.length,"aria-posinset":s+1},i("button",{type:"button",tabindex:"-1",class:"bp-sdk-question-set-navigation__list-item-button",disabled:!this.isNavigationEnabled,onClick:this.updateQuestionSetId(t.question_set_id)},i("span",{class:"bp-sdk-question-set-navigation__list-item-content"},t.question_set.name)))}))))}getPosition(t,s){let i;return"ArrowUp"===s?i=t>1&&t<=this.questionSets.length?t-1:this.questionSets.length:"ArrowDown"===s&&(i=t>-1&&t<this.questionSets.length?t+1:1),i}get el(){return e(this)}};a.style=".bp-sdk-question-set-navigation__list-item-content{user-select:none}";export{a as bp_sdk_question_set_navigation}