define(["fetchHelper", "dom", "registrationServices", "loading", "confirm", "globalize", "connectionManager", "emby-linkbutton", "emby-collapse", "emby-input", "emby-button"], function(fetchHelper, dom, registrationServices, loading, confirm, globalize, connectionManager) { "use strict"; function getPluginSecurityInfo() { var apiClient = ApiClient; return apiClient.getJSON(apiClient.getUrl("Plugins/SecurityInfo")) } function load(page) { loading.show(), getPluginSecurityInfo().then(function(info) { page.querySelector("#txtSupporterKey").value = info.SupporterKey || "", info.SupporterKey && !info.IsMBSupporter ? (page.querySelector("#txtSupporterKey").classList.add("invalidEntry"), page.querySelector(".notSupporter").classList.remove("hide")) : (page.querySelector("#txtSupporterKey").classList.remove("invalidEntry"), page.querySelector(".notSupporter").classList.add("hide")), info.IsMBSupporter ? (page.querySelector(".supporterContainer").classList.add("hide"), getPremiereStatus(info.SupporterKey).then(function(statusInfo) { if (statusInfo) { var statusLine, indicator = page.querySelector("#status-indicator .listItemIcon"), extendedPlans = page.querySelector("#extended-plans"); switch (extendedPlans.innerHTML = globalize.translate("MessagePremiereExtendedPlans", '', ""), statusInfo.deviceStatus) { case 2: statusLine = globalize.translate("MessagePremiereStatusOver", statusInfo.planType), indicator.classList.add("expiredBackground"), indicator.classList.remove("nearExpiredBackground"), indicator.innerHTML = "", extendedPlans.classList.remove("hide"); break; case 1: statusLine = globalize.translate("MessagePremiereStatusClose", statusInfo.planType), indicator.classList.remove("expiredBackground"), indicator.classList.add("nearExpiredBackground"), indicator.innerHTML = "", extendedPlans.classList.remove("hide"); break; default: statusLine = globalize.translate("MessagePremiereStatusGood", statusInfo.planType), indicator.classList.remove("expiredBackground"), indicator.classList.remove("nearExpiredBackground"), indicator.innerHTML = "", extendedPlans.classList.add("hide") } page.querySelector("#premiere-status").innerHTML = statusLine; var subsElement = page.querySelector("#premiere-subs"); if (statusInfo.subscriptions && statusInfo.subscriptions.length > 0) { page.querySelector("#premiere-subs-content").innerHTML = getSubscriptionHtml(statusInfo.subscriptions, info.SupporterKey); var sub = page.querySelector(".lnkSubscription"); sub && sub.addEventListener("click", cancelSub), subsElement.classList.remove("hide") } else subsElement.classList.add("hide"); page.querySelector(".isSupporter").classList.remove("hide") } })) : (page.querySelector(".supporterContainer").classList.remove("hide"), page.querySelector(".isSupporter").classList.add("hide")), loading.hide() }) } function getPremiereStatus(key) { var postData = "key=" + key + "&serverId=" + ApiClient.serverId(); return fetchHelper.ajax({ url: "https://mb3admin.local/admin/service/registration/getStatus", type: "POST", data: postData, contentType: "application/x-www-form-urlencoded", dataType: "json" }) } function getSubscriptionHtml(subs, key) { return subs.map(function(item) { var itemHtml = "", makeLink = item.autoRenew && "Stripe" == item.store, tagName = makeLink ? "button" : "div"; return itemHtml += (tagName = '