@model IEnumerable<MyWebsite.Models.ImageModel>
@{
	ViewData["Title"] = "Gallery";
}

<header>
	&#xE760; <a asp-action="Index" asp-controller="Admin" asp-area="">Back to main menu</a>
	<h1>Gallery</h1>
	<a asp-action="Upload" class="comment">// &#xE11C; Upload new</a><br />
	<a asp-action="UpdateCache" class="comment">// Cache gallery</a>
</header>

<article>
	<table>
		@foreach (ImageModel item in Model)
		{
			<tr>
				<td>
					<a asp-area="" asp-controller="Gallery" asp-action="Details" asp-route-id="@item.FileName" target="_blank">
						<img title="@item.Title" src="~/images/Gallery/@(item.FileName.EndsWith(".svg", StringComparison.OrdinalIgnoreCase) ? item.FileName : $"Cache/{item.FileName}.jpg")" onerror="this.src = '/images/Gallery/@item.FileName'" />
					</a>
				</td>
				<td>
					<p>
						<h3>@item.Title</h3>
						<span>File name: @item.FileName</span><br />
						<span>Creation date: @item.CreationDate.ToShortDateString()</span><br />
						<span>
							<a asp-action="Edit" asp-route-id="@item.FileName">Edit</a> |
							<a asp-action="Delete" asp-route-id="@item.FileName">Delete</a> |
							<a asp-area="" asp-controller="Gallery" asp-action="Details" asp-route-id="@item.FileName" target="_blank">View</a>
						</span>
					</p>
				</td>
			</tr>
		}
	</table>
</article>

@section Imports
{
	<style type="text/css">
		img
		{
			height: 200px;
			margin-right: 20px;
		}

		table
		{
			width: initial;
		}
	</style>
}