<div class="modal-header">
	<div class="pull-left">
		<h3 class="modal-title">
			{{ 'tsrdTitle' | translate }}
		</h3>
	</div>
	<div class="pull-right">
		<span>
			<i ng-show="model.isAvailable" class="fa fa-check-circle fa-2x text-success text-right" aria-hidden="true" tooltip="{{ 'available' | translate }}"></i>
			<i ng-hide="model.isAvailable" class="fa fa-times-circle fa-2x text-danger text-right" aria-hidden="true" tooltip="{{ 'unavailable' | translate }}"></i>
		</span>
	</div>
	<div class="clearfix"></div>
</div>
<div class="modal-body">
	<div class="row" ng-hide="model.isAvailable">
		<div class="col-md-12">
			<div class="alert alert-danger text-center">
				{{ 'unavailable' | translate }}
			</div>
		</div>
	</div>

	<form class="form-horizontal" role="form">

		<!-- Id -->
		<div class="form-group">
			<label class="col-sm-4 control-label">Id</label>
			<div class="col-sm-8">
				<p class="form-control-static">{{ model.id }}</p>
			</div>
		</div>

		<!-- Name (editable) -->
		<lacuna-editable-item description="{{ 'tsrdTooltipName' | translate }}" on-save="save(key, value)" on-edit="edit('name')">
			<item-label>{{ 'name' | translate }}</item-label>
			<item-value>{{ model.name }}</item-value>
			<item-editor>
				<input type="text" class="form-control" ng-model="$editor.data.value">
			</item-editor>
		</lacuna-editable-item>

		<!-- URL (editable) -->
		<lacuna-editable-item description="{{ 'tsrdTooltipUrl' | translate }}" on-save="save(key, value)" on-edit="edit('url')">
			<item-label>{{ 'url' | translate }}</item-label>
			<item-value class="text-primary">{{ model.url }}</item-value>
			<item-editor>
				<input type="text" class="form-control" ng-model="$editor.data.value">
			</item-editor>
		</lacuna-editable-item>

		<!-- TSA Policy ID (editable) -->
		<lacuna-editable-item description="{{ 'tsrdTooltipPolicyId' | translate }}" on-save="save(key, value)" on-edit="edit('tsaPolicyId')">
			<item-label>{{ 'tsrdPolicyId' | translate }}</item-label>
			<item-value class="text-primary">{{ model.tsaPolicyId }}</item-value>
			<item-editor>
				<input type="text" class="form-control" ng-model="$editor.data.value">
			</item-editor>
		</lacuna-editable-item>

		<!-- Authentication Method (editable) -->
		<lacuna-editable-item description="{{ 'tsrdTooltipAuthMethod' | translate }}" on-save="save(key, value)" on-edit="edit('authenticationMethod')">
			<item-label>{{ 'tsrdAuthMethod' | translate }}</item-label>
			<item-value>{{ 'tsrAuth_' + model.authenticationMethod | translate }}</item-value>
			<item-editor>
				<select class="form-control" ng-options="method as ('tsrAuth_' + method | translate) for method in authMethods" ng-model="$editor.data.value"></select>
			</item-editor>
		</lacuna-editable-item>

		<!-- Authentication Parameters -->
		<div ng-switch="model.authenticationMethod" ng-hide="$editor.data.key == 'authenticationMethod'">

			<!-- Mutual SSL -->
			<div ng-switch-when="MutualSSL">
				<lacuna-editable-item description="{{ 'tsrdTooltipAuthCertificate' | translate }}" on-save="saveCertificate(value)" on-edit="editCertificate()">
					<item-label>{{ 'tsrdAuthCertificate' | translate }}</item-label>
					<item-value>{{ displaySslCertificate(model.sslCertificate) || ('tsrdNoCertificate' | translate) }}</item-value>
					<item-editor>
						<select class="form-control" ng-options="cert as displaySslCertificate(cert) for cert in certificates track by cert.thumbprint" ng-model="$editor.data.value"></select>
					</item-editor>
				</lacuna-editable-item>
			</div>

			<!-- Basic HTTP (editable) -->
			<div ng-switch-when="Basic">
				<lacuna-editable-item description="{{ 'tsrdTooltipBasicCredentials' | translate }}" on-save="saveCredentials($editor.data)" on-edit="editCredentials()">
					<item-label>{{ 'tsrdBasicCredentials' | translate }}</item-label>
					<item-value>{{ model.basicUsername }}</item-value>
					<item-editor>
						<input type="text" class="form-control" ng-model="$editor.data.username" placeholder="{{ 'username' | translate }}" ng-hide="$editor.data.userOk">
						<input type="password" class="form-control" ng-model="$editor.data.password" placeholder="{{ 'password' | translate }}" ng-show="$editor.data.userOk">
					</item-editor>
				</lacuna-editable-item>
			</div>

			<!-- OAuth Token (editable) -->
			<div ng-switch-when="OAuthBearerToken">
				<lacuna-editable-item description="{{ 'tsrdTooltipOAuthToken' | translate }}" on-save="saveOAuth(value)" on-edit="editOAuth()">
					<item-label>{{ 'tsrdOAuthToken' | translate }}</item-label>
					<item-value><em class="text-muted">{{ 'hidden' | translate }}</em></item-value>
					<item-editor>
						<input type="text" class="form-control" ng-model="$editor.data.value" placeholder="{{ 'token' | translate }}">
					</item-editor>
				</lacuna-editable-item>
			</div>

		</div>


		<!-- TSA Certificate -->
		<div class="form-group">
			<label class="col-sm-4 control-label">
				<span class="glyphicon glyphicon-question-sign" tooltip="{{ 'tsrdTooltipTsaCertficate' | translate }}"></span>
				{{ 'tsrdTsaCertificate' | translate }}
			</label>
			<div class="col-sm-8">
				<p class="form-control-static">
					<button class="btn btn-xs btn-info" ng-click="showTsaCertificate()">{{ 'view' | translate }}</button>
				</p>
			</div>
		</div>

		<!-- Enabled (editable) -->
		<lacuna-editable-item description="{{ 'tsrdTooltipIsEnabled' | translate }}" on-save="save(key, value)" on-edit="edit('isEnabled')">
			<item-label>{{ 'enabled' | translate }}</item-label>
			<item-value>{{ (model.isEnabled).toString() | translate }}</item-value>
			<item-editor>
				<select class="form-control" ng-options="option as ((option).toString() | translate) for option in [true, false]" ng-model="$editor.data.value"></select>
			</item-editor>
		</lacuna-editable-item>
	</form>
</div>
<div class="modal-footer">
	<button class="btn btn-danger pull-left" ng-click="remove()">{{ 'remove' | translate }}</button>
	<button class="btn btn-info pull-left" ng-click="testRequest()">{{ 'test' | translate }}</button>
	<button class="btn btn-primary" ng-click="close()">{{ 'close' | translate }}</button>
</div>
