@namespace Blog.Components
@inject IPostService postService
@inject IJSRuntime JS


  @if (Posts is null)
  {
    return;
  }
  else if (Posts.Count == 0)
  {
    <div class="container">
      <p>Looks like writers block. Check back later.</p>
    </div>
  }
  else
  {
    <section role="feed" class="container">
      @foreach (var post in Posts)
      {
        <article>
          <NavLink href="@GetLink(post)">
            <h3 title="@post.Title" >@post.Title</h3>
            <p class="date">@post.PublishedAt.ToString("MMMM d, yyyy")</p>
            <p class="lead" title="@post.Lead">@post.Lead</p>
          </NavLink>
        </article>
      }
    </section>
  }

@code 
{
  private List<Post>? Posts;
  
  private string GetLink(Post post) => $"/{post.Slug}";

  protected override async Task OnInitializedAsync()
  {
    Posts = await postService.GetPostsAsync();
  }
}