template(name="adminReports")
  .setting-content.admin-reports-content
    unless currentUser.isAdmin
      | {{_ 'error-notAuthorized'}}
    else
      .content-body
        .side-menu
          ul
            li
              a.js-report-broken(data-id="report-broken")
                i.fa.fa-chain-broken
                | {{_ 'broken-cards'}}

            li
              a.js-report-files(data-id="report-files")
                i.fa.fa-paperclip
                | {{_ 'filesReportTitle'}}

            li
              a.js-report-rules(data-id="report-rules")
                i.fa.fa-magic
                | {{_ 'rulesReportTitle'}}

            li
              a.js-report-boards(data-id="report-boards")
                i.fa.fa-magic
                | {{_ 'boardsReportTitle'}}

            li
              a.js-report-cards(data-id="report-cards")
                i.fa.fa-magic
                | {{_ 'cardsReportTitle'}}

        .main-body
          if loading.get
            +spinner
          else if showBrokenCardsReport.get
            +brokenCardsReport
          else if showFilesReport.get
            +filesReport
          else if showRulesReport.get
            +rulesReport
          else if showBoardsReport.get
            +boardsReport
          else if showCardsReport.get
            +cardsReport


template(name="brokenCardsReport")
  .global-search-results-list-wrapper
    h1 {{_ 'broken-cards'}}
    if resultsCount
      +resultsPaged(this)
    else
      div {{_ 'no-results' }}

template(name="rulesReport")
  h1 {{_ 'rulesReportTitle'}}
  if resultsCount
    table
      tr
        th Rule Title
        th Board Title
        th actionType
        th activityType

      each rule in results
        tr
          td {{ rule.title }}
          td {{ rule.boardTitle }}
          td {{ rule.action.actionType }}
          td {{ rule.trigger.activityType }}
  else
    div {{_ 'no-results' }}

template(name="filesReport")
  h1 {{_ 'filesReportTitle'}}
  if resultsCount
    table
      tr
        th Filename
        th.right Size (kB)
        th MIME Type
        th Attachment ID
        th Board ID
        th Card ID

      each att in results
        tr
          td {{ att.name }}
          td.right {{fileSize att.size }}
          td {{ att.type }}
          td {{ att._id }}
          td {{ att.meta.boardId }}
          td {{ att.meta.cardId }}
  else
    div {{_ 'no-results' }}

template(name="cardsReport")
  h1 {{_ 'cardsReportTitle'}}
  if resultsCount
    table.table
      tr
        th Card Title
        th Board
        th Swimlane
        th List
        th Members
        th Assignees

      each card in results
        tr
          td {{abbreviate card.title }}
          td {{abbreviate card.board.title }}
          td {{abbreviate card.swimlane.title }}
          td {{abbreviate card.list.title }}
          td {{userNames card.members }}
          td {{userNames card.assignees }}
  else
    div {{_ 'no-results' }}

template(name="boardsReport")
  h1 {{_ 'boardsReportTitle'}}
  if resultsCount
    table.table
      tr
        th Title
        th Id
        th Permission
        th Archived?
        th Members
        th Organizations
        th Teams

      each board in results
        tr
          td {{abbreviate board.title }}
          td {{abbreviate board._id }}
          td {{ board.permission }}
          td
            = yesOrNo(board.archived)
          td {{userNames board.members }}
  else
    div {{_ 'no-results' }}
