script(type='text/ng-template', id='partials/options.social.challenges.detail.close.html')
  a.btn.btn-sm.btn-danger(ng-click="delete(closingChal)")=env.t('delete')
  h5= '- ' + env.t('or') + ' -'
  select(ui-select2, ng-required=true, ng-model='closingChal.winner', data-placeholder=env.t('selectWinner'), ng-change='selectWinner(closingChal)', )
    option(value='')
    option(ng-repeat='u in closingChal.members', value='{{u._id}}') {{u.profile.name}}

  small.pull-right
    a(ng-click='cancelClosing(closingChal)')=env.t('cancel')

script(type='text/ng-template', id='partials/options.social.challenges.detail.member.html')
  .modal.bs-modal-lg(style='display: block')
    .modal-dialog.modal-lg
      .modal-content
        .modal-header
          button.close(type='button', ng-click='$state.go("^")', aria-hidden='true') ×
          h3 {{obj.profile.name}}
        .modal-body
          habitrpg-tasks(main=false)
        .modal-footer
          a.btn.btn-default(ng-click='$state.go("^")')=env.t('close')

script(type='text/ng-template', id='partials/options.social.challenges.detail.html')
  // Edit button
  div(bindonce='challenge', ng-if='challenge.leader==user._id')
    div(ng-hide='challenge._locked==false')
      button.btn.btn-sm.btn-default(ng-click='challenge._locked = false')=env.t('edit')
      button.btn.btn-sm.btn-warning(ng-click='close(challenge, $event)', tooltip=env.t('deleteOrSelect'))=env.t('endChallenge')

    form(ng-show='challenge._locked==false')
      .form-group(ng-show='challenge._locked==false')
        button.btn.btn-sm.btn-primary(ng-click='save(challenge)')=env.t('save')
        button.btn.btn-sm.btn-default(ng-click='challenge._locked=true')=env.t('cancel')
      .form-group
        input.form-control(type='text', ng-model='challenge.name')
      .form-group
        input.form-control(type='text', minlength="3", maxlength="16", ng-model='challenge.shortName', placeholder=env.t('challengeTag'), required)
      .form-group
        textarea.form-control(cols='3', placeholder=env.t('challengeDescr'), ng-model='challenge.description')
    hr

  .well(bindonce='challenge', ng-if='challenge.description')
    markdown(ng-model='challenge.description')
  .modal-body=env.t('challengeDiscription')
  habitrpg-tasks(obj='challenge', main=false)

  // Member List
  div(bindonce='challenge', ng-if='challenge.members.length > 0')
    a.btn.btn-primary.btn-sm.pull-right(href='/api/v2/challenges/{{challenge._id}}/csv')
      =env.t('exportChallengeCSV')
    h3=env.t('hows')
    menu
      button.customize-option(ng-repeat='member in challenge.members', ng-click='toggleMember(challenge._id, member._id)') {{member.profile.name}}
  div(ui-view)

  // Accordion version if we choose that instead
  //- div(ng-if='challenge.members')
    h4=env.t('hows')
    .accordion-group(bindonce='challenge.members', ng-repeat='member in challenge.members')
      .accordion-heading
        a.accordion-toggle(ng-click='toggleMember(challenge._id, member._id)') {{member.profile.name}}
      .accordion-body(ng-class='{collapse: $stateParams.uid != member._id}')
        .accordion-inner(ng-if='$stateParams.uid == member._id')
          div(ui-view)

