{"version":3,"sources":["webpack:///./assets/javascripts/modules/components/WishlistComponent.js"],"names":["WishlistComponent","_classCallCheck","this","_this","_possibleConstructorReturn","__proto__","Object","getPrototypeOf","call","main","$","SELECTORS","remove","qtyWishlistTitle","wishlistCount","document","querySelector","wishlistCountMobile","Component","removing","html","_this2","Promise","resolve","reject","e","$elem","ajax","url","data","dataType","error","xhr","console","log","el","self","type","success","$emit","$customEvents","PRODUCT_EVENTS","removedfromwish","qtyNew","dataset","classList","add","text","_this3","$on","addtowish","payload","originalFocus","code","resp","addedtowish","updateWishlist","always","res","appendHtml","then","toString","substring","item","addClass","CLASSES","updateQtyWishlist","setTimeout","off","on","removefromwish","removeProduct","bindEvents"],"mappings":"qXAEqBA,cAkBnB,SAAAA,iGAAcC,CAAAC,KAAAF,GAAA,IAAAG,mKAAAC,CAAAF,MAAAF,EAAAK,WAAAC,OAAAC,eAAAP,IAAAQ,KAAAN,OAAA,OAGZC,EAAKM,KAAOC,EAAEP,EAAKQ,UAAUF,MAC7BN,EAAKS,OAASF,EAAEP,EAAKQ,UAAUC,QAC/BT,EAAKU,iBAAmBH,EAAEP,EAAKQ,UAAUE,kBACzCV,EAAKW,cAAgBC,SAASC,cAAcb,EAAKQ,UAAUG,eAC3DX,EAAKc,oBAAsBF,SAASC,cAAcb,EAAKQ,UAAUM,qBAPrDd,qUAlB+Be,6CAG3C,OACET,KAAM,eACNG,OAAQ,kBACRC,iBAAkB,uBAClBC,cAAe,wBACfG,oBAAqB,gEAKvB,OACEE,SAAU,sDAcHC,GAAM,IAAAC,EAAAnB,KACf,OAAO,IAAIoB,QAAQ,SAACC,EAASC,GAC3B,IACEH,EAAKZ,KAAKW,KAAKA,GACfG,IACA,MAAME,GACND,EAAOC,+CAMX,IACIC,EADOxB,KACMO,KAEjB,OAAOC,EAAEiB,MACPC,IAAMF,EAAMG,KAAK,QACjBC,SAAU,OACVC,MAAO,SAAUC,GACfC,QAAQC,IAAIF,4CAMJG,GACZ,IAAIC,EAAOlC,K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C,GAEzDvB,MAAO,SAASC,GACdC,QAAQC,IAAI,iCAKlBhC,KAAK+C,IAAI/C,KAAKsC,cAAcC,eAAeC,gBAAiB,SAACjB,GAC3DuB,EAAKQ,iBAAiBC,OAAO,SAAAC,GAC3BV,EAAKW,WAAWD,GAAKE,KAAK,SAAAF,GAExB,IAAItB,IAEAiB,EADQ3C,EAAEe,EAAE0B,SACCtB,KAAK,QAAQgC,WAAWC,UAAU,EAAG,IAClDC,EAAOrD,oBAAoB2C,EAApB,MAEXU,EAAKC,SAAS5B,EAAK6B,QAAQ9C,UAC3B6B,EAAKkB,oBAELC,WAAW,WAAYJ,EAAKnD,UAAY,WAM9CF,EAAE,QAAQ0D,IAAI,kBAAkBC,GAAG,iBAAkBjC,EAAKzB,UAAUC,OAAQ,WAC1EwB,EAAKG,MAAMH,EAAKI,cAAcC,eAAe6B,eAAgBpE,QAG/DA,KAAK+C,IAAI/C,KAAKsC,cAAcC,eAAe6B,eAAgB,SAAC7C,GAC1DuB,EAAKuB,cAAc9C,EAAE0B,4CAKvBjD,KAAKgC,IAAI,gBACThC,KAAKsE,sBApJYxE","file":"component-WishlistComponent.chunks.js","sourcesContent":["import Component from '../abstracts/Component';\n\nexport default class WishlistComponent extends Component {\n\n  get SELECTORS() {\n    return {\n      main: '.js-wishlist',\n      remove: '.js-remove-wish',\n      qtyWishlistTitle: '.wishlistCount-title',\n      wishlistCount: '[data-wishlist-count]',\n      wishlistCountMobile: '[data-wishlist-count-mobile]',\n    };\n  }\n\n  get CLASSES() {\n    return {\n      removing: 'removing',\n    };\n  }\n\n  constructor() {\n    super();\n\n    this.main = $(this.SELECTORS.main);\n    this.remove = $(this.SELECTORS.remove);\n    this.qtyWishlistTitle = $(this.SELECTORS.qtyWishlistTitle);\n    this.wishlistCount = document.querySelector(this.SELECTORS.wishlistCount);\n    this.wishlistCountMobile = document.querySelector(this.SELECTORS.wishlistCountMobile);\n  }\n\n  appendHtml(html) {\n    return new Promise((resolve, reject) => {\n      try {\n        this.main.html(html);\n        resolve();\n      } catch(e) {\n        reject(e);\n      }\n    });\n  }\n\n  updateWishlist() {\n    let self = this;\n    let $elem = self.main;\n\n    return $.ajax({\n      url:  $elem.data('href'),\n      dataType: \"html\",\n      error: function (xhr) {\n        console.log(xhr);\n      }\n    });\n  }\n\n\n  removeProduct(el) {\n    let self = this;\n    let $elem = $(el);\n    let url = $elem.data('href');\n\n    $.ajax({\n      url:  url,\n      dataType: \"json\",\n      type: 'POST',\n      success: function() {\n        self.$emit(self.$customEvents.PRODUCT_EVENTS.removedfromwish, el);\n      },\n      error: function(xhr) {\n        console.log(xhr);\n      }\n    });\n  }\n\n  updateQtyWishlist() {\n    let qtyNew = this.wishlistCount.dataset.wishlistCount - 1;\n\n    if(qtyNew == 0) {\n      this.wishlistCount.classList.remove('icon-wishlist-full');\n      this.wishlistCountMobile.classList.remove('icon-wishlist-full-mobile');\n      this.wishlistCount.classList.add('hidden');\n      this.wishlistCountMobile.classList.add('hidden');\n    }\n    this.wishlistCount.dataset.wishlistCount = qtyNew;\n    this.wishlistCountMobile.dataset.wishlistCountMobile = qtyNew;\n    if(this.qtyWishlistTitle != null || typeof this.qtyWishlistTitle !== 'undefined') {\n      this.qtyWishlistTitle.text(' ('+qtyNew+')');\n    }\n  }\n\n  bindEvents() {\n    let self = this;\n\n    this.$on(this.$customEvents.PRODUCT_EVENTS.addtowish, (e) => {\n      let $elem = $(e.payload);\n      let url = $elem.data('href');\n      this.originalFocus = e.payload;\n\n      $.ajax({\n        url:  url,\n        data: {\n          code: $elem.data('code')\n        },\n        dataType: \"html\",\n        success: function(resp) {\n          self.$emit(self.$customEvents.PRODUCT_EVENTS.addedtowish, $elem);\n\n          if(resp > 0) {\n            self.wishlistCount.classList.remove('hidden');\n            self.wishlistCountMobile.classList.remove('hidden');\n            self.wishlistCount.classList.add('icon-wishlist-full');\n            self.wishlistCountMobile.classList.add('icon-wishlist-full-mobile');\n          }\n          self.wishlistCount.dataset.wishlistCount = resp;\n          self.wishlistCountMobile.dataset.wishlistCountMobile = resp;\n        },\n        error: function(xhr) {\n          console.log('error in add to wishlist');\n        }\n      });\n    });\n\n    this.$on(this.$customEvents.PRODUCT_EVENTS.removedfromwish, (e) => {\n      this.updateWishlist().always(res => {\n        this.appendHtml(res).then(res => {\n\n          let self = this;\n          let $elem = $(e.payload);\n          let code = $elem.data('code').toString().substring(0, 13);\n          let item = $(`div[data-code=\"${code}\"]`);\n\n          item.addClass(self.CLASSES.removing);\n          this.updateQtyWishlist();\n\n          setTimeout(function(){ item.remove() }, 800);\n\n        });\n      });\n    });\n\n    $('body').off('click.wishlist').on('click.wishlist', self.SELECTORS.remove, function() {\n      self.$emit(self.$customEvents.PRODUCT_EVENTS.removefromwish, this)\n    });\n\n    this.$on(this.$customEvents.PRODUCT_EVENTS.removefromwish, (e) => {\n      this.removeProduct(e.payload);\n    });\n  }\n\n  render() {\n    this.log('Rendering...');\n    this.bindEvents();\n  }\n}\n"],"sourceRoot":""}