define(["jQuery","cardStyle"],function($){"use strict";function reloadList(page){Dashboard.showLoadingMsg(),AppInfo.enableAppStorePolicy?$(".optionAdultContainer",page).hide():$(".optionAdultContainer",page).show(),query.IsAppStoreSafe=!0;var promise1=ApiClient.getAvailablePlugins(query),promise2=ApiClient.getInstalledPlugins();Promise.all([promise1,promise2]).then(function(responses){populateList({catalogElement:$("#pluginTiles",page),noItemsElement:$("#noPlugins",page),availablePlugins:responses[0],installedPlugins:responses[1]})})}function populateList(options){populateListInternal(options)}function populateListInternal(options){var availablePlugins=options.availablePlugins,installedPlugins=options.installedPlugins,allPlugins=availablePlugins.filter(function(p){return p.category=p.category||"General",p.categoryDisplayName=Globalize.translate("PluginCategory"+p.category.replace(" ","")),(!options.categories||options.categories.indexOf(p.category)!=-1)&&((!options.targetSystem||p.targetSystem==options.targetSystem)&&"UserInstalled"==p.type)});availablePlugins=allPlugins.sort(function(a,b){var aName=a.category,bName=b.category;return aName>bName?1:bName>aName?-1:(aName=a.name,bName=b.name,aName>bName?1:bName>aName?-1:0)});var i,length,plugin,currentCategory,html="";if(!options.categories){currentCategory=Globalize.translate("HeaderTopPlugins"),html+='
";var topPlugins=allPlugins.slice(0).sort(function(a,b){if(a.installs>b.installs)return-1;if(b.installs>a.installs)return 1;var aName=a.name,bName=b.name;return aName>bName?1:bName>aName?-1:0});html+='';var limit=screen.availWidth>=1920?15:12;for(i=0,length=Math.min(topPlugins.length,limit);i
",html+="
",html+="
"}var hasOpenTag=!1;for(currentCategory=null,options.showCategory===!1&&(html+='',hasOpenTag=!0),i=0,length=availablePlugins.length;i
",html+="
",html+="
"),html+='",html+='',hasOpenTag=!0),currentCategory=category),html+=getPluginHtml(plugin,options,installedPlugins)}hasOpenTag&&(html+="
"),!availablePlugins.length&&options.noItemsElement&&$(options.noItemsElement).hide(),$(options.catalogElement).html(html),Dashboard.hideLoadingMsg()}function getPluginHtml(plugin,options,installedPlugins){var html="",href=plugin.externalUrl?plugin.externalUrl:"addplugin.html?name="+encodeURIComponent(plugin.name)+"&guid="+plugin.guid;options.context&&(href+="&context="+options.context);var target=plugin.externalUrl?' target="_blank"':"";html+="",html+='
"}function getTabs(){return[{href:"plugins.html",name:Globalize.translate("TabMyPlugins")},{href:"plugincatalog.html",name:Globalize.translate("TabCatalog")}]}var query={TargetSystems:"Server",IsAdult:!1};$(document).on("pageinit","#pluginCatalogPage",function(){var page=this;$("#selectSystem",page).on("change",function(){query.TargetSystems=this.value,reloadList(page)}),$("#chkAdult",page).on("change",function(){query.IsAdult=!!this.checked&&null,reloadList(page)})}).on("pageshow","#pluginCatalogPage",function(){LibraryMenu.setTabs("plugins",1,getTabs);var page=this;reloadList(page)}),window.PluginCatalog={renderCatalog:populateList}});