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,IAAG,QAAS,4CAA4C,WACpD,MAAMqE,EAAanE,KAAKX,cAAcA,eACZU,EAAAA,EAAAA,IAAaoE,GAErBlF,SAAQmF,GAAMA,EAAGpF,iBAAiB,MAAM,GAAGkB,UAAUC,OAAO,kBAC9EgE,EAAWnF,iBAAiB,MAAM,GAAGkB,UAAUmE,OAAO,eAC1D,IAEAtF,SAASuF,iBAAiB,WAAW,SAAUC,GAC1BxF,SAASC,iBAAiB,kCAElCC,SAAQuF,KACRA,EAAK7D,SAAS4D,EAAME,UAAWC,EAAAA,EAAAA,IAAUF,IAC1CA,EAAKtE,UAAUC,OAAO,eAC1B,GAER,GACJ,C","sources":["webpack://goshop/./src/js/modules/product-detail/option-chooser.js"],"sourcesContent":["import { on } from 'delegated-events';\n\nimport { bannersReload } from './banners-product-card';\nimport { findSiblings, isVisible, showLoader, hideLoader, conditionalContentSet } from '../utils/utils';\n\nexport default function () {\n function refreshTerms() {\n document.querySelectorAll('.detail-options dd').forEach(dd => {\n const item = dd.querySelector('li.selected');\n\n if (item) {\n item.parentElement.previousElementSibling.innerHTML = item.textContent;\n }\n });\n }\n\n function priceFormatter(value) {\n\n if (value)\n return value.toFixed(2).toString().replace('.', ',');\n return value;\n }\n\n function gatherAndSend(caller) {\n\n showLoader();\n\n const selectedFeatureArray = [];\n const scope = caller.closest('[data-scope=\"addcart\"]');\n\n scope.querySelectorAll('dd ul').forEach(ul => {\n ul.querySelectorAll('li').forEach(li => {\n if (li.classList.contains('selected')) {\n selectedFeatureArray.push(li.getAttribute('data-dictid'));\n }\n });\n });\n\n fetch('/cartaction/FetchOptions', {\n method: 'POST',\n credentials: 'same-origin',\n body: JSON.stringify({\n request: {\n dicts: selectedFeatureArray,\n pid: scope.querySelector('[data-pid]').getAttribute('data-pid')\n }\n }),\n headers: {\n 'Content-Type': 'application/json; charset=utf-8'\n }\n })\n .then(response => response.json())\n .then(data => {\n\n const optionItem = scope.querySelector('[data-optionid]');\n\n if (data.OptionId) {\n optionItem.setAttribute('data-optionid', data.OptionId);\n } else {\n optionItem.setAttribute('data-optionid', -1);\n }\n\n if (data.ProductVariantUrl) {\n window.history.pushState(null, null, data.ProductVariantUrl);\n }\n\n if (data.HtmlResponse) {\n scope.querySelector('[data-role=\"option-view\"]').innerHTML = data.HtmlResponse;\n }\n\n conditionalContentSet(document, '[data-role=\"sku\"]', data.SKU);\n conditionalContentSet(document, '[data-role=\"ean\"]', data.EAN);\n\n if (data.Prices) {\n var pricesItem = data.Prices;\n\n conditionalContentSet(scope, '[data-role=\"product-price\"]', priceFormatter(pricesItem.PriceGross));\n\n const omnibusPrice = scope.querySelector('[data-role=\"omnibus-lowest-price\"]');\n if (omnibusPrice) {\n omnibusPrice.innerHTML = '';\n\n if (pricesItem.OldPriceGross) {\n omnibusPrice.innerHTML = pricesItem.OmnibusInfo;\n }\n }\n\n conditionalContentSet(scope, '[data-role=\"product-discount-percentage\"]', pricesItem.PercentDiscount);\n conditionalContentSet(scope, '.promo-text', pricesItem.PercentDiscount);\n conditionalContentSet(scope, '[data-role=\"product-oldprice\"]', priceFormatter(pricesItem.OldPriceGross));\n }\n\n if (data.ProductState) {\n const state = data.ProductState;\n const availName = scope.querySelector('[data-role=\"avail-name\"]');\n\n if (availName) {\n availName.innerHTML = state.Name;\n availName.style.color = state.HexHtmlColor;\n }\n\n conditionalContentSet(document, '[data-role=\"avail-desc\"]', state.Description);\n conditionalContentSet(document, '[data-role=\"avail-time\"]', state.ShippingTime);\n }\n\n if (data.Images) {\n bannersReload(data.Images);\n }\n\n const buyButton = scope.querySelector('.buy-button');\n\n if (data.CartEnabled) {\n scope.classList.remove('cart-disabled');\n buyButton.removeAttribute('disabled');\n } else {\n scope.classList.add('cart-disabled');\n buyButton.setAttribute('disabled', true);\n }\n\n refreshTerms();\n\n hideLoader();\n })\n .catch(error => {\n console.log(error);\n hideLoader();\n });\n }\n\n refreshTerms();\n\n // Wybór wariantu\n on('click', '.detail-options li:not(.selected)', function () {\n const liSiblings = findSiblings(this);\n\n liSiblings.forEach(li => li.classList.remove('selected'));\n this.classList.add('selected');\n\n gatherAndSend(this);\n });\n\n on('click', '.detail-options li.selected', function () {\n const list = document.querySelector('.detail-options dd.list-visible');\n\n if (list) {\n list.classList.remove('list-visible');\n }\n });\n\n // Pokazanie listy możliwych wariantów\n on('click', '.detail-options dd:not(.unactive) > span', function () {\n const optionList = this.parentElement.parentElement;\n const otherOptionsLists = findSiblings(optionList);\n\n otherOptionsLists.forEach(dl => dl.querySelectorAll('dd')[0].classList.remove('list-visible'));\n optionList.querySelectorAll('dd')[0].classList.toggle('list-visible');\n });\n\n document.addEventListener('mouseup', function (event) {\n const elements = document.querySelectorAll('.detail-options dd:not(.color)');\n\n elements.forEach(elem => {\n if (!elem.contains(event.target) && isVisible(elem)) {\n elem.classList.remove('list-visible');\n }\n });\n });\n}"],"names":["refreshTerms","document","querySelectorAll","forEach","dd","item","querySelector","parentElement","previousElementSibling","innerHTML","textContent","priceFormatter","value","toFixed","toString","replace","on","findSiblings","this","li","classList","remove","add","caller","showLoader","selectedFeatureArray","scope","closest","ul","contains","push","getAttribute","fetch","method","credentials","body","JSON","stringify","request","dicts","pid","headers","then","response","json","data","optionItem","OptionId","setAttribute","ProductVariantUrl","window","history","pushState","HtmlResponse","conditionalContentSet","SKU","EAN","Prices","pricesItem","PriceGross","omnibusPrice","OldPriceGross","OmnibusInfo","PercentDiscount","ProductState","state","availName","Name","style","color","HexHtmlColor","Description","ShippingTime","Images","bannersReload","buyButton","CartEnabled","removeAttribute","hideLoader","catch","error","console","log","gatherAndSend","list","optionList","dl","toggle","addEventListener","event","elem","target","isVisible"],"sourceRoot":""}