var eXpress,__extends=window&&window.__extends||function(){var extendStatics=function(d,b){return extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])},extendStatics(d,b)};return function(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)}}();!function(eXpress){var deserialization,core,ContentManager;!function(services){var ShowPriceUpsell,PreviewOnPage,VariantSelectorOnPage,VariantSelectorValue;(ShowPriceUpsell=services.ShowPriceUpsell||(services.ShowPriceUpsell={}))[ShowPriceUpsell.ExtraCost=0]="ExtraCost",ShowPriceUpsell[ShowPriceUpsell.TotalCost=1]="TotalCost",ShowPriceUpsell[ShowPriceUpsell.ExtraCostPerUnit=2]="ExtraCostPerUnit",ShowPriceUpsell[ShowPriceUpsell.TotalCostPerUnit=3]="TotalCostPerUnit",(PreviewOnPage=services.PreviewOnPage||(services.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",(VariantSelectorOnPage=services.VariantSelectorOnPage||(services.VariantSelectorOnPage={}))[VariantSelectorOnPage.None=0]="None",VariantSelectorOnPage[VariantSelectorOnPage.Icon=1]="Icon",VariantSelectorOnPage[VariantSelectorOnPage.DropDown=2]="DropDown",(VariantSelectorValue=services.VariantSelectorValue||(services.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";var ContentService=function(_super){function ContentService(deps){var _this=_super.call(this,deps.apiHostUrl,"ContentService.svc/json/")||this;return _this.language=deps.languageCode,_this.pointOfSaleId=deps.pointOfSaleId,_this.applicationId=deps.applicationId,_this}return __extends(ContentService,_super),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(){for(var keys=[],_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){return key&&prefix&&0!==key.indexOf(prefix)?prefix+"."+key: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)}))},ContentService}(services.ServiceBase);services.ContentService=ContentService}(eXpress.services||(eXpress.services={})),function(deserialization){function productOptionGroupConvert(productOptionGroup){if(productOptionGroup)return{key:productOptionGroup.key,deprecated:productOptionGroup.Deprecated,productOptions:productOptionGroup.ProductOptions.map((function(po){return productOptionInGroupConvert(po)}))}}function productOptionInGroupConvert(productOptionInGroup){return{isDefault:productOptionInGroup.DefaultProductOption,optionCode:productOptionInGroup.OptionCode}}function productUpsellItemConvert(item){return{key:item.Key,title:item.Title||void 0,description:item.Description||void 0,shortTitle:item.ShortTitle||void 0,shortDescription:item.ShortDescription||void 0,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}}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}}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.productOptionGroupConvert=productOptionGroupConvert,deserialization.productOptionInGroupConvert=productOptionInGroupConvert,deserialization.productUpsellConvert=function productUpsellConvert(item){return{productCode:item.ProductCode,title:item.Title,description:item.Description,productUpsellItems:item.ProductUpsellItems.map((function(item){return productUpsellItemConvert(item)}))}},deserialization.productUpsellItemConvert=productUpsellItemConvert,deserialization.productUpsellItemProductVariantConvert=productUpsellItemProductVariantConvert,deserialization.productAdornerInfoConvert=function productAdornerInfoConvert(info){return 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}}}}))},deserialization.productCategoryReviewConvert=productCategoryReviewConvert,deserialization.productCategoryReviewsConvert=function productCategoryReviewsConvert(object){return{productCategoryReviews:object.ProductCategoryReviews.map((function(r){return productCategoryReviewConvert(r)})),totalAmountOfReviews:object.TotalAmountOfReviews,starAmounts:object.StarAmounts}}}(deserialization=eXpress.deserialization||(eXpress.deserialization={})),core=eXpress.core||(eXpress.core={}),ContentManager=function(){function ContentManager(contentService,showLabels){void 0===showLabels&&(showLabels=!1),this.xmlSerializer=new XMLSerializer,this.labels=[],this.icons=[],this.contentService=contentService,this.showLabels=showLabels}return ContentManager.prototype.getIconsByNameAsync=function(iconNames){var _a,_this=this,filteredNames=iconNames.filter((function(item,index){return iconNames.indexOf(item)===index&&!_this.icons[item.toLowerCase()]}));return filteredNames.length>0?(_a=this.contentService).getIconsByNameAsync.apply(_a,filteredNames).then((function(res){var promises=res.map((function(kvp){var deferred=$.Deferred();return $.ajax(kvp.Value,{dataType:"xml"}).then((function(data){var document=data;if(document&&"svg"===document.documentElement.nodeName.toLowerCase()){var svgString=_this.xmlSerializer.serializeToString(document);deferred.resolve({Key:kvp.Key.toLowerCase(),Value:svgString})}else deferred.resolve(void 0)}),(function(jqXhr,status,error){window&&window.onerror&&window.onerror("Icon not found for contentkey: ".concat(kvp.Key," , ").concat(-1!==status.indexOf("parser")?"not an icon":status)),deferred.resolve(void 0)})),deferred.promise()}));return eXpress.utils.whenAll(promises).then((function(svgs){return _this.addSvgs.apply(_this,svgs.filter((function(svg){return!!svg}))),svgs}))})):$.Deferred().resolve([]).promise()},ContentManager.prototype.getIconsAsync=function(urls){var _this=this,missingUrls=[],result=[];if(urls.forEach((function(url){if(url){var svg=_this.getIconByKey(url);svg?result.push({Key:url,Value:svg}):missingUrls.push(url)}})),missingUrls.length>0){var promises_1=[],svgs_1=[];return missingUrls.forEach((function(url){var promise=$.Deferred();$.ajax(url,{dataType:"xml"}).then((function(data){var document=data;if(document&&"svg"===document.documentElement.nodeName.toLowerCase()){var svgString=_this.xmlSerializer.serializeToString(document);svgString?svgs_1.push({Key:url,Value:svgString}):window&&window.onerror&&window.onerror("not a valid icon. url: ".concat(url," "))}promise.resolve()}),(function(jqXHR,status){window&&window.onerror&&(window.onerror("Icon not found for url: ".concat(url,", ").concat(-1!==status.indexOf("parser")?"not an icon":status)),promise.resolve())})),promises_1.push(promise)})),eXpress.utils.whenAll(promises_1).then((function(){return _this.addSvgs.apply(_this,svgs_1),result.concat(svgs_1)}))}return $.Deferred().resolve([]).promise()},ContentManager.prototype.getLabelsAsync=function(keys){var _this=this,cntxt=core.context?core.context:window.context,missingKeys=[],result=[];return keys.forEach((function(key){if(key){var label=_this.getLabelByKey(key);null===label?missingKeys.push(key):result.push({Key:key,Value:label})}})),missingKeys.length>0?this.contentService.getContentsAsync(missingKeys,cntxt.pointOfSaleId,cntxt.languageCode).then((function(keyvalues){return _this.addLabels.apply(_this,keyvalues),$.Deferred().resolve(result.concat(keyvalues)).promise()})):$.Deferred().resolve([]).promise()},ContentManager.prototype.getLabelAsync=function(key){var label,_this=this,cntxt=core.context?core.context:window.context;if(key){if(null===(label=this.getLabelByKey(key)))return this.contentService.getContentAsync(key,cntxt.pointOfSaleId,cntxt.languageCode).then((function(value){return _this.addLabels({Key:key,Value:value}),$.Deferred().resolve(value).promise()}))}else label="";return $.Deferred().resolve(label).promise()},ContentManager.prototype.getLabel=function(key,defaultContent){return void 0===defaultContent&&(defaultContent=""),this.showLabels&&(defaultContent=this.formatLabel(key,defaultContent)),0===this.labels.length?defaultContent:this.getLabelByKey(key)||defaultContent},ContentManager.prototype.addLabels=function(){for(var _this=this,labelsToAdd=[],_i=0;_i<arguments.length;_i++)labelsToAdd[_i]=arguments[_i];labelsToAdd.forEach((function(label){_this.containsKey(label.Key,_this.labels)||_this.labels.push({Key:label.Key,Value:_this.formatLabel(label.Key,label.Value)})}))},ContentManager.prototype.addSvgs=function(){for(var _this=this,svgsToAdd=[],_i=0;_i<arguments.length;_i++)svgsToAdd[_i]=arguments[_i];svgsToAdd.forEach((function(svg){svg&&(_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}));return 0===filtered.length?null: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(0!==filtered.length)return filtered[0]},ContentManager.prototype.formatLabel=function(key,value){return value=value||"",this.showLabels?"[".concat(key,"]").concat(value):value},ContentManager}(),core.ContentManager=ContentManager}(eXpress||(eXpress={}));
//# sourceMappingURL=ContentService.min.js.map
