extends layouts/main
block content

  include ../venue/components/channel-grid
  include user/components/list-item
  include comment/components/comment

  include ../chat/components/message

  div(uk-grid)
    div(class="uk-width-1-1 uk-width-auto@m")
      h3= site.name
      div(uk-grid).uk-flex-middle
        .uk-width-auto
          +renderCell('Members', formatCount(stats.memberCount))
        .uk-width-auto
          +renderCell('Posts', formatCount(stats.postCount))
        .uk-width-auto
          +renderCell('Comments', formatCount(stats.commentCount))
    div(class="uk-width-1-1 uk-width-auto@m")
      h3 DTP Constellation
      div(uk-grid).uk-flex-middle
        .uk-width-auto
          +renderCell('Potential Reach', formatCount(stats.constellation.potentialReach))
        .uk-width-auto
          +renderCell('Connected Cores', formatCount(stats.constellation.connectedCount))
        .uk-width-auto
          +renderCell('Pending Cores', formatCount(stats.constellation.pendingCount))

  .uk-margin
    h3 Hourly Sign-Ups
    canvas(id="hourly-signups")

  if Array.isArray(channels) && (channels.length > 0)
    +renderVenueChannelGrid(channels)

  .uk-margin
    div(uk-grid)
      div(class="uk-width-1-1 uk-width-1-3@l")
        h3 Admins
        if Array.isArray(admins) && (admins.length > 0)
          ul.uk-list.uk-list-divider
            each member in admins
              li
                +renderUserListItem(member)
        else
          div There are no system admins.

        h3 Moderators
        if Array.isArray(moderators) && (moderators.length > 0)
          ul.uk-list.uk-list-divider
            each member in moderators
              li
                +renderUserListItem(member)
        else
          div There are no system-level moderators.

        h3 Recent Members
        if Array.isArray(recentMembers) && (recentMembers.length > 0)
          ul.uk-list.uk-list-divider
            each member in recentMembers
              li
                +renderUserListItem(member)
        else
          div There are no recent members.

      div(class="uk-width-1-1 uk-width-1-3@l")
        h3 Recent Chat
        if Array.isArray(recentChat) && (recentChat.length > 0)
          ul.uk-list.uk-list-divider
            each message in recentChat
              li
                div(uk-grid).uk-grid-small
                  .uk-width-expand
                    +renderChatMessage(message, { fullWidth: true })
                  .uk-width-auto
                    a(href=`/admin/user/local/${message.author._id}`, uk-tooltip={ title: 'Manage user account' }).uk-button.uk-button-default.uk-button-small.uk-border-rounded
                      span
                        i.fas.fa-wrench
        else
          div There is no recent chat.

      div(class="uk-width-1-1 uk-width-1-3@l")
        h3 Recent Comments
        if Array.isArray(recentComments.comments) && (recentComments.comments.length > 0)
          ul.uk-list.uk-list-divider
            each comment in recentComments.comments
              li
                div(uk-grid).uk-grid-small
                  .uk-width-expand
                    +renderComment(comment)
                  .uk-width-auto
                    a(href=`/admin/user/local/${comment.author._id}`, uk-tooltip={ title: 'Manage user account' }).uk-button.uk-button-default.uk-button-small.uk-border-rounded
                      span
                        i.fas.fa-wrench
        else
          div There are no recent comments.

block viewjs
  script(src="/chart.js/chart.min.js")
  script(src="/chartjs-adapter-moment/chartjs-adapter-moment.min.js")
  script.
    window.addEventListener('dtp-load', ( ) => {
      const graphData = !{JSON.stringify(stats.userSignupHourly)};
      dtp.app.renderStatsGraph('#hourly-signups', 'Hourly Signups', graphData);
    });