{"version":3,"sources":["archive/product/variant-selector-provider/fancybox-tiles-variant-selector-v1.ts"],"names":["html","repeat","TilesVariantSelectorBase","$","window","jQuery","pubsub","PubSub","FancyBoxTilesVariantSelectorV1","constructor","name","selectorContainerElement","product","variantTypeId","translations","showPricesInclVat","loadAdditionalInfo","super","this","template","variantSelectorData","variantUniqueId","variants","length","labels","select","variantTypeName","variant","id","image","thumbnailUrl","$mainContainer","getDataBeforeRender","self","result","variantType","sortVariants","get","changeSelection","uniqueId","relatedImages","forEach","variantName","normalize","variantNameRegex","RegExp","variantRelImageMatchRegExp","replace","relatedImage","find","relImg","imageName","title","test","processAfterRender","$variants","$previewImage","$previewName","$selectedVariantImage","$selectVariantBtn","on","evt","preventDefault","$variantToSelect","_setPreview","filter","removeClass","setSelectedInternal","fancybox","close","publish","container","isVariantAlreadySelected","hasClass","currentVariantValue","removeAttr","hide","isSelectedOptionAvailable","data","css","attr","show","isSelectedAvailable","trigger","VARIANT_CHANGED_EVENT","productId","setVariantSelectorLabelPrefix","getSelected","empty","addClass","append","text"],"mappings":"OAASA,IAAsB,KAAV,kBACZC,MAA0C,KAA5B,oCACdC,wBAAkE,KAAlC,mCAGzC,MAAMC,EAAIC,OAAOC,OACXC,OAASF,OAAOG,aAETC,uCAAuCN,yBAOhDO,YAAYC,EAAcC,EAAuCC,EAA+BC,EAAuBC,EAAmCC,EAA4BC,GAClLC,MAAMP,EAAMC,EAA0BC,EAASC,EAAeC,EAAcC,EAAmBC,CAAkB,EAG3GE,KAAAC,SAAW,IAAMnB;;+GAEgFkB,KAAKE,oBAAoBC;;;sBAGvE,EAA3CH,KAAKE,oBAAoBE,SAASC,OAAaL,KAAKE,oBAAoBI,OAAOC,OAAS,MAAOP,KAAKE,oBAAoBM;;;;oFAI1DR,KAAKE,oBAAoBC;;;kBAG3FpB,OAAOiB,KAAKE,oBAAoBE,SAAU,GAAsBtB;oHACkC2B,EAAQC;+FAC7BD,EAAQE,qCAAuCF,EAAQE,MAAMC,iBAAmB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,EAA2BT,EAAiBU,SAAS,UAAU,EAEnEvD,KAAKqC,UAAUW,YAAY,UAAU,EACrChD,KAAKsC,cAAcmB,WAAW,OAAO,EACrCzD,KAAKuC,aAAa+B,MAAK,EAElBhB,IACDT,EAAiB0B,SAAS,UAAU,EACpCvE,KAAKsC,cAAcwB,KAAK,QAASjB,EAAiBd,KAAK,mBAAmB,EAAE+B,KAAK,OAAO,CAAC,EACzF9D,KAAKuC,aAAaiC,OAAO3B,EAAiBd,KAAK,kBAAkB,EAAE0C,KAAI,CAAE,EAEjF,C,QAvISnF,8B","file":"fancybox-tiles-variant-selector-v1.js","sourcesContent":["import { html } from 'lit-html';\nimport { repeat } from 'lit-html/directives/repeat';\nimport { TilesVariantSelectorBase } from \"./tiles-variant-selector-base.js\";\nimport { IProductWithVariants, IVariant } from './variant-selector-base.js';\n\nconst $ = window.jQuery;\nconst pubsub = window.PubSub;\n\nexport class FancyBoxTilesVariantSelectorV1 extends TilesVariantSelectorBase {\n private $mainContainer: any;\n private $previewImage: any;\n private $previewName: any;\n private $selectedVariantImage: any;\n private $selectVariantBtn: any;\n\n constructor(name: string, selectorContainerElement: HTMLElement, product: IProductWithVariants, variantTypeId: number, translations: Map, showPricesInclVat: boolean, loadAdditionalInfo: boolean) {\n super(name, selectorContainerElement, product, variantTypeId, translations, showPricesInclVat, loadAdditionalInfo);\n this.$mainContainer = $(selectorContainerElement);\n }\n protected template = () => html`\n
\n \n
\n
\n
\n
\n ${repeat(this.variantSelectorData.variants, (variant:IVariant) => html`\n `\n )}\n
\n
\n
\n
\n
\n \n
\n
\n
\n
`;\n\n protected getDataBeforeRender(): any {\n const self = this;\n \n const result = {\n variantTypeName: this.variantType.name,\n variants: this.sortVariants(this.selectorContainerElement, this.variantType.variants, this.product),\n labels: { select: this.translations.get('selectVariantPrefix'), changeSelection: this.translations.get('changeSelectionVariantPrefix') },\n variantUniqueId: this.product.uniqueId + '_' + this.variantType.id\n };\n\n if (self.product.relatedImages && self.product.relatedImages.length > 0) {\n result.variants.forEach(function (variant: any) {\n const variantName = typeof (variant.name.normalize) === 'function' ? variant.name.normalize() : variant.name;\n const variantNameRegex = RegExp(self.product.variantRelImageMatchRegExp.replace('VARIANTNAME', variantName), 'gi');\n\n var relatedImage = self.product.relatedImages.find(function (relImg) {\n var imageName = typeof (relImg.title.normalize) === 'function' ? relImg.title.normalize() : relImg.title;\n return variantNameRegex.test(imageName);\n });\n\n if (relatedImage) {\n variant.image = relatedImage;\n }\n });\n }\n\n return result;\n }\n\n protected processAfterRender(): void {\n const self = this;\n\n self.$variants = self.$mainContainer.find('.js-variant');\n self.$previewImage = self.$mainContainer.find('.js-variant-preview-image');\n self.$previewName = self.$mainContainer.find('.js-variant-preview-name');\n self.$selectedVariantImage = self.$mainContainer.find('.js-selected-variant-image');\n self.$selectVariantBtn = self.$mainContainer.find('.js-select-variant-btn');\n\n self.$variants.on('click', function (evt) {\n evt.preventDefault();\n\n var $variantToSelect = $(this);\n self._setPreview($variantToSelect);\n });\n\n self.$selectVariantBtn.on('click', function (evt) {\n evt.preventDefault();\n\n var $variantToSelect = self.$variants.filter('.selected').removeClass('selected');\n self.setSelectedInternal($variantToSelect);\n\n $.fancybox.close();\n });\n\n pubsub.publish('variantprocessor.variant.render', { variant: self.variantSelectorData, container: self.$mainContainer });\n }\n\n protected setSelectedInternal($variantToSelect: any) {\n var isVariantAlreadySelected = $variantToSelect.hasClass('selected');\n this.$selectedVariantImage.removeAttr('style').hide();\n\n var currentVariantValue = null;\n if (!isVariantAlreadySelected) {\n currentVariantValue = $variantToSelect.data('variantid');\n if (currentVariantValue > 0 && $variantToSelect.find('.js-variant-image').css('background-image') !== 'none') {\n this.$selectedVariantImage.attr('style', $variantToSelect.find('.js-variant-image').attr('style')).show();\n }\n }\n\n this._setPreview($variantToSelect);\n\n var isSelectedOptionAvailable = this.isSelectedAvailable();\n this.$mainContainer.trigger(this.VARIANT_CHANGED_EVENT, [this.variantType, currentVariantValue || 0, isSelectedOptionAvailable, this.product.productId]);\n\n this.setVariantSelectorLabelPrefix(this.getSelected() > 0\n ? this.variantSelectorData.labels.changeSelection\n : this.variantSelectorData.labels.select);\n }\n\n private _setPreview($variantToSelect) {\n var isVariantAlreadySelected = $variantToSelect.hasClass('selected');\n\n this.$variants.removeClass('selected');\n this.$previewImage.removeAttr('style');\n this.$previewName.empty();\n\n if (!isVariantAlreadySelected) {\n $variantToSelect.addClass('selected');\n this.$previewImage.attr('style', $variantToSelect.find('.js-variant-image').attr('style'));\n this.$previewName.append($variantToSelect.find('.js-variant-name').text());\n }\n }\n}\n"]}