import events from"./../emby-apiclient/events.js";import connectionManager from"./../emby-apiclient/connectionmanager.js";import appSettings from"./../common/appsettings.js";import focusManager from"./../focusmanager.js";import dialogHelper from"./../dialoghelper/dialoghelper.js";import loading from"./../loading/loading.js";import{appHost,shell,iapManager}from"./../common/servicelocator.js";import layoutManager from"./../layoutmanager.js";import globalize from"./../common/globalize.js";import listView from"./../listview/listview.js";import"./../emby-elements/emby-button/emby-button.js";import"./../emby-elements/emby-dialogclosebutton/emby-dialogclosebutton.js";import"./../emby-elements/emby-itemscontainer/emby-itemscontainer.js";require(["formDialogStyle"]);let 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 showPrompt(options){return Emby.importModule("./modules/prompt/prompt.js").then(function(prompt){return prompt(options)})}function showInAppPurchaseInfo(subscriptionOptions,unlockableProductInfo,dialogOptions){return new Promise(function(resolve,reject){showInAppPurchaseElement(subscriptionOptions,unlockableProductInfo,dialogOptions,resolve,reject),currentDisplayingResolve=resolve})}function getBenefitsListOptions(items){return{renderer:listView,options:{defaultBackground:!1,moreButton:!1,action:"none",multiSelect:!1,roundImage:!0,fields:["Name","ShortOverview"],draggable:!1,draggableXActions:!1,contextMenu:!1}}}function initSubscriptionBenefitsItemsContainer(context){let itemsContainer=context.querySelector(".benefitsItemsContainer");if(itemsContainer)return itemsContainer.fetchData=getSubscriptionBenefits,itemsContainer.getListOptions=getBenefitsListOptions,itemsContainer.waitForCustomElementUpgrade().then(function(){return itemsContainer.resume({refresh:!0})})}function showPeriodicMessage(feature,settingsKey){return new Promise(function(resolve,reject){let dlg=dialogHelper.createDialog({size:layoutManager.tv?"fullscreen-border":"medium-tall",removeOnClose:!0,scrollY:!1});dlg.classList.add("formDialog");var html=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html=(html="")+'
"+'",dlg.innerHTML=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.focus(btnContinue)):dlg.querySelector(".continueTimeText").innerHTML=globalize.translate("ContinueInSecondsValue",seconds)},1e3),i,length;var btnPurchases=dlg.querySelectorAll(".buttonPremiereInfo");for(i=0,length=btnPurchases.length;iintervalMs)||"554ae9ea56b94c1c82cc628f6de52d85"===(lastMessage=connectionManager.currentApiClient()).serverId()?Promise.resolve():(intervalMs={viewOnly:!0},connectionManager.getRegistrationInfo(iapManager.getAdminFeatureName(feature),lastMessage,intervalMs).catch(function(errorResult){return"overlimit"===errorResult?(appSettings.set(settingsKey,Date.now()),Promise.resolve()):showPeriodicMessage(feature,settingsKey)})):(appSettings.set(settingsKey,Date.now()),Promise.resolve())}function validateFeature(feature,options){return options=options||{},console.log("validateFeature: "+feature),iapManager.isUnlockedByDefault(feature,options).then(function(){return showPeriodicMessageIfNeeded(feature)},function(){var unlockableFeatureCacheKey="featurepurchased-"+feature;if("1"===appSettings.get(unlockableFeatureCacheKey))return showPeriodicMessageIfNeeded(feature);var unlockableProduct=iapManager.getProductInfo(feature);if(unlockableProduct){var unlockableCacheKey="productpurchased-"+unlockableProduct.id;if(unlockableProduct.owned)return appSettings.set(unlockableFeatureCacheKey,"1"),appSettings.set(unlockableCacheKey,"1"),showPeriodicMessageIfNeeded(feature);if("1"===appSettings.get(unlockableCacheKey))return showPeriodicMessageIfNeeded(feature)}let unlockableProductInfo=unlockableProduct?{enableAppUnlock:!0,id:unlockableProduct.id,price:unlockableProduct.price,feature:feature}:null;return iapManager.getSubscriptionOptions().then(function(subscriptionOptions){var registrationOptions,apiClient;return 0"+term+""}function getTermsOfPurchaseHtml(){var html="",termsOfPurchase=iapManager.getTermsOfPurchase?iapManager.getTermsOfPurchase():[];return termsOfPurchase.length?(html+=""+globalize.translate("HeaderTermsOfPurchase")+"
",termsOfPurchase.push(''+globalize.translate("PrivacyPolicy")+""),termsOfPurchase.push(''+globalize.translate("TermsOfUse")+""),(html+="")+termsOfPurchase.map(getPurchaseTermHtml).join("")+"
"):""}function showInAppPurchaseElement(subscriptionOptions,unlockableProductInfo,dialogOptions,resolve,reject){cancelInAppPurchase(),currentDisplayingProductInfos=subscriptionOptions.slice(0),unlockableProductInfo&¤tDisplayingProductInfos.push(unlockableProductInfo);let dlg=dialogHelper.createDialog({size:layoutManager.tv?"fullscreen-border":"medium-tall",removeOnClose:!0,scrollY:!1}),html=(dlg.classList.add("formDialog"),"");html=(html=(html=(html=(html=(html=(html=(html=(html+='")+'",dlg.innerHTML=html,document.body.appendChild(dlg);let btnPurchases=dlg.querySelectorAll(".btnPurchase");for(i=0,length=btnPurchases.length;i