{"version":3,"file":"change_store_controller-BvRk9zS6.js","sources":["../../../app/javascript/controllers/change_store_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\";\n\n// Connects to data-controller=\"change-store\"\nexport default class extends Controller {\n static values = {\n name: String,\n value: String,\n expiration: Number,\n rootUrl: String\n };\n\n static targets = [\"storeLink\", \"selectedStore\", \"storeRootUrl\"];\n\n connect() {\n this.state = {\n hrefLangLookup: {}\n };\n\n this.createHrefLookUp();\n\n this.storeLinkTargets.forEach(link => {\n const matchingLocale = this.state.hrefLangLookup[link.dataset.locale];\n\n if (matchingLocale) {\n link.href = matchingLocale;\n }\n });\n }\n\n updateStoreUrl() {\n const selectedOption =\n this.selectedStoreTarget.options[this.selectedStoreTarget.selectedIndex];\n const matchingLocale =\n this.state.hrefLangLookup[selectedOption.getAttribute(\"locale\")];\n\n if (matchingLocale) {\n this.storeRootUrlTarget.value = matchingLocale;\n } else {\n this.storeRootUrlTarget.value = selectedOption.getAttribute(\"url\");\n }\n }\n\n createHrefLookUp() {\n const links = document.querySelectorAll('link[rel=\"alternate\"]');\n\n const linksArray = Array.from(links);\n\n const lookUpObject = linksArray.reduce((obj, link) => {\n obj[link.hreflang] = link.href;\n return obj;\n }, {});\n\n this.state.hrefLangLookup = lookUpObject;\n }\n}\n"],"names":["change_store_controller","Controller","link","matchingLocale","selectedOption","links","lookUpObject","obj","__publicField"],"mappings":"4VAGe,MAAKA,UAASC,CAAW,CAUtC,SAAU,CACR,KAAK,MAAQ,CACX,eAAgB,CAAA,CACjB,EAED,KAAK,iBAAkB,EAEvB,KAAK,iBAAiB,QAAQC,GAAQ,CACpC,MAAMC,EAAiB,KAAK,MAAM,eAAeD,EAAK,QAAQ,MAAM,EAEhEC,IACFD,EAAK,KAAOC,EAEpB,CAAK,CACL,CAEE,gBAAiB,CACf,MAAMC,EACJ,KAAK,oBAAoB,QAAQ,KAAK,oBAAoB,aAAa,EACnED,EACJ,KAAK,MAAM,eAAeC,EAAe,aAAa,QAAQ,CAAC,EAE7DD,EACF,KAAK,mBAAmB,MAAQA,EAEhC,KAAK,mBAAmB,MAAQC,EAAe,aAAa,KAAK,CAEvE,CAEE,kBAAmB,CACjB,MAAMC,EAAQ,SAAS,iBAAiB,uBAAuB,EAIzDC,EAFa,MAAM,KAAKD,CAAK,EAEH,OAAO,CAACE,EAAKL,KAC3CK,EAAIL,EAAK,QAAQ,EAAIA,EAAK,KACnBK,GACN,EAAE,EAEL,KAAK,MAAM,eAAiBD,CAChC,CACA,CAlDEE,EADkBR,EACX,SAAS,CACd,KAAM,OACN,MAAO,OACP,WAAY,OACZ,QAAS,MACV,GAEDQ,EARkBR,EAQX,UAAU,CAAC,YAAa,gBAAiB,cAAc"}