<div ng-controller="SlideAssignmentCtrl" class="content scrollcontent">

  <!-- Title -->
  <div id="title">
    <h1>{{ assignment.agenda_item.getTitle() || assignment.title }}</h1>
    <h2>
      <translate>Election</translate>
    </h2>
  </div>

  <!-- Description -->
  <div ng-if="!showResult && assignment.description !== ''" class="white-space-pre-line">
    {{ assignment.description }}
  </div>

  <!-- Candidates -->
  <div ng-if="!showResult">
    <h3 translate>Candidates</h3>
    <ul>
      <li ng-repeat="related_user in assignment.assignment_related_users | orderBy:'weight'">
        {{ related_user.user.get_full_name() }}
        <i ng-if="related_user.elected" class="fa fa-star" title="{{ 'is elected' | translate }}"></i>
    </ul>
  </div>

  <!-- vote results -->
  <div ng-show="showResult">
    <div ng-if="(assignment.polls | filter: {id: element.poll}).length == 0" translate>
        Waiting for results ...
    </div>

    <div ng-repeat="poll in assignment.polls | filter: {id: element.poll}" class="electionresults spacer">
      <table class="table table-bordered table-striped minimumTable">
      <tr>
        <th translate>Candidates
        <th ng-if="poll.has_votes" class="col-sm-6" translate>Votes</th>

      <!-- candidates (poll options) -->
      <tr ng-repeat="option in poll.options | orderBy:'weight'">

        <!-- candidate name -->
        <td>
          <i ng-if="option.is_elected" class="fa fa-star" title="{{ 'is elected' | translate }}"></i>
          <strong>{{ option.candidate.get_full_name() }}</strong>

        <!-- votes -->
        <td ng-if="poll.has_votes">
          <div ng-init="votes = option.getVotes()">
            <div ng-show="poll.pollmethod == 'yna' || poll.pollmethod == 'yn'">
              <span ng-show="poll.pollmethod == 'yna'">
                {{ votes[0].label | translate }}: {{ votes[0].value }} ·
                {{ votes[1].label | translate }}: {{ votes[1].value }} ·
                {{ votes[2].label | translate }}: {{ votes[2].value }} </span>
              <span ng-show="poll.pollmethod == 'yn'">
                {{ votes[0].label | translate }}: {{ votes[0].value }} ·
                {{ votes[1].label | translate }}: {{ votes[1].value }}</span>
              <uib-progress ng-if="votes[0].percentNumber>=0">
                <uib-bar value="votes[0].percentNumber" type="success">
                  <span ng-hide="votes[0].percentNumber < 5">{{votes[0].percentNumber}} %</span>
                </uib-bar>
                <uib-bar value="votes[1].percentNumber" type="danger">
                  <span ng-hide="votes[1].percentNumber < 5">{{votes[1].percentNumber}} %</span>
                </uib-bar>
                <uib-bar value="votes[2].percentNumber" type="warning">
                  <span ng-hide="votes[2].percentNumber < 5">{{votes[2].percentNumber}} %</span>
                </uib-bar>
              </uib-progress>
            </div>
            <div ng-show="poll.pollmethod == 'votes'">
              <div ng-repeat="vote in votes">
                {{ vote.value }} {{ vote.percentStr }}
                <div ng-if="vote.percentNumber >= 0">
                  <uib-progressbar value="vote.percentNumber" type="success"></uib-progressbar>
                </div>
              </div>
            </div>
          </div>

      <!-- total votes (valid/invalid/casts) -->
      <tr class="total">
        <td>
          <translate>Valid ballots</translate>
        <td ng-if="poll.has_votes" ng-init="vote = poll.getVote('votesvalid')">
          {{ vote.value }} {{ vote.percentStr }}
      <tr class="total">
        <td>
          <translate>Invalid ballots</translate>
        <td ng-if="poll.has_votes" ng-init="vote = poll.getVote('votesinvalid')">
          {{ vote.value }} {{ vote.percentStr }}
      <tr class="total bg-info">
        <td>
          <translate>Casted ballots</translate>
        <td ng-if="poll.has_votes" ng-init="vote = poll.getVote('votescast')">
          {{ vote.value }} {{ vote.percentStr }}
      </table>
    </div>

  </div>
</div>
