@model IEnumerable<BlogPost>

<h2 markdown="@ViewData["Title"]"></h2>
<p class="text-success">@ViewData["StatusMessage"]</p>
@if (User.IsSignedIn()) {

<label>
<input type="checkbox" id="cbv" checked/>Invisibles, posts privés</label>
    <script>
        $("#cbv").change(function() {
            if (this.checked) {
                $("tr.hiddenpost").removeClass("hidden");
            } else {
                $("tr.hiddenpost").addClass("hidden");
            }
        });
        </script>
}
<p>
    <a asp-action="Create" asp-route-title="@ViewData["Title"]">Poster au même titre"]</a>
</p>

<table class="table">
    
@foreach (var item in Model) {
    var trclass = (item.Visible)?"visiblepost":"hiddenpost";

    <tr class="@trclass">
        <td><a asp-action="Details" asp-route-id="@item.Id" class="bloglink">
       <img src="@item.Photo" class="blogphoto"></a>
        </td>
        <td>
            <markdown>@((item.Content?.Length > 256) ? item.Content.Substring(0, 256) + " ..." : item.Content)</markdown>
            <span style="font-size:x-small;">(@item.Author.UserName </span>,
            <span style="font-size:xx-small;">
            posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")
            @if ((item.DateModified - item.DateCreated).Minutes > 0){ 
                @:- Modifié le @item.DateModified.ToString("dddd d MMM yyyy à H:mm")
             })
            </span>
        </td>
        <td> 
            <ul class="actiongroup">
                @if ((await AuthorizationService.AuthorizeAsync(User, item, new ViewRequirement())).Succeeded) {
                <li>
                    <a asp-action="Details" asp-route-id="@item.Id"  class="btn btn-lg">Details</a>
            </li>
                }
            @if ((await AuthorizationService.AuthorizeAsync(User, item, new EditRequirement())).Succeeded) {
            <li><a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-default">Edit</a>
            </li>
            <li><a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Delete</a>
            </li>
            }
            </ul>
        </td>
    </tr>
}
</table>


