<script type="text/ng-template" id="deploy_modal.html">
	<div class="modal-header">
		<h3 class="modal-title">Deploy {{branch}} to {{environment}}</h3>
	</div>
	<div class="modal-body">
		<form ng-submit="ok()">
			<p>Should support or oncall know anything about this deploy? (optional)</p>
			<input autofocus type="text" style="width:100%" ng-model="settings.description">
		</form>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" ng-click="ok()">Ship it</button>
		<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
	</div>
</script>

<div class="alert alert-warning" ng-show="repos.settings_exist == false">deploy.json not found! <a href="" ng-click="write_default_config()">Create it now.</a></div>
<div class="alert alert-warning" ng-show="repos.settings != null && deployments.environments.length == 0">No deploy environments defined in deploy.json!</div>

<div class="container">
	<div class="row">
		<div class="col-md-7">
			<div ng-repeat="item in repos.settings.deploy.graphite_items" style="display:inline-block; width:{{repos.settings.deploy.graphite_width}}px; overflow:hidden;">
				<a href="{{item.link_url}}" target="_blank">
					<img class="graphite_chart" ng-src="{{item.url}}" data-original-src="{{item.url}}">
					<div style="font-size:80%; margin-right:15px; direction:rtl">{{item.target}}</div>
				</a>
			</div>
		</div>
	</div>
</div>

<h3>Release Candidates</h3>

<div class="container candidates">
	<div class="row" ng-repeat="candidate in candidates.current">
		<div class="col-md-5 name">
			<h3>{{candidate.branch}} <a ng-click="toggle_previous_candidates(candidate.branch)"><span class="caret"></span></a> <img ng-show="previous_loading[candidate.branch] == true" ng-src="/img/ajax-loader.gif"></h3>
			<p>
				<span ng-show="state_classes(candidate.state).indexOf('unknown') == -1">
					<a tooltip-placement="right" tooltip="{{candidate.description}}" href="{{candidate.target_url}}"><span ng-class="state_classes(candidate.state)" style="width: 14px;"></span></a>
				</span>
				<span ng-show="state_classes(candidate.state).indexOf('unknown') != -1" ng-class="state_classes(candidate.state)" style="width: 14px;"></span>
				Last updated <span am-time-ago="candidate.date" title="{{candidate.date}}"></span> by {{candidate.author.login}}
			</p>
		</div>
		<div class="col-md-4">
			<div class="dropdown" ng-show="deployments.environments.length > 0">
				<button class="btn btn-default" data-toggle="dropdown">Deploy to <span class="caret"></span></button>
				<ul class="dropdown-menu">
					<li ng-class="deployable_classes(candidate.state)" ng-repeat="env in deployments.environments"><a href="" ng-click="deploy(candidate.branch, candidate.branch, env)">{{env}}</a></li>
				</ul>
			</div>
		</div>
		<div class="col-md-12" ng-show="previous_panel == candidate.branch && previous_candidates[candidate.branch].length > 0">

			<div class="container">
				<div class="row previous_candidate" ng-repeat="previous_candidate in previous_candidates[candidate.branch]">

					<div class="col-md-5">
						<span class="octicon octicon-git-commit"></span>
						<h3><a href="https://git-aws.internal.justin.tv/{{owner}}/{{repo}}/commit/{{previous_candidate.sha}}">{{previous_candidate.commit.message | first_line}}</a></h3>
						<p>
							<span ng-show="state_classes(previous_candidate.state).indexOf('unknown') == -1">
								<a tooltip-placement="right" tooltip="{{previous_candidate.description}}" href="{{previous_candidate.target_url}}"><span ng-class="state_classes(previous_candidate.state)" style="width: 14px;"></span></a>
							</span>
							<span ng-show="state_classes(previous_candidate.state).indexOf('unknown') != -1" ng-class="state_classes(previous_candidate.state)" style="width: 14px;"></span>
							Committed <span am-time-ago="previous_candidate.commit.committer.date" title="{{previous_candidate.commit.committer.date}}"></span> by {{previous_candidate.commit.committer.name}}
						</p>
					</div>

					<div class="col-md-4">
						<div class="dropdown" ng-show="deployments.environments.length > 0">
							<button class="btn btn-default" data-toggle="dropdown">Deploy to <span class="caret"></span></button>
							<ul class="dropdown-menu">
								<li ng-class="deployable_classes(previous_candidate.state)" ng-repeat="env in deployments.environments"><a href="" ng-click="deploy(candidate.branch, previous_candidate.sha, env)">{{env}}</a></li>
							</ul>
						</div>
					</div>
				</div>

			</div>

		</div>
	</div>