{"version":3,"file":"category-selection-bar-a1dd840f.js","sources":["../../../../src/scripts/modules/category-selection-bar.ts"],"sourcesContent":["import { Component } from '@verndale/core';\nimport { ExtendedWindowType } from '../helpers/global-types';\n\nclass CategorySelectionBar extends Component {\n  setupDefaults() {\n    this.dom = {\n      links: this.el.querySelectorAll('.category-selection-bar__link'),\n      dropdown: this.el.querySelector<HTMLSelectElement>('.field__select')\n    };\n  }\n\n  addListeners() {\n    (this.dom.dropdown as HTMLSelectElement).addEventListener(\n      'change',\n      this.handleDropdownChange.bind(this)\n    );\n\n    (this.dom.links as NodeListOf<HTMLAnchorElement>).forEach(link => {\n      link.addEventListener('click', this.handleClick.bind(this));\n    });\n  }\n\n  handleClick(event: Event) {\n    const { target } = event;\n\n    const anchor = (target as HTMLElement).classList.contains(\n      'category-selection-bar__link'\n    )\n      ? target\n      : (target as HTMLElement).closest('.category-selection-bar__link');\n\n    (anchor as HTMLAnchorElement).classList.add('active');\n\n    (this.dom.links as NodeListOf<HTMLAnchorElement>).forEach(link => {\n      if (link !== anchor) {\n        link.classList.remove('active');\n      }\n    });\n  }\n\n  handleDropdownChange(event: Event) {\n    const { value } = event.target as HTMLSelectElement;\n    (this.dom.links as NodeListOf<HTMLAnchorElement>).forEach(link => {\n      link.classList.remove('active');\n\n      if (link.href === value) {\n        const layer = link.dataset.layer;\n        link.classList.add('active');\n\n        if (layer) {\n          const global = window as ExtendedWindowType;\n          global.dataLayer?.push(JSON.parse(layer));\n        }\n      }\n    });\n\n    window.location.href = value;\n  }\n}\n\nexport default CategorySelectionBar;\n"],"names":["CategorySelectionBar","Component","link","event","target","anchor","value","layer","_a"],"mappings":"wEAGA,MAAMA,UAA6BC,CAAU,CAC3C,eAAgB,CACd,KAAK,IAAM,CACT,MAAO,KAAK,GAAG,iBAAiB,+BAA+B,EAC/D,SAAU,KAAK,GAAG,cAAiC,gBAAgB,CAAA,CAEvE,CAEA,cAAe,CACZ,KAAK,IAAI,SAA+B,iBACvC,SACA,KAAK,qBAAqB,KAAK,IAAI,CAAA,EAGpC,KAAK,IAAI,MAAwC,QAAgBC,GAAA,CAChEA,EAAK,iBAAiB,QAAS,KAAK,YAAY,KAAK,IAAI,CAAC,CAAA,CAC3D,CACH,CAEA,YAAYC,EAAc,CAClB,KAAA,CAAE,OAAAC,CAAW,EAAAD,EAEbE,EAAUD,EAAuB,UAAU,SAC/C,8BAEE,EAAAA,EACCA,EAAuB,QAAQ,+BAA+B,EAElEC,EAA6B,UAAU,IAAI,QAAQ,EAEnD,KAAK,IAAI,MAAwC,QAAgBH,GAAA,CAC5DA,IAASG,GACNH,EAAA,UAAU,OAAO,QAAQ,CAChC,CACD,CACH,CAEA,qBAAqBC,EAAc,CAC3B,KAAA,CAAE,MAAAG,CAAM,EAAIH,EAAM,OACvB,KAAK,IAAI,MAAwC,QAAgBD,GAAA,OAG5D,GAFCA,EAAA,UAAU,OAAO,QAAQ,EAE1BA,EAAK,OAASI,EAAO,CACjB,MAAAC,EAAQL,EAAK,QAAQ,MACtBA,EAAA,UAAU,IAAI,QAAQ,EAEvBK,KAEFC,EADe,OACR,YAAP,MAAAA,EAAkB,KAAK,KAAK,MAAMD,CAAK,IAE3C,CACD,EAED,OAAO,SAAS,KAAOD,CACzB,CACF"}