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

  UI for manually editing the result for a match.
*/}}
{{define "title"}}Edit Match Results{{end}}
{{define "body"}}
<div class="row">
  <div class="well">
    <form class="form-horizontal" method="POST">
      <fieldset>
        <legend>Edit Match {{.Match.DisplayName}} Results</legend>
        <div class="col-lg-6" id="redScore"></div>
        <div class="col-lg-6" id="blueScore"></div>
        <div class="row form-group">
          <div class="text-center col-lg-12">
            <a href="/match_review"><button type="button" class="btn btn-default">Cancel</button></a>
            <button type="submit" class="btn btn-info">Save</button>
          </div>
        </div>
      </fieldset>
    </form>
  </div>
</div>
<div id="scoreTemplate" style="display: none;">
  <div class="well well-{{"{{alliance}}"}}">
    <legend>Autonomous</legend>
    <div class="form-group">
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Auto Runs</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}AutoRuns">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Ownership Points</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}AutoOwnershipPoints">
          </div>
        </div>
        <div class="col-lg-6">
          <label class="col-lg-9 control-label">Owned Switch at End</label>
          <div class="col-lg-3">
            <input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}AutoEndSwitchOwnership">
          </div>
        </div>
      </div>
    </div>
    <legend>Teleoperated</legend>
    <div class="form-group">
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Ownership Points</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopOwnershipPoints">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Force Cubes</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}ForceCubes">
          </div>
        </div>
        <div class="col-lg-6">
          <label class="col-lg-9 control-label">Force Played</label>
          <div class="col-lg-3">
            <input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}ForcePlayed">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Levitate Cubes</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}LevitateCubes">
          </div>
        </div>
        <div class="col-lg-6">
          <label class="col-lg-9 control-label">Levitate Played</label>
          <div class="col-lg-3">
            <input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}LevitatePlayed">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Boost Cubes</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}BoostCubes">
          </div>
        </div>
        <div class="col-lg-6">
          <label class="col-lg-9 control-label">Boost Played</label>
          <div class="col-lg-3">
            <input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}BoostPlayed">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Parks</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}Parks">
          </div>
        </div>
        <div class="col-lg-6">
          <label class="col-lg-8 control-label">Climbs</label>
          <div class="col-lg-4">
            <input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}Climbs">
          </div>
        </div>
      </div>
    </div>
    <br /><br />
    <legend>Fouls</legend>
    {{"{{#each score.Fouls}}"}}
      <div class="well well-sm well-dark{{"{{../alliance}}"}}">
        <button type="button" class="close" onclick="deleteFoul('{{"{{../alliance}}"}}', {{"{{@index}}"}});">×</button>
        <br />
        <div class="form-group">
          <label class="col-lg-4 control-label">Team</label>
          <div class="col-lg-8">
            <div class="radio col-lg-3">
              <label>
                <input type="radio" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}Team" value="{{"{{../team1}}"}}">
                {{"{{../team1}}"}}
               </label>
            </div>
            <div class="radio col-lg-3">
              <label>
                <input type="radio" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}Team" value="{{"{{../team2}}"}}">
                {{"{{../team2}}"}}
              </label>
            </div>
            <div class="radio col-lg-3">
              <label>
                <input type="radio" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}Team" value="{{"{{../team3}}"}}">
                {{"{{../team3}}"}}
              </label>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-4 control-label">Rule Violated</label>
          <div class="col-lg-3">
            <input type="text" class="form-control input-sm" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}RuleNumber">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-4 control-label">Is Technical</label>
          <div class="col-lg-3">
            <input type="checkbox" class="input-sm" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}IsTechnical">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-4 control-label">Seconds Into Match</label>
          <div class="col-lg-3">
            <input type="text" class="form-control input-sm" name="{{"{{../alliance}}"}}Foul{{"{{@index}}"}}Time">
          </div>
        </div>
      </div>
    {{"{{/each}}"}}
    <button type="button" class="btn btn-default btn-sm" onclick="addFoul('{{"{{alliance}}"}}');">
      Add Foul
    </button>
    <br /><br />
    <legend>Cards</legend>
    <div class="form-group">
      <label class="col-lg-4 control-label">Team {{"{{team1}}"}}</label>
      <div class="col-lg-8">
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team1}}"}}Card" value="" checked>
            None
          </label>
        </div>
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team1}}"}}Card" value="yellow">
            Yellow
          </label>
        </div>
        <div class="radio col-lg-6">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team1}}"}}Card" value="red">
            Red
          </label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="col-lg-4 control-label">Team {{"{{team2}}"}}</label>
      <div class="col-lg-8">
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team2}}"}}Card" value="" checked>
            None
          </label>
        </div>
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team2}}"}}Card" value="yellow">
            Yellow
          </label>
        </div>
        <div class="radio col-lg-6">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team2}}"}}Card" value="red">
            Red
          </label>
        </div>
      </div>
    </div>
    <div class="form-group">
      <label class="col-lg-4 control-label">Team {{"{{team3}}"}}</label>
      <div class="col-lg-8">
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team3}}"}}Card" value="" checked>
            None
          </label>
        </div>
        <div class="radio col-lg-3">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team3}}"}}Card" value="yellow">
            Yellow
          </label>
        </div>
        <div class="radio col-lg-6">
          <label>
            <input type="radio" name="{{"{{alliance}}"}}Team{{"{{team3}}"}}Card" value="red">
            Red
          </label>
        </div>
      </div>
    </div>
  </div>
</div>
{{end}}
{{define "script"}}
<script src="/static/js/match_review.js"></script>
<script>
  var matchId = {{.Match.Id}}
  var allianceResults = {};
  allianceResults["red"] = {alliance: "red", team1: {{.Match.Red1}}, team2: {{.Match.Red2}},
      team3: {{.Match.Red3}}, score: jQuery.parseJSON('{{.MatchResultJson.RedScoreJson}}'),
      cards: jQuery.parseJSON('{{.MatchResultJson.RedCardsJson}}')};
  allianceResults["blue"] = {alliance: "blue", team1: {{.Match.Blue1}}, team2: {{.Match.Blue2}},
      team3: {{.Match.Blue3}}, score: jQuery.parseJSON('{{.MatchResultJson.BlueScoreJson}}'),
      cards: jQuery.parseJSON('{{.MatchResultJson.BlueCardsJson}}')};
  renderResults("red");
  renderResults("blue");
</script>
{{end}}
