{"version":3,"file":"recentlyViewedHeaderCarousel-C5sMng-g.js","sources":["../../../app/javascript/modules/recentlyViewedHeaderCarousel.js"],"sourcesContent":["import Flickity from \"flickity\";\nimport Cookies from \"js-cookie\";\nimport { on } from \"../utils/listeners\";\n\nconst recentlyViewedHeaderCarousel = () => {\n  window.initializeRecentlyViewedHeaderCarousel = () => {\n    // Loop through and set up any product carousels\n    // (product page, landing page, the fold)\n    const carousels = document.querySelectorAll(\n      \".recently-viewed-products-header-carousel\"\n    );\n\n    carousels.forEach(carousel => {\n      const options = {\n        pageDots: true,\n        contain: true,\n        cellAlign: \"left\",\n        groupCells: true,\n        imagesLoaded: true,\n        cellSelector: \".mini-carousel-cell\",\n        watchCSS: true,\n        arrowShape:\n          \"M2.896 52.164A4.716 4.716 0 0 1 .6 48a4.716 4.716 0 0 1 2.292-4.164l41.82-42.464a4.572 4.572 0 0 1 6.536 0c1.8 1.832 1.8 4.804 0 6.636L11.86 48l39.388 39.992c1.8 1.832 1.8 4.8 0 6.636a4.572 4.572 0 0 1-6.536 0L2.896 52.16v.004z\",\n        // These events work around ios 11.3+ bug\n        // https://github.com/metafizzy/flickity/issues/740\n        on: {\n          dragStart() {\n            document.ontouchmove = e => {\n              e.preventDefault();\n            };\n          },\n\n          dragEnd() {\n            document.ontouchmove = () => {\n              return true;\n            };\n          }\n        }\n      };\n\n      const flkty = new Flickity(carousel, options);\n\n      const renderDots = () => {\n        document.querySelector(\".custom-page-dots\").innerHTML =\n          flkty.pageDots.dots\n            .map((el, i) => `<li class='dot' data-index='${i}'></li>`)\n            .join(\"\");\n\n        const dots = document.querySelectorAll(\".custom-page-dots li\");\n\n        if (dots.length > 0) {\n          dots[flkty.selectedIndex].classList.add(\"is-selected\");\n\n          dots.forEach(dot => {\n            dot.addEventListener(\"click\", e => {\n              flkty.select(e.target.dataset.index);\n            });\n          });\n        }\n      };\n\n      renderDots();\n      flkty.on(\"select\", renderDots);\n      flkty.on(\"resize\", () => {\n        const isSingleSlide = flkty.slides.length < 2;\n        carousel.classList.toggle(\"is-single-slide\", isSingleSlide);\n        renderDots();\n      });\n\n      // Trigger a resize event to\n      flkty.resize();\n    });\n  };\n\n  on(\"click\", \".js-dismiss-recently-viewed-header\", () => {\n    Cookies.set(\"dismissedRecentlyViewedHeader\", true, {\n      expires: 3650\n    });\n  });\n\n  window.initializeRecentlyViewedHeaderCarousel();\n};\n\nexport default recentlyViewedHeaderCarousel;\n"],"names":["recentlyViewedHeaderCarousel","carousel","options","e","flkty","Flickity","renderDots","el","i","dots","dot","isSingleSlide","on","Cookies"],"mappings":"uKAIK,MAACA,EAA+B,IAAM,CACzC,OAAO,uCAAyC,IAAM,CAGlC,SAAS,iBACzB,2CACD,EAES,QAAQC,GAAY,CAC5B,MAAMC,EAAU,CACd,SAAU,GACV,QAAS,GACT,UAAW,OACX,WAAY,GACZ,aAAc,GACd,aAAc,sBACd,SAAU,GACV,WACE,sOAGF,GAAI,CACF,WAAY,CACV,SAAS,YAAcC,GAAK,CAC1BA,EAAE,eAAgB,CACnB,CACF,EAED,SAAU,CACR,SAAS,YAAc,IACd,EAErB,CACA,CACO,EAEKC,EAAQ,IAAIC,EAASJ,EAAUC,CAAO,EAEtCI,EAAa,IAAM,CACvB,SAAS,cAAc,mBAAmB,EAAE,UAC1CF,EAAM,SAAS,KACZ,IAAI,CAACG,EAAIC,IAAM,+BAA+BA,CAAC,SAAS,EACxD,KAAK,EAAE,EAEZ,MAAMC,EAAO,SAAS,iBAAiB,sBAAsB,EAEzDA,EAAK,OAAS,IAChBA,EAAKL,EAAM,aAAa,EAAE,UAAU,IAAI,aAAa,EAErDK,EAAK,QAAQC,GAAO,CAClBA,EAAI,iBAAiB,QAASP,GAAK,CACjCC,EAAM,OAAOD,EAAE,OAAO,QAAQ,KAAK,CACjD,CAAa,CACb,CAAW,EAEJ,EAEDG,EAAY,EACZF,EAAM,GAAG,SAAUE,CAAU,EAC7BF,EAAM,GAAG,SAAU,IAAM,CACvB,MAAMO,EAAgBP,EAAM,OAAO,OAAS,EAC5CH,EAAS,UAAU,OAAO,kBAAmBU,CAAa,EAC1DL,EAAY,CACpB,CAAO,EAGDF,EAAM,OAAQ,CACpB,CAAK,CACF,EAEDQ,EAAG,QAAS,qCAAsC,IAAM,CACtDC,EAAQ,IAAI,gCAAiC,GAAM,CACjD,QAAS,IACf,CAAK,CACL,CAAG,EAED,OAAO,uCAAwC,CACjD"}