!function(){"use strict";class t{constructor(t){this.tablistNode=t,this.tabs=Array.from(this.tablistNode.querySelectorAll("[role=tab]")),this.tabpanels=[],0!==this.tabs.length&&(this.firstTab=null,this.lastTab=null,this.tabs.forEach((t=>{const e=document.getElementById(t.getAttribute("aria-controls"));t.tabIndex=-1,t.setAttribute("aria-selected","false"),this.tabpanels.push(e),t.addEventListener("keydown",this.onKeydown.bind(this)),t.addEventListener("click",this.onClick.bind(this)),this.firstTab||(this.firstTab=t),this.lastTab=t})),this.setSelectedTab(this.firstTab))}setSelectedTab(t){this.tabs.forEach(((e,a)=>{t===e?(e.setAttribute("aria-selected","true"),e.removeAttribute("tabindex"),this.tabpanels[a].hidden=!1):(e.setAttribute("aria-selected","false"),e.tabIndex=-1,this.tabpanels[a].hidden=!0)}))}moveFocusToTab(t){t.focus()}moveFocusToPreviousTab(t){const e=this.tabs.indexOf(t);this.moveFocusToTab(this.tabs[0===e?this.tabs.length-1:e-1])}moveFocusToNextTab(t){const e=this.tabs.indexOf(t);this.moveFocusToTab(this.tabs[e===this.tabs.length-1?0:e+1])}onKeydown(t){const e=t.currentTarget;let a=!1;switch(t.key){case"ArrowLeft":this.moveFocusToPreviousTab(e),a=!0;break;case"ArrowRight":this.moveFocusToNextTab(e),a=!0;break;case"Home":this.moveFocusToTab(this.firstTab),a=!0;break;case"End":this.moveFocusToTab(this.lastTab),a=!0}a&&(t.stopPropagation(),t.preventDefault())}onClick(t){this.setSelectedTab(t.currentTarget)}}learndash.global=learndash.global||{},learndash.global.ajaxurl=learndash.global.ajaxurl||"";class e{constructor(t,e){this.container=t,this.paginationSelector=e}init(){this.container.addEventListener("click",(t=>this.paginationClicked(t)))}paginationClicked(t){const e=t.target.closest("BUTTON");if(!e||!e.closest(this.paginationSelector))return;t.preventDefault();const a=e.closest(this.paginationSelector),s={next:e.getAttribute("data-next"),previous:e.getAttribute("data-previous"),nonce:a.getAttribute("data-nonce"),pagination_source:a.getAttribute("data-pagination-source"),parent_id:a.getAttribute("data-parent-id"),paged:parseInt(a.getAttribute("data-paged"),10)};s.next?s.paged+=1:s.previous&&(s.paged-=1),this.getPage(s,a)}getPage(t,e){const a={action:"ld30_modern_course_accordion_"+t.pagination_source+"_pagination",nonce:t.nonce,parent_id:t.parent_id,paged:t.paged},s=new URL(learndash.global.ajaxurl);Object.entries(a).forEach((([t,e])=>s.searchParams.set(t,e))),fetch(s,{method:"GET"}).then((a=>{a.json().then((a=>{const s=a?.data?.html,i=a?.data?.header,n=e.closest('[data-ld-pagination-target="'+t.pagination_source+'"]'),o=this.container.querySelector("[data-accordion-header]");this.replaceElement(s,n),this.replaceElement(i,o),this.container.dispatchEvent(new CustomEvent("ldAccordionPaginationComplete",{bubbles:!0,cancelable:!0,type:"course"}))}))})).catch((t=>{console.error("Pagination error:",t)}))}replaceElement(t,e){if(t.length<=0)return;const a=document.createElement("div");a.innerHTML=t,e.replaceWith(a.firstElementChild)}}window.addEventListener("DOMContentLoaded",(()=>{var a;a=".ld-tab-bar__tabs",document.querySelectorAll(a).forEach((e=>new t(e))),((t,a)=>{document.querySelectorAll(t).forEach((t=>{new e(t,a).init()}))})(".ld-accordion--course",".ld-accordion--course [data-ld-pagination]")}))}();