<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 !== ''"
    ng-bind-html="assignment.description | trusted"
    class="zoomcontent clearfix">
  </div>

  <!-- Candidates -->
  <div class="zoomcontent" 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 class="zoomcontent" 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-5" translate>Votes</th>

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

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

        <!-- votes -->
        <td ng-if="poll.has_votes" class="bold">
          <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[0].percentStr }}<br>
                {{ votes[1].label | translate }}: {{ votes[1].value }} {{ votes[1].percentStr }}<br>
                {{ votes[2].label | translate }}: {{ votes[2].value }} {{ votes[2].percentStr }}</span>
              <span ng-show="poll.pollmethod == 'yn'">
                {{ votes[0].label | translate }}: {{ votes[0].value }} {{ votes[0].percentStr }}<br>
                {{ votes[1].label | translate }}: {{ votes[1].value }} {{ votes[1].percentStr }}</span>
            </div>
            <div ng-show="poll.pollmethod == 'votes'">
              <div ng-repeat="vote in votes">
                {{ vote.value }} {{ vote.percentStr }}
              </div>
            </div>
          </div>

      <!-- total votes (valid/invalid/casts) -->
      <tr class="total" ng-if="poll.has_votes && poll.getVote('votesvalid').value !== null">
        <td>
          <translate>Valid ballots</translate>
        <td ng-init="vote = poll.getVote('votesvalid')">
          {{ vote.value }} {{ vote.percentStr }}

      <tr class="total" ng-if="poll.has_votes && poll.getVote('votesinvalid').value !== null">
        <td>
          <translate>Invalid ballots</translate>
        <td ng-init="vote = poll.getVote('votesinvalid')">
          {{ vote.value }} {{ vote.percentStr }}

      <tr class="total bg-info" ng-if="poll.has_votes && poll.getVote('votescast').value !== null">
        <td>
          <translate>Casted ballots</translate>
        <td ng-init="vote = poll.getVote('votescast')">
          {{ vote.value }} {{ vote.percentStr }}
      </table>
    </div>

  </div>
</div>
