define(["exports","./../emby-apiclient/events.js","./../emby-apiclient/connectionmanager.js","./../common/appsettings.js","./../focusmanager.js","./../dialoghelper/dialoghelper.js","./../loading/loading.js","./../common/servicelocator.js","./../layoutmanager.js","./../common/globalize.js","./../listview/listview.js","./../emby-elements/emby-button/emby-button.js"],function(_exports,_events,_connectionmanager,_appsettings,_focusmanager,_dialoghelper,_loading,_servicelocator,_layoutmanager,_globalize,_listview,_embyButton){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["formDialogStyle"]);var currentDisplayingProductInfos=[],currentDisplayingResolve=null,currentValidatingFeature=null,isCurrentDialogRejected=null;function showAlert(options){return Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}function showInAppPurchaseInfo(subscriptionOptions,unlockableProductInfo,dialogOptions){return new Promise(function(resolve,reject){!function(subscriptionOptions,unlockableProductInfo,dialogOptions,resolve,reject){cancelInAppPurchase(),currentDisplayingProductInfos=subscriptionOptions.slice(0),unlockableProductInfo&¤tDisplayingProductInfos.push(unlockableProductInfo);var i,length,dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"fullscreen-border",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),"");html=(html=(html=(html=(html=(html+='
')+'

')+(dialogOptions.title||""))+"

")+'
')+'

',html+=unlockableProductInfo?_globalize.default.translate("MessageUnlockAppWithPurchaseOrSupporter"):_globalize.default.translate("MessageUnlockAppWithSupporter");for(html=(html+='

')+_globalize.default.translate("MessageToValidateSupporter")+"

",i=0,length=subscriptionOptions.length;i")+'

";unlockableProductInfo&&(unlockText=_globalize.default.translate("ButtonUnlockWithPurchase"),unlockableProductInfo.price&&(unlockText=_globalize.default.translate("ButtonUnlockPrice",unlockableProductInfo.price)),html=(html+="

")+'

");html=(html+="

")+'

",subscriptionOptions.length&&(html=(html=html+('

'+_globalize.default.translate("HeaderBenefitsEmbyPremiere"))+'

')+getSubscriptionBenefits().map(getSubscriptionBenefitHtml).join("")+"
");"playback"===dialogOptions.feature&&(html=(html+="

")+'

");html=(html=html+function(){var html="",termsOfPurchase=_servicelocator.iapManager.getTermsOfPurchase?_servicelocator.iapManager.getTermsOfPurchase():[];return termsOfPurchase.length&&(html+="

"+_globalize.default.translate("HeaderTermsOfPurchase")+"

",termsOfPurchase.push(''+_globalize.default.translate("PrivacyPolicy")+""),termsOfPurchase.push(''+_globalize.default.translate("TermsOfUse")+""),html=(html+="
    ")+termsOfPurchase.map(getPurchaseTermHtml).join("")+"
"),html}()+"")+"
",dlg.innerHTML=html,document.body.appendChild(dlg);var btnPurchases=dlg.querySelectorAll(".btnPurchase");for(i=0,length=btnPurchases.length;i')+'

')+_servicelocator.iapManager.getRestoreButtonText())+"

")+'
')+'

')+_globalize.default.translate("HowDidYouPay"))+"

")+'

",unlockableProductInfo&&(html=(html+="

")+'

");html=(html+="
")+"
",dlg.innerHTML=html,document.body.appendChild(dlg),_loading.default.hide(),dlg.querySelector(".btnCloseDialog").addEventListener("click",function(){_dialoghelper.default.close(dlg)}),dlg.querySelector(".btnRestoreSub").addEventListener("click",function(){_dialoghelper.default.close(dlg),showAlert({text:_globalize.default.translate("MessageToValidateSupporter"),title:"Emby Premiere"})});unlockableProductInfo=dlg.querySelector(".btnRestoreUnlock");unlockableProductInfo&&unlockableProductInfo.addEventListener("click",function(){_dialoghelper.default.close(dlg),_servicelocator.iapManager.restorePurchase()});_dialoghelper.default.open(dlg)}(unlockableProductInfo)}),_loading.default.hide();var btnCloseDialogs=dlg.querySelectorAll(".btnCloseDialog");for(i=0,length=btnCloseDialogs.length;iintervalMs)||"554ae9ea56b94c1c82cc628f6de52d85"===(lastMessage=_connectionmanager.default.currentApiClient()).serverId()?Promise.resolve():_connectionmanager.default.getRegistrationInfo(_servicelocator.iapManager.getAdminFeatureName(feature),lastMessage,{viewOnly:!0}).catch(function(errorResult){return"overlimit"===errorResult?(_appsettings.default.set(settingsKey,Date.now()),Promise.resolve()):function(settingsKey){return new Promise(function(resolve,reject){for(var dlg=_dialoghelper.default.createDialog({size:_layoutmanager.default.tv?"fullscreen":"fullscreen-border",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),""),seconds=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=html+'
'+'')+'

Emby Premiere'+"

")+"
"+'
')+'
'+'
')+('

'+_globalize.default.translate("HeaderDiscoverEmbyPremiere")+"

"))+("

"+_globalize.default.translate("MessageDidYouKnowCinemaMode")+"

"))+("

"+_globalize.default.translate("CinemaModeFeatureDescription")+"

"))+("

"+_globalize.default.translate("HeaderBenefitsEmbyPremiere")+"

")+"
")+getSubscriptionBenefits().map(getSubscriptionBenefitHtml).join("")+"
")+"
"+'
')+('"),11),isRejected=(html=(html+='
'+_globalize.default.translate("ContinueInSecondsValue",seconds)+"
")+('"),dlg.innerHTML=html=(html=html+"
"+"
")+"
"+"
",!0),timeTextInterval=setInterval(function(){var btnContinue;--seconds<=0?(clearInterval(timeTextInterval),dlg.querySelector(".continueTimeText").classList.add("hide"),(btnContinue=dlg.querySelector(".btnContinue")).classList.remove("hide"),_focusmanager.default.focus(btnContinue)):dlg.querySelector(".continueTimeText").innerHTML=_globalize.default.translate("ContinueInSecondsValue",seconds)},1e3),btnPurchases=dlg.querySelectorAll(".buttonPremiereInfo"),i=0,length=btnPurchases.length;i"+term+""}function getSubscriptionBenefits(){var list=[];return list.push({name:_globalize.default.translate("HeaderFreeApps"),icon:"",autortl:!1,text:_globalize.default.translate("FreeAppsFeatureDescription")}),_servicelocator.appHost.supports("sync")&&list.push({name:_globalize.default.translate("HeaderOfflineDownloads"),icon:"",text:_globalize.default.translate("HeaderOfflineDownloadsDescription")}),list.push({name:_globalize.default.translate("LiveTV"),icon:"",text:_globalize.default.translate("LiveTvFeatureDescription")}),list.push({name:"Emby DVR",icon:"",text:_globalize.default.translate("DvrFeatureDescription")}),list.push({name:_globalize.default.translate("HeaderCinemaMode"),icon:"",text:_globalize.default.translate("CinemaModeFeatureDescription")}),list.push({name:_globalize.default.translate("HeaderCloudSync"),icon:"",text:_globalize.default.translate("CloudSyncFeatureDescription")}),list}function getSubscriptionBenefitHtml(item){var enableLink=_servicelocator.appHost.supports("externalpremium"),html="",cssClass="listItem listItem-border";return _layoutmanager.default.tv&&(cssClass+=" listItem-focusscale"),html+=enableLink?'":"")}function onPurchaseButtonClick(){var featureId=this.getAttribute("data-featureid");"true"===this.getAttribute("data-email")?function(){if(_connectionmanager.default.isLoggedIntoConnect()){var connectUser=_connectionmanager.default.connectUser();if(connectUser&&connectUser.Email)return Promise.resolve(connectUser.Email)}return function(options){return Emby.importModule("./modules/prompt/prompt.js").then(function(prompt){return prompt(options)})}({label:_globalize.default.translate("LabelEmailAddress")})}().then(function(email){_servicelocator.iapManager.beginPurchase(featureId,email)}):_servicelocator.iapManager.beginPurchase(featureId)}function showPremiereInfo(){return _servicelocator.appHost.supports("externalpremium")?(showExternalPremiereInfo(),Promise.resolve()):_servicelocator.iapManager.getSubscriptionOptions().then(function(subscriptionOptions){return showInAppPurchaseInfo(subscriptionOptions,null,{title:"Emby Premiere",feature:"sync"})})}_events.default.on(_servicelocator.iapManager,"productupdated",function(e,product){var feature,resolve=currentDisplayingResolve;product.owned&&resolve&¤tDisplayingProductInfos.filter(function(p){return product.id===p.id}).length?(isCurrentDialogRejected=!1,cancelInAppPurchase(),resolve()):(feature=currentValidatingFeature)&&_servicelocator.iapManager.isUnlockedByDefault(feature).then(function(){isCurrentDialogRejected=!1,cancelInAppPurchase(),resolve&&resolve()})}),_exports.default={validateFeature:function(feature,options){return options=options||{},console.log("validateFeature: "+feature),_servicelocator.iapManager.isUnlockedByDefault(feature,options).then(function(){return showPeriodicMessageIfNeeded(feature)},function(){var unlockableFeatureCacheKey="featurepurchased-"+feature;if("1"===_appsettings.default.get(unlockableFeatureCacheKey))return showPeriodicMessageIfNeeded(feature);var unlockableProduct=_servicelocator.iapManager.getProductInfo(feature);if(unlockableProduct){var unlockableCacheKey="productpurchased-"+unlockableProduct.id;if(unlockableProduct.owned)return _appsettings.default.set(unlockableFeatureCacheKey,"1"),_appsettings.default.set(unlockableCacheKey,"1"),showPeriodicMessageIfNeeded(feature);if("1"===_appsettings.default.get(unlockableCacheKey))return showPeriodicMessageIfNeeded(feature)}var unlockableProductInfo=unlockableProduct?{enableAppUnlock:!0,id:unlockableProduct.id,price:unlockableProduct.price,feature:feature}:null;return _servicelocator.iapManager.getSubscriptionOptions().then(function(subscriptionOptions){var registrationOptions,apiClient;return 0