function fcn_cleanUpActions(){_$$(".story__actions > *").forEach((t=>{const e=window.getComputedStyle(t);"none"!==e.display&&"hidden"!==e.visibility||t.remove()}))}application.register("fictioneer-story",class extends Stimulus.Controller{static get targets(){return["tab","tabContent","commentsPlaceholder","commentsWrapper","commentsList"]}static values={id:Number};commentPage=1;connect(){window.FictioneerApp.Controllers.fictioneerStory=this,this.#t()}toggleChapterOrder(){const t=this.#e();t.order="asc"===t.order?"desc":"asc",this.#s(t),this.#t()}toggleChapterView(){const t=this.#e();t.view="list"===t.view?"grid":"list",this.#s(t),this.#t()}unfoldChapters(t){const e=t.currentTarget.closest(".chapter-group[data-folded]");e&&(e.dataset.folded="true"==e.dataset.folded?"false":"true")}toggleTab(t){const e=t.currentTarget;this.tabTargets.forEach((t=>{t.classList.remove("_current")})),this.tabContentTargets.forEach((e=>{e.dataset.tabName===t.params.tabName?e.classList.add("_current"):e.classList.remove("_current")})),e.classList.add("_current")}loadComments(t){this.hasIdValue&&this.hasCommentsListTarget&&(t.currentTarget.remove(),this.hasCommentsPlaceholderTarget&&this.commentsPlaceholderTarget.classList.remove("hidden"),FcnUtils.aGet({post_id:this.idValue,page:this.commentPage},"get_story_comments").then((t=>{this.hasCommentsPlaceholderTarget&&this.commentsPlaceholderTarget.remove(),t.success?(this.commentsListTarget.innerHTML+=t.data.html,this.commentPage++):t.data?.error&&this.commentsListTarget.appendChild(FcnUtils.buildErrorNotice(t.data.error))})).catch((t=>{this.hasCommentsPlaceholderTarget&&this.commentsPlaceholderTarget.remove(),this.commentsListTarget.appendChild(FcnUtils.buildErrorNotice(t))})))}startEpubDownload(t){t.preventDefault(),this.#a(t.currentTarget,0)}#e(){let t=FcnUtils.parseJSON(localStorage.getItem("fcnStorySettings"))??this.#i();return t.timestamp<1674770712849&&(t=this.#i(),t.timestamp=Date.now()),this.#s(t),t}#i(){return{view:"list",order:"asc",timestamp:1674770712849}}#s(t){"object"==typeof t&&localStorage.setItem("fcnStorySettings",JSON.stringify(t))}#t(){const t=this.#e();"object"==typeof t&&(_$$("[data-view]").forEach((e=>{e.dataset.view=t.view})),_$$("[data-order]").forEach((e=>{e.dataset.order=t.order})))}#a(t,e=0){!t.classList.contains("ajax-in-progress")&&this.hasIdValue&&(e>3?t.classList.remove("ajax-in-progress"):(t.classList.add("ajax-in-progress"),FcnUtils.aGet({action:"fictioneer_ajax_download_epub",story_id:this.idValue}).then((s=>{s.success?(window.location.href=t.href,setTimeout((()=>{t.classList.remove("ajax-in-progress")}),2e3)):setTimeout((()=>{fcn_startEpubDownload(t,e+1)}),2e3)})).catch((e=>{t.classList.remove("ajax-in-progress"),e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")}))))}}),document.addEventListener("fcnUserDataReady",(()=>{fcn_cleanUpActions()}));