@model IEnumerable<IBlogPost>
@{
    ViewData["Title"] = "Blogs, l'index";
}
@section header {
    <style>
        .collapsed {
            height: 1em;
        }
        .sametitlegrip {
            text-decoration: underline;
            cursor: pointer;
        }
        .sametitle {
            overflow: hidden;
            transition: height 1s;
        }
        td {
            transition: height 1s;
        }
        div.row {
            border-bottom: dashed black 1px;
        }
        </style>
}
@section scripts {
    <script>
        $(document).ready(function () {
                $(".sametitle").addClass("collapsed")
                .on("mouseover",function(){
                    $(this).removeClass("collapsed")
                }).on("mouseout",function(){
                    $(this).addClass("collapsed")
                });
            }
        )
   </script>
}
<h2>@ViewData["Title"]</h2>
<p class="text-success">@ViewData["StatusMessage"]</p>
@if (User.IsSignedIn()) {
<p>
    <a asp-action="Create">Create a new article</a>
</p>
}
     
<div class="blog-index">
@{
    int maxTextLen = 75;
  foreach (var post in Model) {
    <div class="post card">
    

        <a asp-action="Details" asp-route-id="@post.Id" class="bloglink" >
            <div class="float-left"><img class="photo card-photo" src="@post.Photo" ></div>
            <h3 class="index-post-title">@post.Title</h3>
        </a>
        <div>
          <a asp-action="Details" asp-route-id="@post.Id">
            <asciidoc summary="@maxTextLen">@post.Content</asciidoc></a>
            <span style="font-size:x-small;">@Html.DisplayFor(m => post.Author)</span>
            <span style="font-size:xx-small;">
            posté le @post.DateCreated.ToString("dddd d MMM yyyy à H:mm")
            @if ((post.DateModified - post.DateCreated).Minutes > 0){ 
                @:- Modifié le @post.DateModified.ToString("dddd d MMM yyyy à H:mm")
            })
            </span>
        </div>
        <div class="actiongroup">
            @if ((await AuthorizationService.AuthorizeAsync(User, post, new ReadPermission())).Succeeded) 
            {
                <a asp-action="Details" asp-route-id="@post.Id"  class="btn btn-light">Details</a>
            }
            else 
            {
            <a asp-action="Details" asp-route-id="@post.Id" class="btn btn-light">Details</a>
            }
            @if ((await AuthorizationService.AuthorizeAsync(User, post, new EditPermission())).Succeeded) 
            {
           <a asp-action="Edit" asp-route-id="@post.Id" class="btn btn-primary">Edit</a>
            
            <a asp-action="Delete" asp-route-id="@post.Id" class="btn btn-danger">Delete</a>
            
            }
        </div>
    </div>
  }
}
</div>

@if(Model.Count()==0){<p>Néant</p>}
