{"version":3,"file":"switch_tabs_controller-CcPbmNDS.js","sources":["../../../frontend/common/controllers/switch_tabs_controller.js"],"sourcesContent":["import { Controller } from '@hotwired/stimulus'\n\nexport default class extends Controller {\n\n static targets = ['tab']\n static values = { focusedTabIndex: Number }\n\n markActive(e) {\n this.tabTargets.forEach(tab => {\n if (tab === e.currentTarget.parentElement) {\n tab.dataset.active = true\n tab.children[0].setAttribute('aria-selected', true)\n\n this.updateUrlTabParam(tab.dataset.tabId)\n\n } else {\n tab.dataset.active = false\n tab.children[0].setAttribute('aria-selected', false)\n }\n })\n }\n\n updateUrlTabParam(tabId) {\n if (tabId == null) return;\n\n let url = new URL(window.location.href)\n url.searchParams.set('tab', tabId);\n history.pushState({}, '', url.href)\n }\n\n nextTab(e) {\n // Make current tab not tabbable\n e.currentTarget.setAttribute('tabindex', -1)\n \n // Go to the first tab if overshooting\n if (this.focusedTabIndexValue >= this.tabTargets.length - 1) {\n this.focusedTabIndexValue = 0\n } else {\n this.focusedTabIndexValue++;\n }\n\n this.focusTab()\n }\n\n prevTab(e) {\n // Make current tab not tabbable\n e.currentTarget.setAttribute('tabindex', -1)\n\n // Go to the last tab if overshooting\n if (this.focusedTabIndexValue == 0) {\n this.focusedTabIndexValue = this.tabTargets.length - 1\n } else {\n this.focusedTabIndexValue--;\n }\n\n this.focusTab()\n }\n\n focusTab() {\n // Make new tab tabbable and focus it\n this.tabTargets[this.focusedTabIndexValue].children[0].setAttribute('tabindex', 0)\n this.tabTargets[this.focusedTabIndexValue].children[0].focus()\n }\n}\n"],"names":["SwitchTabsController","Controller","tab","tabId","url","__publicField"],"mappings":"0PACe,MAAKA,UAASC,CAAW,CAKtC,WAAW,EAAG,CACZ,KAAK,WAAW,QAAQC,GAAO,CACzBA,IAAQ,EAAE,cAAc,eAC1BA,EAAI,QAAQ,OAAS,GACrBA,EAAI,SAAS,CAAC,EAAE,aAAa,gBAAiB,EAAI,EAClD,KAAK,kBAAkBA,EAAI,QAAQ,KAAK,IAExCA,EAAI,QAAQ,OAAS,GACrBA,EAAI,SAAS,CAAC,EAAE,aAAa,gBAAiB,EAAK,EAE3D,CAAK,CACF,CACD,kBAAkBC,EAAO,CACvB,GAAIA,GAAS,KAAM,OACnB,IAAIC,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EACtCA,EAAI,aAAa,IAAI,MAAOD,CAAK,EACjC,QAAQ,UAAU,CAAE,EAAE,GAAIC,EAAI,IAAI,CACnC,CACD,QAAQ,EAAG,CAET,EAAE,cAAc,aAAa,WAAY,EAAE,EAGvC,KAAK,sBAAwB,KAAK,WAAW,OAAS,EACxD,KAAK,qBAAuB,EAE5B,KAAK,uBAEP,KAAK,SAAQ,CACd,CACD,QAAQ,EAAG,CAET,EAAE,cAAc,aAAa,WAAY,EAAE,EAGvC,KAAK,sBAAwB,EAC/B,KAAK,qBAAuB,KAAK,WAAW,OAAS,EAErD,KAAK,uBAEP,KAAK,SAAQ,CACd,CACD,UAAW,CAET,KAAK,WAAW,KAAK,oBAAoB,EAAE,SAAS,CAAC,EAAE,aAAa,WAAY,CAAC,EACjF,KAAK,WAAW,KAAK,oBAAoB,EAAE,SAAS,CAAC,EAAE,OACxD,CACH,CAnDEC,EADkBL,EACX,UAAU,CAAC,KAAK,GACvBK,EAFkBL,EAEX,SAAS,CACd,gBAAiB,MACrB"}