﻿@model DownloadViewModel
@{
    Layout = "~/Views/GdsLayout.cshtml";
    Title = "Administration: History";
}

@section BeforeMain {
    <a class="govuk-back-link govuk-!-margin-bottom-0" href="@Url.Action("Home")">Back to Adminstration home</a>
}

<div class="govuk-grid-row">
    <div class="govuk-grid-column-full">
        <div style="float: right; font-size: smaller;">
            <span>
                <a class="govuk-link" href="@Url.Action("History", "Admin", new {v = Guid.NewGuid().ToShortString()})" title="Show more recent content">@VirtualDateTime.Now.ToString("d MMM HH:mm")</a>
            </span>
        </div>

        <h1 class="govuk-heading-l" style="margin-top: 0.3em;">
            <span id="companyname">Administration</span> <br />
            <span class="govuk-hint govuk-!-font-size-24 govuk-!-margin-top-2">History</span>
        </h1>

        <table class="govuk-table">
            <thead class="govuk-table__head">
                <tr class="govuk-table__row">
                    <th scope="col" class="govuk-table__header">Description</th>
                    <th scope="col" class="govuk-table__header">File</th>
                </tr>
            </thead>
            <tbody class="govuk-table__body">
                @{
                    var types = Model.Downloads.Select(d => d.Type).Distinct();
                }

                @foreach (var type in types)
                {
                    var downloads = Model.Downloads.Where(d => d.Type.EqualsI(type));
                    <tr class="govuk-table__row">
                        <td colspan="2" class="govuk-table__cell">
                            <b>@type Downloads</b>
                        </td>
                    </tr>

                    @if (!downloads.Any())
                    {
                        <tr class="govuk-table__row">
                            <td colspan="2" class="govuk-table__cell">No @type.ToLower() found</td>
                        </tr>
                    }
                    else
                    {
                        foreach (var download in downloads)
                        {
                            <tr class="govuk-table__row">
                                <td class="govuk-table__cell">
                                    <a class="govuk-link" href="@Url.Action("Read", new {filePath = download.Filepath})">
                                        <b>@download.Title</b>
                                    </a><br />@download.Description
                                </td>
                                <td class="govuk-table__cell">
                                    <a class="govuk-link" href="@Url.Action("Download", new {filePath = download.Filepath})" target="_blank">@download.Filename</a>
                                </td>
                            </tr>
                        }
                    }
                }
            </tbody>
        </table>
    </div>
</div>
