template(name="minicard")
  .minicard(
    class="{{#if isLinkedCard}}linked-card{{/if}}"
    class="{{#if isLinkedBoard}}linked-board{{/if}}"
    class="{{#if colorClass}}minicard-{{colorClass}}{{/if}}")
    if isMiniScreenOrShowDesktopDragHandles
      .handle
        .fa.fa-arrows
    if cover
      .minicard-cover(style="background-image: url('{{cover.link 'original' '/'}}?dummyReloadAfterSessionEstablished={{sess}}');")
    if labels
      .minicard-labels(class="{{#if hiddenMinicardLabelText}}minicard-labels-no-text{{/if}}")
        each labels
          unless hiddenMinicardLabelText
            span.js-card-label.card-label(class="card-label-{{color}}" title=name)
              +viewer
                = name
          if hiddenMinicardLabelText
            .minicard-label(class="card-label-{{color}}" title="{{name}}")
    .minicard-title
      if $eq 'prefix-with-full-path' currentBoard.presentParentTask
        .parent-prefix
          | {{ parentString ' > ' }}
      if $eq 'prefix-with-parent' currentBoard.presentParentTask
        .parent-prefix
          | {{ parentCardName }}
      if isLinkedBoard
        a.js-linked-link
          span.linked-icon.fa.fa-folder
      else if isLinkedCard
        a.js-linked-link
          span.linked-icon.fa.fa-id-card
      if getArchived
        span.linked-icon.linked-archived.fa.fa-archive
      +viewer
        if currentBoard.allowsCardNumber
          span.card-number
            | ##{getCardNumber}
        = getTitle
      if $eq 'subtext-with-full-path' currentBoard.presentParentTask
        .parent-subtext
          | {{ parentString ' > ' }}
      if $eq 'subtext-with-parent' currentBoard.presentParentTask
        .parent-subtext
          | {{ parentCardName }}

    .dates
      if getReceived
        unless getStart
          unless getDue
            unless getEnd
              .date
                +minicardReceivedDate
      if getStart
        .date
          +minicardStartDate
      if getDue
        .date
          +minicardDueDate
      if getEnd
         +minicardEndDate
      if getSpentTime
        .date
          +cardSpentTime

    .minicard-custom-fields
      each customFieldsWD
        if definition.showOnCard
          if trueValue
            .minicard-custom-field
              if definition.showLabelOnMiniCard
                .minicard-custom-field-item
                  +viewer
                    = definition.name
              .minicard-custom-field-item
                if $eq definition.type "currency"
                  +viewer
                    = formattedCurrencyCustomFieldValue(definition)
                else if $eq definition.type "date"
                  .date
                    +minicardCustomFieldDate
                else if $eq definition.type "checkbox"
                  .materialCheckBox(class="{{#if value }}is-checked{{/if}}")
                else if $eq definition.type "stringtemplate"
                  +viewer
                    = formattedStringtemplateCustomFieldValue(definition)
                else
                  +viewer
                    = trueValue

    if showAssignee
      if getAssignees
        .minicard-assignees.js-minicard-assignees
          each getAssignees
            +userAvatar(userId=this)

    if showMembers
      if getMembers
        .minicard-members.js-minicard-members
          each getMembers
            +userAvatar(userId=this)

    if showCreator
      .minicard-creator
        +userAvatar(userId=this.userId noRemove=true)

    .badges
      unless currentUser.isNoComments
        if comments.count
          .badge(title="{{_ 'card-comments-title' comments.count }}")
            span.badge-icon.fa.fa-comment-o.badge-comment
              = ' '
              = comments.count
            //span.badge-comment.badge-text
            //|  {{_ 'comment'}}
      if getDescription
        unless currentBoard.allowsDescriptionTextOnMinicard
          .badge.badge-state-image-only(title=getDescription)
            span.badge-icon.fa.fa-align-left
      if getVoteQuestion
        .badge.badge-state-image-only(title=getVoteQuestion)
          span.badge-icon.fa.fa-thumbs-up(class="{{#if voteState}}text-green{{/if}}")
          span.badge-text {{ voteCountPositive }}
          span.badge-icon.fa.fa-thumbs-down(class="{{#if $eq voteState false}}text-red{{/if}}")
          span.badge-text {{ voteCountNegative }}
      if getPokerQuestion
        .badge.badge-state-image-only(title=getPokerQuestion)
          span.badge-icon.fa.fa-check(class="{{#if pokerState}}text-green{{/if}}")
          if expiredPoker
            span.badge-text {{ getPokerEstimation }}
      if attachments.length
        .badge
          span.badge-icon.fa.fa-paperclip
          span.badge-text= attachments.length
      if checklists.count
        .badge(class="{{#if checklistFinished}}is-finished{{/if}}")
          span.badge-icon.fa.fa-check-square-o
          span.badge-text.check-list-text {{checklistFinishedCount}}/{{checklistItemCount}}
      if allSubtasks.count
        .badge
          span.badge-icon.fa.fa-sitemap
          span.badge-text.check-list-text {{subtasksFinishedCount}}/{{allSubtasksCount}}
          //{{subtasksFinishedCount}}/{{subtasksCount}} does not work because when a subtaks is archived, the count goes down
      if currentBoard.allowsCardSortingByNumber
        .badge
          span.badge-icon.fa.fa-sort
          span.badge-text.check-list-sort {{ sort }}
    if currentBoard.allowsDescriptionTextOnMinicard
      if getDescription
        .minicard-description
          +viewer
            | {{ getDescription }}

template(name="editCardSortOrderPopup")
  input.js-edit-card-sort-popup(type='text' autofocus value=sort dir="auto")
  .edit-controls.clearfix
    button.primary.confirm.js-submit-edit-card-sort-popup(type="submit") {{_ 'save'}}
