extends ../layouts/main
block content

  include ../../comment/components/comment-review

  div(uk-grid).uk-grid-small
    div(class="uk-width-1-1 uk-width-2-3@l")
      form(method="POST", action=`/admin/core-user/${userAccount._id}`).uk-form
        input(type="hidden", name="username", value= userAccount.username)
        input(type="hidden", name="displayName", value= userAccount.displayName)
        .uk-card.uk-card-default.uk-card-small
          .uk-card-header
            if userAccount.displayName
              .uk-text-large= userAccount.displayName
            div
              a(href=`/user/${userAccount._id}`) @#{userAccount.username}

          .uk-card-body
            .uk-margin
              label(for="bio").uk-form-label Bio
              textarea(id="bio", name="bio", rows="3", placeholder="Enter profile bio").uk-textarea= userAccount.bio

            .uk-margin
              label.uk-form-label Flags
              div(uk-grid).uk-grid-small
                label
                  input(id="is-admin", name="isAdmin", type="checkbox", checked= userAccount.flags.isAdmin)
                  |  Admin
                label
                  input(id="is-moderator", name="isModerator", type="checkbox", checked= userAccount.flags.isModerator)
                  |  Moderator
                label
                  input(id="is-email-verified", name="isEmailVerified", type="checkbox", checked= userAccount.flags.isEmailVerified)
                  |  Email Verified

            .uk-margin
              label.uk-form-label Permissions
              .uk-margin
                div(uk-grid).uk-grid-small
                  label
                    input(id="can-login", name="canLogin", type="checkbox", checked= userAccount.permissions.canLogin)
                    |  Can Login
                  label
                    input(id="can-chat", name="canChat", type="checkbox", checked= userAccount.permissions.canChat)
                    |  Can Chat
                  label
                    input(id="can-comment", name="canComment", type="checkbox", checked= userAccount.permissions.canComment)
                    |  Can Comment
                  label
                    input(id="can-report", name="canReport", type="checkbox", checked= userAccount.permissions.canReport)
                    |  Can Report
                  label
                    input(id="can-author-pages", name="canAuthorPages", type="checkbox", checked= userAccount.permissions.canAuthorPages)
                    |  Can Author Pages
                  label
                    input(id="can-author-posts", name="canAuthorPosts", type="checkbox", checked= userAccount.permissions.canAuthorPosts)
                    |  Can Author Posts
                  label
                    input(id="can-publish-pages", name="canPublishPages", type="checkbox", checked= userAccount.permissions.canPublishPages)
                    |  Can Publish Pages
                  label
                    input(id="can-publish-posts", name="canPublishPosts", type="checkbox", checked= userAccount.permissions.canPublishPosts)
                    |  Can Publish Posts

            .uk-margin
              label.uk-form-label Opt-Ins
              div(uk-grid).uk-grid-small
                label
                  input(id="optin-system", name="optInSystem", type="checkbox", checked= userAccount.optIn.system)
                  |  System
                label
                  input(id="optin-marketing", name="optInMarketing", type="checkbox", checked= userAccount.optIn.marketing)
                  |  Marketing

            .uk-margin
              label.uk-form-label Badges
              input(id="badges", name="badges", type="text", placeholder="Enter badges", value= (userAccount.badges || [ ]).join(', ')).uk-input
              .uk-text-small.uk-text-muted Enter badge labels separated by commas

          .uk-card-footer
            div(uk-grid).uk-grid-small
              .uk-width-expand
                +renderBackButton()
              .uk-width-auto
                button(type="submit").uk-button.uk-button-primary Update User

    div(class="uk-width-1-1 uk-width-1-3@l")

      .uk-margin
        .uk-card.uk-card-default.uk-card-small
          .uk-card-header
            h4.uk-card-title
              div(uk-grid).uk-grid-small
                .uk-width-expand
                  div= userAccount.core.meta.name
                .uk-width-auto
                  img(src="/img/icon/dtp-core.svg", alt="DTP Core Icon", style="height: 1em; width: auto;")

          .uk-card-body
            .uk-margin
              label.uk-form-label Description
              div= userAccount.core.meta.description

            .uk-margin
              div(uk-grid)
                .uk-width-auto
                  label.uk-form-label Name
                  div= userAccount.core.meta.name
                .uk-width-auto
                  label.uk-form-label Created
                  div= moment(userAccount.core.created).fromNow()
                .uk-width-auto
                  label.uk-form-label Updated
                  div= moment(userAccount.core.updated).fromNow()

            .uk-margin
              div(uk-grid)
                .uk-width-auto
                  label.uk-form-label Domain
                  div= userAccount.core.meta.domain
                .uk-width-auto
                  label.uk-form-label Domain Key
                  div= userAccount.core.meta.domainKey

      .uk-margin
        .uk-card.uk-card-default.uk-card-small
          .uk-card-header
            h4.uk-card-title Recent Comments

          .uk-card-body
            if Array.isArray(recentComments) && (recentComments.length > 0)
              ul.uk-list.uk-list-divider
                each comment in recentComments
                  li
                    +renderCommentReview(comment)
            else
              div #{userAccount.displayName || userAccount.uslername} has no recent comments.