extends ../layouts/main
block content

  .uk-margin
    div(uk-grid)
      .uk-width-expand
        h1.uk-text-truncate Posts
      .uk-width-auto
        a(href="/admin/post/compose").uk-button.dtp-button-primary
          +renderButtonIcon('fa-plus', 'New Post')

  .uk-margin
    if (Array.isArray(posts) && (posts.length > 0))

      ul.uk-list

        each post in posts

          li(data-post-id= post._id)
            div(uk-grid).uk-grid-small.uk-flex-middle
              .uk-width-expand
                a(href=`/post/${post.slug}`).uk-display-block.uk-text-large.uk-text-truncate #{post.title}
                .uk-text-small
                  div(uk-grid).uk-grid-small
                    .uk-width-auto
                      span published: 
                      span(data-dtp-timestamp= post.created)
                    if post.updated
                      .uk-width-auto
                        span last update: 
                        span(data-dtp-timestamp= post.updated)
                    .uk-width-auto
                      span by 
                      a(href=`/admin/user/${post.author._id}`)=` ${post.author.username}`

              .uk-width-auto
                div(uk-grid).uk-grid-small.uk-flex-middle
                  if post.flags.isFeatured
                    .uk-width-auto
                      i(style="color: yellow;").fas.fa-star
                  .uk-width-auto(class={
                    'uk-text-info': (post.status === 'draft'),
                    'uk-text-success': (post.status === 'published'),
                    'uk-text-danger': (post.status === 'archived'),
                  })= post.status
                  .uk-width-auto
                    a(href=`/admin/post/${post._id}`).uk-button.dtp-button-primary
                      +renderButtonIcon('fa-pen', 'Edit')
                  .uk-width-auto
                    button(
                      type="button",
                      data-post-id= post._id,
                      data-post-title= post.title,
                      onclick="return dtp.adminApp.deletePost(event);",
                    ).uk-button.dtp-button-danger
                      +renderButtonIcon('fa-trash', 'Delete')
    else
      div There are no posts at this time.