!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.WtbWidget=e():t.WtbWidget=e()}("undefined"!=typeof self?self:this,(function(){return function(t){var e={};function i(o){if(e[o])return e[o].exports;var n=e[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,o){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(i.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(o,n,function(e){return t[e]}.bind(null,n));return o},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="./",i(i.s=4)}([function(t,e,i){var o=i(1),n=i(2);"string"==typeof(n=n.__esModule?n.default:n)&&(n=[[t.i,n,""]]);var d={insert:"head",singleton:!1};o(n,d);t.exports=n.locals||{}},function(t,e,i){"use strict";var o,n=function(){return void 0===o&&(o=Boolean(window&&document&&document.all&&!window.atob)),o},d=function(){var t={};return function(e){if(void 0===t[e]){var i=document.querySelector(e);if(window.HTMLIFrameElement&&i instanceof window.HTMLIFrameElement)try{i=i.contentDocument.head}catch(t){i=null}t[e]=i}return t[e]}}(),r=[];function s(t){for(var e=-1,i=0;it.stockInfo)}return i.offers}return[]}async getOfflineStores(){const t=`https://core.24wtb.com/api/v1/${this.defaultParams.brandId}/offline/product/by-area?${this.defaultParams.skuType}=${this.productId}&latitude=${this.centerLat}&longitude=${this.centerLng}&distance=${this.distance}`,e=await fetch(t),i=await e.json();return 200===i.status?i.stores:[]}async addOffLineStores(){const t=document.querySelector(".wtb-widget-stores-list");if(!t)throw new Error("Widget was didn't find");this.stores=await this.getOfflineStores();const e=document.querySelector(".wtb-widget-stores-count");e&&(e.innerHTML=this.stores.length);let i="";this.loadClusterer(),this.stores.length&&this.stores.forEach(t=>{i+=`\n
\n
\n
\n ${t.name}\n
\n
\n
\n ${t.address}\n
\n \n
\n
\n
\n `}),t.innerHTML=i,this.addListenerToStores()}addMapScript(){const t=document.createElement("script");t.src="https://mapgl.2gis.com/api/js/v1",t.async=!0,t.defer=!0,document.querySelector("body").appendChild(t);const e=document.createElement("script");e.src="https://unpkg.com/@2gis/mapgl-clusterer@^2/dist/clustering.js",e.async=!0,e.defer=!0,document.querySelector("body").appendChild(e)}mapInit(){this.map=new mapgl.Map("wtb-widget-map",{center:[this.centerLng,this.centerLat],zoom:13,maxZoom:18,minZoom:8,key:"bb3fed87-0279-4b2f-9342-7551bf1bb622"}),console.log(this.map.getLanguage());const t=this;localStorage.getItem("wtbOfflineLocationAccess")&&navigator.geolocation&&navigator.geolocation.getCurrentPosition(this.getUserLocation.bind(t),()=>{console.log("something went wrong")});new mapgl.Control(this.map,'',{position:"topLeft"}).getContainer().querySelector("button").addEventListener("click",t=>{this.map.setRotation(0).setPitch(0)}),this.map.on("move",()=>{const t=this.map.getRotation(),e=this.map.getPitch();document.querySelector(".wtb-compass").style.transform=`rotate(${t}deg)`,document.querySelector(".wtb-compass-pitch").style.transform=`translate(-50%,-50%) rotateX(${e}deg)`}),this.map.on("moveend",()=>{const t=this.map.getCenter();this.centerLat=t[1],this.centerLng=t[0],this.addOffLineStores()}),this.addOffLineStores()}mapDestroy(){const t=document.querySelector("#wtb-widget-map");t&&(t.innerHTML=""),this.map=null}loadClusterer(){const t=this.activeStoreId;this.markers=this.stores.map(e=>({coordinates:[e.longitude,e.latitude],type:"html",coordinates:[e.longitude,e.latitude],html:``,size:[30,30],id:e.id})),null!==this.clusterer&&(this.clusterer.destroy(),this.clusterer=null),this.markers.length&&(this.clusterer=new mapgl.Clusterer(this.map,{clusterStyle:t=>({type:"html",html:`
${t}
`})}),this.clusterer.load(this.markers),this.clusterer.on("click",t=>{if("marker"===t.target.type){const e=document.querySelector(`[data-id="${t.target.data.id}"]`);e&&e.click()}else if("cluster"===t.target.type){this.map.setCenter(t.lngLat);const e=this.map.getZoom();this.map.setZoom(e+1)}}))}async addShops(){const t=document.querySelector(".wtb-retailers-list");if(!t)throw new Error("Widget was didn't find");const e=await this.getOffers();let i="";e.length?e.forEach(t=>{const e=this.getCookie("cid")?"&CID="+this.getCookie("cid"):"";i+=`\n
\n \n \n
\n \n
\n
\n
`}):i='
ეს პროდუქტი არ არის შეთავაზებაში
',t.innerHTML=i}async addProductInfo(){const t=`https://api.samsung.com/model?key=56FE13336ABF4709AFCF7704B24D83F0&siteCode=ge&type=json&modelCode=${this.productId}&option=4`,e="https://searchapi.samsung.com/v6/front/b2c/product/card/detail/global?siteCode=ge&shopSiteCode=ru&onlyRequestSkuYN=Y&keySummaryYN=Y&modelList="+this.productId,i=await fetch(t),o=await i.json();if(200!==o.response.statusCode||"object"!=typeof o.response.resultData)return console.error(o.response.resultData),[];{const t=o.response.resultData.Products.Product.VisualContents[0].Media.find(t=>"XXLarge"===t.sizeType).url;document.querySelector(".wtb-product-img").innerHTML=``}const n=await fetch(e),d=await n.json();if(200!==d.response.statusCode||"object"!=typeof d.response.resultData)return console.error(d.response.resultData),[];{const t=d.response.resultData.productList[0].modelList[0].displayName;document.querySelector(".wtb-product-content-name").innerHTML=t}}locationAccessPopup(){if(!localStorage.getItem("wtbOfflineLocationAccess")){const t=document.createElement("div");t.innerHTML='\n
\n
\n
\n \n \n \n
\n
\n მაღაზიების მოძებნა შენს გარშემო. გამოყენებული იქნება მოწყობილობის ადგილმდებარეობა\n
\n
\n
გაუქმება
\n
დადასტურება
\n
\n
\n ',document.querySelector("body").appendChild(t),document.querySelector(".wtb-location-buttons-item--cancel, .wtb-location-close").addEventListener("click",()=>{localStorage.setItem("wtbOfflineLocationAccess",!1),t.innerHTML=""}),document.querySelector(".wtb-location-buttons-item--submit").addEventListener("click",()=>{localStorage.setItem("wtbOfflineLocationAccess",!0),t.innerHTML="";const e=this;localStorage.getItem("wtbOfflineLocationAccess")&&navigator.geolocation&&navigator.geolocation.getCurrentPosition(this.getUserLocation.bind(e),()=>{console.log("something went wrong")})})}}async renderWidget(){const t=document.createElement("div");t.className="wtb",t.innerHTML='\n
\n
\n
\n
\n
\n იპოვე მაღაზია\n
\n
\n
\n
\n
\n
\n
\n
\n
\n ონლაინ მაღაზია\n
\n
\n
\n
\n
\n
\n \n
\n \n \n \n
\n
\n
\n ',document.querySelector("body").appendChild(t)}addListeners(){const t=document.querySelectorAll(this.defaultParams.buttonSelector);t.length&&t.forEach(t=>{t.classList.contains("wtb-init")||(t.classList.add("wtb-init"),t.addEventListener("click",e=>{if(console.log("clicked"),e.preventDefault(),!t.getAttribute(this.defaultParams.attrType)||""===t.getAttribute(this.defaultParams.attrType).trim())throw new Error("Parameter with product sku was didn't find at this button");document.querySelector(".wtb").classList.add("wtb--active"),this.productId=t.getAttribute(this.defaultParams.attrType),this.modelName=t.getAttribute(this.defaultParams.modelNameAttrType),this.addProductInfo(),this.addShops()}))});const e=document.querySelector(".wtb-widget-close");e&&e.addEventListener("click",t=>{t.preventDefault(),this.closePopup()});const i=document.querySelector(".wtb-overlay");i&&i.addEventListener("click",t=>{t.target.classList.contains("wtb-widget")||t.target.closest(".wtb-widget")||this.closePopup()})}addListenerToStores(){const t=document.querySelectorAll(".wtb-widget-stores-list-item");t.length&&t.forEach(t=>{t.addEventListener("click",()=>{this.activeStoreId=t.dataset.id,this.map.setCenter([t.dataset.lng,t.dataset.lat]),this.map.setZoom(16),this.showStoreDetailInfo({title:t.querySelector(".wtb-widget-stores-list-item-title").innerHTML,address:t.dataset.address,phone:t.dataset.phone,email:t.dataset.email})})});const e=document.querySelector(".wtb-widget-store-info-close");e&&e.addEventListener("click",()=>{this.storeInfoReset();const t=document.querySelector(".wtb-widget-store-info--active");t&&t.classList.remove("wtb-widget-store-info--active"),this.activeStoreId=null,this.loadClusterer()})}storeInfoReset(){document.querySelector(".wtb-widget-store-info").classList.add("wtb-widget-store-info--active"),document.querySelector(".wtb-widget-store-info-title").innerHTML="",document.querySelector(".wtb-widget-store-info-contacts-item--mail .wtb-widget-store-info-contacts-item-text").innerHTML="-",document.querySelector(".wtb-widget-store-info-contacts-item--mail").style.display="none",document.querySelector(".wtb-widget-store-info-contacts-item--phone .wtb-widget-store-info-contacts-item-text").innerHTML="-",document.querySelector(".wtb-widget-store-info-contacts-item--phone").style.display="none",document.querySelector(".wtb-widget-store-info-contacts-item--address .wtb-widget-store-info-contacts-item-text").innerHTML="-",document.querySelector(".wtb-widget-store-info-contacts-item--address").style.display="none"}showStoreDetailInfo({title:t,distance:e,address:i,phone:o,email:n}){document.querySelector(".wtb-widget-store-info").classList.add("wtb-widget-store-info--active"),document.querySelector(".wtb-widget-store-info-title").innerHTML=t,document.querySelector(".wtb-widget-store-info-contacts-item--mail .wtb-widget-store-info-contacts-item-text").innerHTML=n,document.querySelector(".wtb-widget-store-info-contacts-item--mail"),document.querySelector(".wtb-widget-store-info-contacts-item--phone .wtb-widget-store-info-contacts-item-text").innerHTML=o,document.querySelector(".wtb-widget-store-info-contacts-item--address .wtb-widget-store-info-contacts-item-text").innerHTML=i,"-"!==o&&(document.querySelector(".wtb-widget-store-info-contacts-item--phone").style.display="block"),"-"!==i&&(document.querySelector(".wtb-widget-store-info-contacts-item--address").style.display="block"),"-"!==n&&(document.querySelector(".wtb-widget-store-info-contacts-item--mail").style.display="block")}closePopup(){document.querySelector(".wtb").classList.remove("wtb--active"),document.querySelector(".wtb-retailers-list").innerHTML="",document.querySelector(".wtb-product-content-name").innerHTML="",document.querySelector(".wtb-product-img").innerHTML="",document.querySelector(".wtb-widget-tabs-item--active").classList.remove("wtb-widget-tabs-item--active"),document.querySelector(".wtb-widget-tabs-content-item--active").classList.remove("wtb-widget-tabs-content-item--active"),document.querySelector(".wtb-widget-tabs-item:first-child").classList.add("wtb-widget-tabs-item--active"),document.querySelector(".wtb-widget-tabs-content-item:first-child").classList.add("wtb-widget-tabs-content-item--active");const t=document.querySelector(".wtb-widget-store-info--active");t&&t.classList.remove("wtb-widget-store-info--active"),this.mapDestroy()}getUserLocation(t){this.centerLng=t.coords.longitude,this.centerLat=t.coords.latitude,this.map.setCenter([this.centerLng,this.centerLat])}getCookie(t){var e=document.cookie.match(new RegExp("(?:^|; )"+t.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));return e?decodeURIComponent(e[1]):void 0}}}]).default}));