{{/*
  Copyright 2014 Team 254. All Rights Reserved.
  Author: pat@patfairbank.com (Patrick Fairbank)

  UI for configuring the team list for an event.
*/}}
{{define "title"}}Team List{{end}}
{{define "body"}}
{{if .ShowErrorMessage}}
  <div class="alert alert-dismissable alert-danger">
    <button type="button" class="close" data-dismiss="alert">×</button>
    You can't modify the team list once the qualification schedule has been generated. If you need to change
    the team list, clear all other data first on the Settings page.
  </div>
{{end}}
<div class="row">
  <div class="col-lg-2">
    <form class="form-horizontal" action="/setup/teams" method="POST">
      <fieldset>
        <legend>Import Teams</legend>
        {{if not .EventSettings.TBADownloadEnabled}}<p>To automatically download data about teams, enable TBA Team Info Download on the settings page</p>{{end}}
        <div class="form-group">
          <textarea class="form-control" rows="10" name="teamNumbers"
              placeholder="One team number per line"></textarea>
        </div>
        <div class="form-group">
          <button type="submit" class="btn btn-info">Add Teams</button>
        </div>
        {{if .EventSettings.TBADownloadEnabled}}
          <div class="form-group">
            <a href="/setup/teams/refresh" class="btn btn-info">Refresh Team Data from TBA</a>
          </div>
        {{end}}
        <div class="form-group">
          <button type="button" class="btn btn-primary" onclick="$('#confirmClearTeams').modal('show');">
            Clear Team List
          </button>
        </div>
        {{if .EventSettings.TbaPublishingEnabled}}
          <div class="form-group">
            <button type="button" class="btn btn-info" onclick="$('#confirmPublishTeams').modal('show');">
              Publish Team List to TBA
            </button>
          </div>
        {{end}}
        {{if .EventSettings.NetworkSecurityEnabled}}
          <div class="form-group">
            <a href="/setup/teams/generate_wpa_keys?all=true" class="btn btn-primary">Generate All WPA Keys</a>
          </div>
          <div class="form-group">
            <a href="/setup/teams/generate_wpa_keys?all=false" class="btn btn-primary">Generate Missing WPA Keys</a>
          </div>
        {{end}}
      </fieldset>
    </form>
  </div>
  <div class="col-lg-10">
    <table class="table table-striped table-hover ">
      <thead>
        <tr>
          <th>#</th>
          <th>Name</th>
          <th>Nickname</th>
          <th>Location</th>
          <th>Rookie Year</th>
          <th>Robot Name</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        {{range $team := .Teams}}
          <tr>
            <td>{{$team.Id}}</td>
            <td>{{$team.Name}}</td>
            <td>{{$team.Nickname}}</td>
            <td>{{$team.City}}, {{$team.StateProv}}, {{$team.Country}}</td>
            <td>{{$team.RookieYear}}</td>
            <td>{{$team.RobotName}}</td>
            <td class="text-center nowrap">
              <form action="/setup/teams/{{$team.Id}}/delete" method="POST">
                <a href="/setup/teams/{{$team.Id}}/edit">
                  <button type="button" class="btn btn-info btn-xs">
                    <i class="glyphicon glyphicon-edit"></i>
                  </button>
                </a>
                <button type="submit" class="btn btn-primary btn-xs">
                  <i class="glyphicon glyphicon-trash"></i>
                </button>
              </form>
            </td>
          </tr>
        {{end}}
      </tbody>
    </table>
    <b>{{len .Teams}} teams</b>
  </div>
</div>
<div id="confirmClearTeams" class="modal" style="top: 20%;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Confirm</h4>
      </div>
      <div class="modal-body">
        <p>Are you sure you want to clear the team list?</p>
      </div>
      <div class="modal-footer">
        <form class="form-horizontal" action="/setup/teams/clear" method="POST">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Clear Team List</button>
        </form>
      </div>
    </div>
  </div>
</div>
<div id="confirmPublishTeams" class="modal" style="top: 20%;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Confirm</h4>
      </div>
      <div class="modal-body">
        <p>Are you sure you want to publish the team list to The Blue Alliance? This will overwrite any
          existing team list data.</p>
      </div>
      <div class="modal-footer">
        <form class="form-horizontal" action="/setup/teams/publish" method="POST">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Publish Team List</button>
        </form>
      </div>
    </div>
  </div>
</div>
{{end}}
{{define "script"}}{{end}}