script(type='text/ng-template', id='partials/options.social.challenges.html')
  .container-fluid
    .row
      .col-md-2.well#challenges-filters
        h3=env.t('filter') + ':'
        h4=env.t('groups')
        ul.list-unstyled
          a.btn.btn-xs.btn-default.pull-left(ng-click='selectAll()')=env.t('all')
          a.btn.btn-xs.btn-default(ng-click='selectNone()')=env.t('none')
        br
        .checkbox(ng-repeat='group in groupsFilter')
          label
            input(type='checkbox', ng-model='search.group[group._id]')
            | {{group.name}}
        h4=env.t('membership')
        .radio
          label
            input(type='radio', name='search-participation-radio', ng-click='search._isMember = true')
            =env.t('participating')
        .radio
          label
            input(type='radio', name='search-participation-radio', ng-click='search._isMember = false')
            =env.t('notParticipating')
        .radio
          label
            input(type='radio', name='search-participation-radio', ng-click='search._isMember = undefined', checked='checked')
            =env.t('either')
      .col-md-10
        // Creation form
        button.btn.btn-success#create-challenge-btn(ng-click='create()', ng-hide='newChallenge')=env.t('createChallenge')
        .create-challenge-from.well(ng-if='newChallenge')
          form(ng-submit='save(newChallenge)')
            div
              input.btn.btn-success(type='submit', value=env.t('save'))
              input.btn.btn-danger(type='button', ng-click='discard()', value=env.t('discard'))
              select(ng-model='newChallenge.group', ng-required='required', name='Group', ng-options='g._id as g.name for g in groups')
            .challenge-options
              .form-group
                input.form-control(type='text', ng-model='newChallenge.name', placeholder=env.t('challengeTitle'), required='required')

              .form-group
                input.form-control(type='text', minlength="3", maxlength="16", ng-model='newChallenge.shortName', placeholder=env.t('challengeTag'), required)
                &nbsp;
                a.hint.vertical-20(target='_blank', href='http://habitrpg.wikia.com/wiki/Tags', popover=env.t('challengeTagPop'), popover-trigger='mouseenter', popover-placement='right')
                  ="More info"

              .form-group
                textarea.form-control(cols='3', placeholder=env.t('challengeDescr'), ng-model='newChallenge.description')

              //- what's going on here?
              br
              br

              .form-group
                input.form-control(type='number', min="{{newChallenge.group=='habitrpg' ? 1 : 0}}", max="{{maxPrize}}", ng-model='newChallenge.prize', placeholder=env.t('prize'))
                span.input-suffix.Pet_Currency_Gem1x.inline-gems
                &nbsp;
                span.hint.vertical-20(popover=env.t('prizePop'), popover-trigger='mouseenter', popover-placement='right')
                  ="More info"
                span(ng-show='newChallenge.group=="habitrpg"')
                  !=env.t('publicChallenges')

              .form-group(ng-if='user.contributor.admin')
                .checkbox
                  label
                    input(type='checkbox', ng-model='newChallenge.official')
                    =env.t('officialChallenge')

          habitrpg-tasks(main=false, obj='newChallenge')

        // Challenges list
        .panel-group
          .panel.panel-default(ng-repeat='challenge in challenges|filter:filterChallenges')
            .panel-heading
              ul.pull-right.challenge-accordion-header-specs
                li(ng-if='challenge.official')
                  span.label.label-success=env.t('officialChallenge')
                li {{challenge.group.name}}
                li
                  =env.t('by') + ' '
                  strong {{challenge.leader.profile.name}}
                li
                  | {{challenge.memberCount}}
                  = ' ' + env.t('participants')
                li(ng-show='challenge.prize')
                  p
                    // prize
                    | {{challenge.prize}}&nbsp;
                    span.inline-block.Pet_Currency_Gem1x
                    | &nbsp;
                    =env.t('prize')
                li
                  // leave / join
                  a.btn.btn-sm.btn-danger(ng-show='challenge._isMember', ng-click='clickLeave(challenge, $event)')
                    span.glyphicon.glyphicon-ban-circle
                    =env.t('leave')
                  a.btn.btn-sm.btn-success(ng-hide='challenge._isMember', ng-click='join(challenge)')
                    span.glyphicon.glyphicon-ok
                    =env.t('join')
              a.accordion-toggle(ng-click='toggle(challenge._id)') {{challenge.name}}
            .panel-body(ng-class='{collapse: !$stateParams.cid == challenge._id}')
              .accordion-inner(ng-if='$stateParams.cid == challenge._id')
                div(ui-view)
