{ "version": 3, "sources": ["../../../Vettvangur.Frontend/src/scripts/components/product-page.ts"], "sourcesContent": ["import axios from 'axios'\nimport gsap from 'gsap'\nimport Swiper from 'swiper'\nimport { validateRecaptcha } from 'utility/recaptcha'\n\nconst productPage = {\n el: {\n slider: document.querySelector('.product-page__picture-slider'),\n thumbnails: document.querySelectorAll('.product-page__picture-thumbnail'),\n stockNotification: document.querySelector('.product-page__stock-notification'),\n },\n\n swiper: null,\n\n init(): void {\n if (this.el.slider) {\n this.initSlider()\n this.handleThumbnails()\n }\n\n if (this.el.stockNotification) {\n this.handleStockNotification(this.el.stockNotification)\n }\n },\n\n initSlider(): void {\n this.swiper = new Swiper(this.el.slider, {\n grabCursor: true,\n initialSlide: 0,\n loop: true,\n slidesPerView: 1,\n spaceBetween: 0,\n speed: 456,\n })\n },\n\n handleThumbnails(): void {\n this.el.thumbnails.forEach((thumbnail, index) => {\n thumbnail.addEventListener('click', (event) => {\n event.preventDefault()\n this.swiper.slideToLoop(index)\n })\n })\n\n this.swiper.on('slideChange', () => {\n this.el.thumbnails.forEach((thumbnail) => {\n thumbnail.classList.remove('product-page__picture-thumbnail--active')\n })\n\n this.el.thumbnails[this.swiper.realIndex].classList.add('product-page__picture-thumbnail--active')\n })\n },\n\n handleStockNotification(target): void {\n const el = {\n button: target.querySelector('.product-page__stock-notification-form .button'),\n error: target.querySelector('.input-group__error'),\n form: target.querySelector('.product-page__stock-notification-form'),\n input: target.querySelector('.input-group'),\n thankYou: target.querySelector('.product-page__stock-notification-thank-you'),\n }\n\n const method = {\n init(): void {\n el.form.addEventListener('submit', (event) => {\n validateRecaptcha(event, method.submitForm.bind(this))\n })\n },\n\n hideError(): void {\n el.input.classList.remove('input-group--error')\n el.error.innerexTt = ''\n document.removeEventListener('click', this.hideError.bind(this))\n },\n\n renderError(error): void {\n el.input.classList.add('input-group--error')\n el.error.innerText = error\n el.button.classList.remove('button--loading')\n el.button.removeAttribute('disabled')\n document.addEventListener('click', this.hideError.bind(this))\n },\n\n renderSuccess(): void {\n gsap\n .timeline()\n .to(el.form, {\n duration: 0.321,\n onComplete: () => {\n el.form.remove()\n },\n opacity: 0,\n })\n .set(el.thankYou, {\n display: 'block',\n opacity: 0,\n })\n .to(el.thankYou, {\n duration: 0.321,\n opacity: 1,\n })\n },\n\n async submitForm(event, token): Promise {\n event.preventDefault()\n\n const action = event.target.action\n const data = new FormData(event.target)\n\n data.append('g-recaptcha-response', token)\n\n el.button.setAttribute('disabled', 'true')\n el.button.classList.add('button--loading')\n\n await axios\n .post(action, data)\n .then((response) => {\n if (response.status === 200) {\n setTimeout(() => {\n this.renderSuccess()\n }, 567)\n }\n })\n .catch((error) => {\n console.log(`submitForm error: ${error}`)\n this.renderError(error)\n })\n },\n }\n\n method.init()\n },\n}\n\nexport default productPage\n"], "mappings": "2MAKA,IAAMA,EAAc,CAClB,GAAI,CACF,OAAQ,SAAS,cAA2B,+BAA+B,EAC3E,WAAY,SAAS,iBAA8B,kCAAkC,EACrF,kBAAmB,SAAS,cAA2B,mCAAmC,CAC5F,EAEA,OAAQ,KAER,MAAa,CACP,KAAK,GAAG,SACV,KAAK,WAAW,EAChB,KAAK,iBAAiB,GAGpB,KAAK,GAAG,mBACV,KAAK,wBAAwB,KAAK,GAAG,iBAAiB,CAE1D,EAEA,YAAmB,CACjB,KAAK,OAAS,IAAIC,EAAO,KAAK,GAAG,OAAQ,CACvC,WAAY,GACZ,aAAc,EACd,KAAM,GACN,cAAe,EACf,aAAc,EACd,MAAO,GACT,CAAC,CACH,EAEA,kBAAyB,CACvB,KAAK,GAAG,WAAW,QAAQ,CAACC,EAAWC,IAAU,CAC/CD,EAAU,iBAAiB,QAAUE,GAAU,CAC7CA,EAAM,eAAe,EACrB,KAAK,OAAO,YAAYD,CAAK,CAC/B,CAAC,CACH,CAAC,EAED,KAAK,OAAO,GAAG,cAAe,IAAM,CAClC,KAAK,GAAG,WAAW,QAASD,GAAc,CACxCA,EAAU,UAAU,OAAO,yCAAyC,CACtE,CAAC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,OAAO,aAAa,WAAY,MAAM,EACzCA,EAAG,OAAO,UAAU,IAAI,iBAAiB,EAEzC,MAAMQ,EACH,KAAKF,EAAQC,CAAI,EACjB,KAAME,GAAa,CACdA,EAAS,SAAW,KACtB,WAAW,IAAM,CACf,KAAK,cAAc,CACrB,EAAG,GAAG,CAEV,CAAC,EACA,MAAON,GAAU,CAChB,QAAQ,IAAI,qBAAqBA,CAAK,EAAE,EACxC,KAAK,YAAYA,CAAK,CACxB,CAAC,CACL,CACF,EAEAF,EAAO,KAAK,CACd,CACF,EAEOS,EAAQhB", "names": ["productPage", "Swiper", "thumbnail", "index", "event", "target", "el", "method", "validateRecaptcha", "error", "gsapWithCSS", "token", "action", "data", "axios_default", "response", "product_page_default"] }