var __extends=this&&this.__extends||function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(Object.prototype.hasOwnProperty.call(b,p))d[p]=b[p]};return extendStatics(d,b)};return function(d,b){if(typeof b!=="function"&&b!==null)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}}();var eXpress;(function(eXpress){var services;(function(services){var ShowPriceUpsell;(function(ShowPriceUpsell){ShowPriceUpsell[ShowPriceUpsell["ExtraCost"]=0]="ExtraCost";ShowPriceUpsell[ShowPriceUpsell["TotalCost"]=1]="TotalCost";ShowPriceUpsell[ShowPriceUpsell["ExtraCostPerUnit"]=2]="ExtraCostPerUnit";ShowPriceUpsell[ShowPriceUpsell["TotalCostPerUnit"]=3]="TotalCostPerUnit"})(ShowPriceUpsell=services.ShowPriceUpsell||(services.ShowPriceUpsell={}));var PreviewOnPage;(function(PreviewOnPage){PreviewOnPage[PreviewOnPage["Packshot"]=0]="Packshot";PreviewOnPage[PreviewOnPage["PackshotOpenDSP"]=1]="PackshotOpenDSP";PreviewOnPage[PreviewOnPage["Preview2D"]=2]="Preview2D";PreviewOnPage[PreviewOnPage["Preview2DWithOverlay"]=3]="Preview2DWithOverlay";PreviewOnPage[PreviewOnPage["UpsellImage"]=6]="UpsellImage"})(PreviewOnPage=services.PreviewOnPage||(services.PreviewOnPage={}));var VariantSelectorOnPage;(function(VariantSelectorOnPage){VariantSelectorOnPage[VariantSelectorOnPage["None"]=0]="None";VariantSelectorOnPage[VariantSelectorOnPage["Icon"]=1]="Icon";VariantSelectorOnPage[VariantSelectorOnPage["DropDown"]=2]="DropDown"})(VariantSelectorOnPage=services.VariantSelectorOnPage||(services.VariantSelectorOnPage={}));var VariantSelectorValue;(function(VariantSelectorValue){VariantSelectorValue[VariantSelectorValue["None"]=0]="None";VariantSelectorValue[VariantSelectorValue["ShortNameProductCategory"]=1]="ShortNameProductCategory";VariantSelectorValue[VariantSelectorValue["ShortNameProduct"]=2]="ShortNameProduct";VariantSelectorValue[VariantSelectorValue["ShortNameProductVariant"]=3]="ShortNameProductVariant";VariantSelectorValue[VariantSelectorValue["NameProductCategory"]=4]="NameProductCategory";VariantSelectorValue[VariantSelectorValue["NameProduct"]=5]="NameProduct";VariantSelectorValue[VariantSelectorValue["NameProductVariant"]=6]="NameProductVariant";VariantSelectorValue[VariantSelectorValue["DspNameWithFallback"]=7]="DspNameWithFallback"})(VariantSelectorValue=services.VariantSelectorValue||(services.VariantSelectorValue={}));var ContentService=function(_super){__extends(ContentService,_super);function ContentService(deps){var _this=_super.call(this,deps.apiHostUrl,"ContentService.svc/json/")||this;_this.language=deps.languageCode;_this.pointOfSaleId=deps.pointOfSaleId;_this.applicationId=deps.applicationId;return _this}ContentService.prototype.bulkEditorGetAllProductsAsync=function(pointOfSaleId,language,pcg,pvc){var args={pointOfSaleId:pointOfSaleId,language:language,pcg:pcg,pvc:pvc};return services.ServiceBase.getJSON(this.url+"BulkEditorGetAllProducts",args).then(function(res){return deserialization.BulkEditorGetAllProductsResultConvert(res.BulkEditorGetAllProductsResult)})};ContentService.prototype.getContentsAsync=function(keys,pointOfSaleId,language){return services.ServiceBase.postJSON(this.url+"GetContentList",{pointOfSaleId:pointOfSaleId,language:language,contentKeys:keys||[]}).then(function(res){return res.GetContentListResult})};ContentService.prototype.getIconsByNameAsync=function(){var keys=[];for(var _i=0;_i<arguments.length;_i++){keys[_i]=arguments[_i]}return services.ServiceBase.postJSON(this.url+"GetIconsByName",{pointOfSaleId:this.pointOfSaleId,language:this.language,contentKeys:keys||[]}).then(function(res){return res.GetIconsByNameResult})};ContentService.prototype.getContentAsync=function(key,pointOfSaleId,language){return services.ServiceBase.getJSON(this.url+"GetContent",{pointOfSaleId:pointOfSaleId,language:language,contentKey:key}).then(function(res){return res.GetContentResult})};ContentService.prototype.getProductOptionGroup=function(contentKey,productVariantCode){return services.ServiceBase.getJSON(this.url+"GetProductOptionGroup",{pointOfSaleId:this.pointOfSaleId,language:this.language,contentKey:this.patchContentKey("ProductOptionGroup",contentKey),productVariantCode:productVariantCode}).then(function(res){var optiongroup=eXpress.deserialization.productOptionGroupConvert(res.GetProductOptionGroupResult);if(!optiongroup)throw new Error("Coudn't get product optiongroup for "+contentKey);return optiongroup})};ContentService.prototype.getProductUpsell=function(contentKey,quantity,pdp,baseProductOptions){return services.ServiceBase.postJSON(this.url+"GetProductUpsell",{pointOfSaleId:this.pointOfSaleId,language:this.language,contentKey:this.patchContentKey("ProductUpsell",contentKey),quantity:quantity,currentPdp:pdp,baseProductOptions:baseProductOptions}).then(function(res){return eXpress.deserialization.productUpsellConvert(res.GetProductUpsellResult)})};ContentService.prototype.getProductUpsellItem=function(contentKey,sourcePvc){return services.ServiceBase.getJSON(this.url+"GetProductUpsellItem",{pointOfSaleId:this.pointOfSaleId,language:this.language,contentKey:this.patchContentKey("ProductUpsellItem",contentKey),sourcePvc:sourcePvc}).then(function(res){return eXpress.deserialization.productUpsellItemConvert(res.GetProductUpsellItemResult)})};ContentService.prototype.GetProductAdornerInfo=function(pvc,option){return services.ServiceBase.getJSON(this.url+"GetProductAdornerInfo",{productVariantCode:pvc,productOptionCode:option,pointOfSaleId:this.pointOfSaleId,language:this.language}).then(function(res){return eXpress.deserialization.productAdornerInfoConvert(res.GetProductAdornerInfoResult)})};ContentService.prototype.patchContentKey=function(prefix,key){if(!key||!prefix||key.indexOf(prefix)===0)return key;return prefix+"."+key};ContentService.prototype.GetProductCategoryReviews=function(productCategoryId,page,stars,reviewLanguage,theme){return services.ServiceBase.getJSON(this.url+"GetProductCategoryReviews",{productCategoryId:productCategoryId,pointOfSaleId:this.pointOfSaleId,language:this.language,page:page,stars:stars,reviewLanguage:reviewLanguage,theme:theme}).then(function(res){return eXpress.deserialization.productCategoryReviewsConvert(res.GetProductCategoryReviewsResult)})};return ContentService}(services.ServiceBase);services.ContentService=ContentService})(services=eXpress.services||(eXpress.services={}));var deserialization;(function(deserialization){function productOptionGroupConvert(productOptionGroup){if(!productOptionGroup)return undefined;return{key:productOptionGroup.key,deprecated:productOptionGroup.Deprecated,productOptions:productOptionGroup.ProductOptions.map(function(po){return productOptionInGroupConvert(po)})}}deserialization.productOptionGroupConvert=productOptionGroupConvert;function productOptionInGroupConvert(productOptionInGroup){return{isDefault:productOptionInGroup.DefaultProductOption,optionCode:productOptionInGroup.OptionCode}}deserialization.productOptionInGroupConvert=productOptionInGroupConvert;function productUpsellConvert(item){return{productCode:item.ProductCode,title:item.Title,description:item.Description,productUpsellItems:item.ProductUpsellItems.map(function(item){return productUpsellItemConvert(item)})}}deserialization.productUpsellConvert=productUpsellConvert;function productUpsellItemConvert(item){return{key:item.Key,title:item.Title||undefined,description:item.Description||undefined,shortTitle:item.ShortTitle||undefined,shortDescription:item.ShortDescription||undefined,showPrice:item.ShowPrice,previewOnPage:item.PreviewOnPage,upsellImage:item.UpsellImage,variantSelectorOnPage:item.VariantSelectorOnPage,variantSelectorValue:item.VariantSelectorValue,inShoppingBasketText:item.InShoppingBasketText,yesPleaseButtonText:item.YesPleaseButtonText,showUpsell:item.ShowUpsell,fallBackDesignGroup:item.FallBackDesignGroup,productVariantsNew:item.ProductVariantsNew.map(function(pv){return productUpsellItemProductVariantConvert(pv)}),photoSelectionUrl:item.PhotoSelectionUrl}}deserialization.productUpsellItemConvert=productUpsellItemConvert;function productUpsellItemProductVariantConvert(item){return{productVariantKey:item.ProductVariantKey,icon:item.Icon,iconColorCode:item.IconColorCode,iconOverlayColorCode:item.IconOverlayColorCode,defaultForupsell:item.DefaultForupsell,productOptionGroup:productOptionGroupConvert(item.ProductOptionGroup),preview2DOverlay:item.Preview2DOverlay,packShotUrl:item.PackShotUrl,productCategory:item.ProductCategory,variantSelectorValueText:item.VariantSelectorValueText}}deserialization.productUpsellItemProductVariantConvert=productUpsellItemProductVariantConvert;function productAdornerInfoConvert(info){var adornerInfo=info.map(function(i){return{key:i.Key,value:{imageFileName:i.Value.ImageFileName,imageHeight:i.Value.ImageHeight,imageUriRel:i.Value.ImageUriRel,imageWidth:i.Value.ImageWidth,isBackground:i.Value.IsBackground,optimizedJsonUriRel:i.Value.OptimizedJsonUriRel,projection:{height:i.Value.Projection.Height,left:i.Value.Projection.Left,top:i.Value.Projection.Top,width:i.Value.Projection.Width}}}});return adornerInfo}deserialization.productAdornerInfoConvert=productAdornerInfoConvert;function productCategoryReviewConvert(review){return{reviewDate:review.ReviewDate,comment:review.Comment,firstName:review.FirstName,lastName:review.LastName,score:review.Score,feedbackDate:review.FeedbackDate,feedback:review.Feedback,language:review.Language}}deserialization.productCategoryReviewConvert=productCategoryReviewConvert;function productCategoryReviewsConvert(object){return{productCategoryReviews:object.ProductCategoryReviews.map(function(r){return productCategoryReviewConvert(r)}),totalAmountOfReviews:object.TotalAmountOfReviews,starAmounts:object.StarAmounts}}deserialization.productCategoryReviewsConvert=productCategoryReviewsConvert})(deserialization=eXpress.deserialization||(eXpress.deserialization={}));var core;(function(core){var ContentManager=function(){function ContentManager(contentService,showLabels){if(showLabels===void 0){showLabels=false}this.xmlSerializer=new XMLSerializer;this.labels=[];this.icons=[];this.contentService=contentService;this.showLabels=showLabels}ContentManager.prototype.getIconsByNameAsync=function(iconNames){var _a;var _this=this;var filteredNames=iconNames.filter(function(item,index){return iconNames.indexOf(item)===index&&!_this.icons[item.toLowerCase()]});if(filteredNames.length>0){return(_a=this.contentService).getIconsByNameAsync.apply(_a,filteredNames).then(function(res){var promises=res.map(function(kvp){var deferred=$.Deferred();$.ajax(kvp.Value,{dataType:"xml"}).then(function(data){var document=data;if(document&&document.documentElement.nodeName.toLowerCase()==="svg"){var svgString=_this.xmlSerializer.serializeToString(document);deferred.resolve({Key:kvp.Key.toLowerCase(),Value:svgString})}else{deferred.resolve(undefined)}},function(jqXhr,status,error){if(window&&window.onerror)window.onerror("Icon not found for contentkey: ".concat(kvp.Key," , ").concat(status.indexOf("parser")!==-1?"not an icon":status));deferred.resolve(undefined)});return deferred.promise()});return eXpress.utils.whenAll(promises).then(function(svgs){_this.addSvgs.apply(_this,svgs.filter(function(svg){return!!svg}));return svgs})})}else return $.Deferred().resolve([]).promise()};ContentManager.prototype.getIconsAsync=function(urls){var _this=this;var missingUrls=[];var result=[];urls.forEach(function(url){if(!url)return;var svg=_this.getIconByKey(url);if(!svg)missingUrls.push(url);else result.push({Key:url,Value:svg})});if(missingUrls.length>0){var promises_1=[];var svgs_1=[];missingUrls.forEach(function(url){var promise=$.Deferred();$.ajax(url,{dataType:"xml"}).then(function(data){var document=data;if(document&&document.documentElement.nodeName.toLowerCase()==="svg"){var svgString=_this.xmlSerializer.serializeToString(document);if(svgString){svgs_1.push({Key:url,Value:svgString})}else{if(window&&window.onerror)window.onerror("not a valid icon. url: ".concat(url," "))}}promise.resolve()},function(jqXHR,status){if(window&&window.onerror)window.onerror("Icon not found for url: ".concat(url,", ").concat(status.indexOf("parser")!==-1?"not an icon":status)),promise.resolve()});promises_1.push(promise)});return eXpress.utils.whenAll(promises_1).then(function(){_this.addSvgs.apply(_this,svgs_1);return result.concat(svgs_1)})}return $.Deferred().resolve([]).promise()};ContentManager.prototype.getLabelsAsync=function(keys){var _this=this;var cntxt=core.context?core.context:window.context;var missingKeys=[];var result=[];keys.forEach(function(key){if(!key)return;var label=_this.getLabelByKey(key);if(label===null)missingKeys.push(key);else result.push({Key:key,Value:label})});if(missingKeys.length>0){return this.contentService.getContentsAsync(missingKeys,cntxt.pointOfSaleId,cntxt.languageCode).then(function(keyvalues){_this.addLabels.apply(_this,keyvalues);return $.Deferred().resolve(result.concat(keyvalues)).promise()})}return $.Deferred().resolve([]).promise()};ContentManager.prototype.getLabelAsync=function(key){var _this=this;var cntxt=core.context?core.context:window.context;var label;if(key){label=this.getLabelByKey(key);if(label===null){return this.contentService.getContentAsync(key,cntxt.pointOfSaleId,cntxt.languageCode).then(function(value){_this.addLabels({Key:key,Value:value});return $.Deferred().resolve(value).promise()})}}else{label=""}return $.Deferred().resolve(label).promise()};ContentManager.prototype.getLabel=function(key,defaultContent){if(defaultContent===void 0){defaultContent=""}if(this.showLabels)defaultContent=this.formatLabel(key,defaultContent);if(this.labels.length===0)return defaultContent;return this.getLabelByKey(key)||defaultContent};ContentManager.prototype.addLabels=function(){var _this=this;var labelsToAdd=[];for(var _i=0;_i<arguments.length;_i++){labelsToAdd[_i]=arguments[_i]}labelsToAdd.forEach(function(label){if(!_this.containsKey(label.Key,_this.labels)){_this.labels.push({Key:label.Key,Value:_this.formatLabel(label.Key,label.Value)})}})};ContentManager.prototype.addSvgs=function(){var _this=this;var svgsToAdd=[];for(var _i=0;_i<arguments.length;_i++){svgsToAdd[_i]=arguments[_i]}svgsToAdd.forEach(function(svg){if(!svg)return;if(!_this.containsKey(svg.Key,_this.icons))_this.icons.push({Key:svg.Key,Value:svg.Value})})};ContentManager.prototype.containsKey=function(key,source){return source.filter(function(keyVal){return keyVal.Key===key}).length>0};ContentManager.prototype.getLabelByKey=function(key){var filtered=this.labels.filter(function(keyVal){return keyVal.Key.toLowerCase()===key.toLowerCase()}).map(function(p){return p.Value});if(filtered.length===0)return null;return filtered[0]};ContentManager.prototype.getIconByKey=function(key){var filtered=this.icons.filter(function(keyVal){return keyVal.Key.toLowerCase()===key.toLowerCase()}).map(function(p){return p.Value});if(filtered.length===0)return undefined;return filtered[0]};ContentManager.prototype.formatLabel=function(key,value){value=value||"";return this.showLabels?"[".concat(key,"]").concat(value):value};return ContentManager}();core.ContentManager=ContentManager})(core=eXpress.core||(eXpress.core={}))})(eXpress||(eXpress={}));