define(["jQuery","cardStyle"],function($){"use strict";function deletePlugin(page,uniqueid,name){var msg=Globalize.translate("UninstallPluginConfirmation").replace("{0}",name);require(["confirm"],function(confirm){confirm(msg,Globalize.translate("UninstallPluginHeader")).then(function(){Dashboard.showLoadingMsg(),ApiClient.uninstallPlugin(uniqueid).then(function(){reloadList(page)})})})}function showNoConfigurationMessage(){Dashboard.alert({message:Globalize.translate("NoPluginConfigurationMessage")})}function showConnectMessage(){Dashboard.alert({message:Globalize.translate("MessagePluginConfigurationRequiresLocalAccess")})}function getPluginCardHtml(plugin,pluginConfigurationPages){var configPage=$.grep(pluginConfigurationPages,function(pluginConfigurationPage){return pluginConfigurationPage.PluginId==plugin.Id})[0],html="",isConnectMode=Dashboard.isConnectMode(),configPageUrl=configPage?Dashboard.getConfigurationPageUrl(configPage.Name):null,href=configPage&&!isConnectMode?configPageUrl:null;return html+="
",html+='
',html+='
',html+='
',html+=href?'':configPageUrl?isConnectMode?'
':'
':'",html+='
',html+='
',html+='',html+="
",html+="
",html+=plugin.Name,html+="
",html+="
",html+=plugin.Version,html+="
",html+="
",html+="
",html+="
"}function renderPlugins(page,plugins,showNoPluginsMessage){ApiClient.getJSON(ApiClient.getUrl("web/configurationpages")+"?pageType=PluginConfiguration").then(function(configPages){populateList(page,plugins,configPages,showNoPluginsMessage)})}function populateList(page,plugins,pluginConfigurationPages,showNoPluginsMessage){plugins=plugins.sort(function(plugin1,plugin2){return plugin1.Name>plugin2.Name?1:-1});var html=plugins.map(function(p){return getPluginCardHtml(p,pluginConfigurationPages)}).join("");if(plugins.length){var elem=$(".installedPlugins",page).addClass("itemsContainer").addClass("vertical-wrap").html(html);$(".noConfigPluginCard",elem).on("click",function(){showNoConfigurationMessage()}),$(".connectModePluginCard",elem).on("click",function(){showConnectMessage()}),$(".btnCardMenu",elem).on("click",function(){showPluginMenu(page,this)})}else showNoPluginsMessage&&(html+='
',AppInfo.enableAppStorePolicy?html+="

"+Globalize.translate("MessageNoPluginsDueToAppStore")+"

":(html+="

"+Globalize.translate("MessageNoPluginsInstalled")+"

",html+='

',html+=Globalize.translate("BrowsePluginCatalogMessage"),html+="

"),html+="
"),$(".installedPlugins",page).html(html);Dashboard.hideLoadingMsg()}function showPluginMenu(page,elem){var card=$(elem).parents(".card"),id=card.attr("data-id"),name=card.attr("data-name"),configHref=$(".cardContent",card).attr("href"),menuItems=[];configHref&&menuItems.push({name:Globalize.translate("ButtonSettings"),id:"open",ironIcon:"mode-edit"}),menuItems.push({name:Globalize.translate("ButtonUninstall"),id:"delete",ironIcon:"delete"}),require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:elem,callback:function(resultId){switch(resultId){case"open":Dashboard.navigate(configHref);break;case"delete":deletePlugin(page,id,name)}}})})}function reloadList(page){Dashboard.showLoadingMsg(),ApiClient.getInstalledPlugins().then(function(plugins){renderPlugins(page,plugins,!0)})}function getTabs(){return[{href:"plugins.html",name:Globalize.translate("TabMyPlugins")},{href:"plugincatalog.html",name:Globalize.translate("TabCatalog")}]}$(document).on("pageshow","#pluginsPage",function(){LibraryMenu.setTabs("plugins",0,getTabs),reloadList(this)}),window.PluginsPage={renderPlugins:renderPlugins}});