<% local form, viewlibrary, page_info, session = ... %>
<% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %>

<% htmlviewfunctions.displaycommandresults({"delete", "install", "upgrade"}, session) %>

<H1><%= html.html_escape(form.label) %></H1>
<H2><%= html.html_escape(form.value.toplevel.label) %></H2>
<DL>
<TABLE>
	<TR style="background:#eee;font-weight:bold;">
	<% if viewlibrary.check_permission("delete") or viewlibrary.check_permission("upgrade") then %>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Action</TD>
	<% end %>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Package Name</TD>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Version</TD>
		<TD style="white-space:nowrap;" class="header">Description</TD>
	</TR>

<% for i,packagetable in pairs(form.value.toplevel.value) do %>
	<TR>
	<% if viewlibrary.check_permission("delete") then %>
		<TD style="padding-right:20px;white-space:nowrap;">
		<%= html.link{value = "delete?submit=true&package=" .. packagetable.name, label="Delete "} %>
	<% if viewlibrary.check_permission("upgrade") and packagetable.upgrade then %>
		<%= html.link{value = "upgrade?submit=true&package=" .. packagetable.name, label="Upgrade "} %>
	<% end %>
		</TD>
	<% end %>
		<TD><%= html.link{value = "details?package="..packagetable.name, label=packagetable.name} %></TD>
		<TD><%= html.html_escape(packagetable.version) %></TD>
		<TD><%= html.html_escape(packagetable.description) %></TD>
	</TR>
<% end %>
</TABLE>
</DL>

<H2><%= html.html_escape(form.value.dependent.label) %></H2>
<DL>
<TABLE>
	<TR style="background:#eee;font-weight:bold;">
	<% if viewlibrary.check_permission("install") or viewlibrary.check_permission("upgrade") then %>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Action</TD>
	<% end %>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Package Name</TD>
		<TD style="padding-right:20px;white-space:nowrap;" class="header">Version</TD>
		<TD style="white-space:nowrap;" class="header">Description</TD>
	</TR>

<% for i,packagetable in pairs(form.value.dependent.value) do %>
	<TR>
	<% if viewlibrary.check_permission("install") or viewlibrary.check_permission("upgrade") then %>
		<TD style="padding-right:20px;white-space:nowrap;">
	<% if viewlibrary.check_permission("install") then %>
		<%= html.link{value = "install?submit=true&package=" .. packagetable.name, label="Promote "} %>
	<% end %>
	<% if viewlibrary.check_permission("upgrade") and packagetable.upgrade then %>
		<%= html.link{value = "upgrade?submit=true&package=" .. packagetable.name, label="Upgrade "} %>
	<% end %>
		</TD>
	<% end %>
		<TD><%= html.link{value = "details?package="..packagetable.name, label=packagetable.name} %></TD>
		<TD><%= html.html_escape(packagetable.version) %></TD>
		<TD><%= html.html_escape(packagetable.description) %></TD>
	</TR>
<% end %>
</TABLE>
</DL>
