extends ../layouts/main-sidebar
block content-header

  if post.image
    div(style="position: relative;")
      img(src=`/image/${post.image._id}`, style="max-height: 420px; object-fit: cover; object-position: center center;").responsive

block content

  include ../components/share-buttons

  include ../comment/components/comment-list
  include ../comment/components/composer

  include components/author-credit

  article(dtp-post-id= post._id).content-block
    .uk-margin
      h1.article-title= post.title

      .uk-margin
        .uk-text-lead= post.summary

      div(uk-grid)
        .uk-width-auto
          +renderGabShareButton(`https://${site.domainKey}/post/${post.slug}`, `${post.title} - ${post.summary}`)
      +renderSectionTitle('Post tags')
      if Array.isArray(post.tags) && (post.tags.length > 0)
        div(uk-grid).uk-grid-small
          each tag in post.tags
            -
              var tagSlug;
              tagSlug = tag.replace(" ", "_")
            a(href=`/tag/${tagSlug}`).uk-display-block.uk-link-reset.uk-margin-small= tag
          
    .uk-margin
      .uk-article-meta
        div(uk-grid).uk-grid-small.uk-flex-top
          .uk-width-expand
            uk-text-small(data-dtp-timestamp= post.created)
            span  by #[a(href=`/user/${post.author.username}`)= post.author.displayName || post.author.username]
          if user && user.hasAuthorDashboard
            .uk-width-auto= post.status

            if post.author._id.equals(user._id) || user.hasAuthorDashboard
              .uk-width-auto
                a(href=`/post/${post._id}/edit`).uk-display-block
                  +renderButtonIcon('fa-pen', 'edit')
              .uk-width-auto
                a(
                  href="",
                  data-post-id= post._id,
                  data-post-title= post.title,
                  onclick="return dtp.app.deletePost(event);",
                ).uk-display-block.uk-text-danger
                  +renderButtonIcon('fa-trash', 'delete')

          .uk-width-auto
            +renderButtonIcon('fa-eye', displayIntegerValue(post.stats.totalVisitCount))
          .uk-width-auto
            +renderButtonIcon('fa-chevron-up', displayIntegerValue(post.stats.upvoteCount))
          .uk-width-auto
            +renderButtonIcon('fa-chevron-down', displayIntegerValue(post.stats.downvoteCount))
          .uk-width-auto
            +renderButtonIcon('fa-comment', displayIntegerValue(post.stats.commentCount))
    .uk-margin
      != post.content

    if post.updated
      .uk-margin
        .uk-article-meta This post was updated on 
          uk-text-small(data-dtp-timestamp= post.updated)
          
    
  .content-block
    .uk-margin
      +renderSectionTitle('Post author')
    +renderPostAuthorCredit(post.author)

  if user && post.flags.enableComments && user.permissions.canComment
    .content-block
      .uk-margin
        +renderSectionTitle('Add a comment')
      .uk-margin-small
        +renderCommentComposer(`comment-post-${post._id}`, { rootUrl: `/post/${post._id}/comment` })
      .uk-text-small.uk-text-muted Each site has it's own #[a(href='/policy/terms-of-service') Terms of Service]. Please read it before commenting.

  if featuredComment && post.flags.enableComments
    .content-block
      #featured-comment.uk-margin-large
        .uk-margin
          +renderSectionTitle('Linked Comment')
        +renderComment(featuredComment)

  if post.flags.enableComments
    .content-block
      +renderSectionTitle('Comments')

      if Array.isArray(comments) && (comments.length > 0)
        ul#post-comment-list.uk-list.uk-list-divider.uk-list-large
          +renderCommentList(comments, { countPerPage, rootUrl: `/post/${post.slug}/comment` })
      else
        ul#post-comment-list.uk-list.uk-list-divider.uk-list-large
        div There are no comments at this time. Please check back later.
  else
    div Come join the discussion in #[a(href='/chat/room') the chat].