<div class="form-g">
	<fieldset>
		<legend>Deployment Options</legend>
		<div>
			<label>Branch:</label><img class="loadingImage" ng-src={{imagePath}} ng-if="loadingBranches">
			<select class="form-control" ng-if="!loadingBranches" data-ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.gitSource.branch" ng-change="updateGitBranch(oneSrv, oneEnv, version)" ng-required="true">
				<option ng-repeat="myBranch in branches" value="{{myBranch.name}}">
					{{myBranch.name}}
				</option>
			</select>
			<br/><br/>
		</div>
		<div>
			<label>Memory Limit Per Instance (in MBytes)</label>
			<input type="number" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.memoryLimit" ng-required="true"/>
			<label class="fieldMsg">
				Specify the Maximum memory limit (in Megabytes) that should be provided when deploying your service/daemon.<br />
				You can use 0 if you want the deployment to use elastic memory from the node where it will be deployed in.
			</label>
			<br/>
		</div>
		<div ng-if="isKubernetes">
			<label>CPU Limit Per Instance</label>
			<input type="text" class="form-control" placeholder="100m or 0.1" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.cpuLimit" ng-required="autoScale"/>
			<label class="fieldMsg">Specify the Maximum cpu limit (in millicpu or decimal point) that should be provided
				when running your service/daemon. Click
				<a href="https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu" target="_blank">here </a>for
				more information.</label>
			<br/>
		</div>
		<div>
			<label>Catalog Recipe</label><img class="loadingImage" ng-src={{imagePath}} ng-if="loadingRecipes">
			<select class="form-control" ng-if="!loadingRecipes" ng-required="true" ng-disabled="deployed" ng-options="recipe._id as recipe.name group by recipe.type for recipe in myRecipes" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.recipe" ng-change="injectCatalogEntries(oneEnv, version, oneSrv, true)"></select>
			<label class="fieldMsg">Choose a catalog recipe and define the deployment strategy in this
				environment.</label>
			<br>
		</div>
		
		<div ng-include="'modules/dashboard/environments/directives/list-repos-catalogInputs.tmpl'"></div>
	</fieldset>
	
	<div ng-if="catalogConflictingPorts !== ''">
		<alert type='danger'>Unable to proceed, Detected port conflict in Catalog recipe: {{catalogConflictingPorts}}</alert>
	</div>
	<div ng-if="catalogConflictingPorts === ''">
		<fieldset class="custom-fieldset" ng-if="sourceCodeConfig.configuration.isEnabled">
			<legend>{{selectedSourceCode.configuration.label}}</legend>
			<div>
				<label>Repository</label>
				<select class="form-control" ng-required="sourceCodeConfig.configuration.repoAndBranch.required" ng-options="repo.name as repo.name group by repo.owner for repo in configRepos.config" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo" ng-change="fetchBranches(oneEnv, version, oneSrv,'conf')" ng-disabled="sourceCodeConfig.configuration.repoAndBranch.disabled"></select>
				<label class="fieldMsg">Choose your repository</label>
				<br>
			</div>
			
			<div ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo !== '-- Leave Empty --'">
				<label>Branch<img class="loadingImage" ng-src="themes/default/img/loading.gif" ng-if="configReposBranchesStatus[cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo]==='loading'"></label>
				<select class="form-control" ng-required="sourceCodeConfig.configuration.repoAndBranch.required" ng-options="branch.name as branch.name for branch in configReposBranches[cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo]" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.branch" ng-disabled="sourceCodeConfig.configuration.repoAndBranch.disabled"></select>
				<label class="fieldMsg">Choose your branch</label>
				<br>
			</div>
			
			<div ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.repo !== '-- Leave Empty --'">
				<label>Path</label>
				<input type="text" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.sourceCode.configuration.path" ng-required="false"/>
				<label class="fieldMsg">Unless specified, the root will be used</label>
			</div>
		</fieldset>
		<fieldset  ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.ports && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].publishPorts">
			<legend>Published Ports</legend>
			<div ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.loadBalancer">
				<label class="f-left" >Load Balancer</label>
				<label class="toggleSwitch f-left"><input type="checkbox" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.loadBalancer" ng-value ="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.loadBalancer" ng-disabled=true><span class="buttonSlider round"></span></label>
				<label class="fieldMsg">This recipe allows LoadBalancer port configuration only.</label>
				<br /><br/>
			</div>
			<div ng-if="!cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.loadBalancer" ng-repeat="exposedPorts in cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.ports track by exposedPorts.target">
				<fieldset ng-if="exposedPorts.isPublished || exposedPorts.published">
					<legend class="capitalize">{{exposedPorts.name}} : {{exposedPorts.target}}</legend>
					<div >
						<label>Published Port</label>
						<input type="number" class="form-control" ng-model="exposedPorts.published" ng-disabled="false" min="1" max="2767" ng-required="true"/>
						<label class="fieldMsg">Detected Published Port <b>{{exposedPorts.name}}</b> with internal value <b>{{exposedPorts.target}}</b>.
							Enter a value if you want to expose this resource to a specific port; Port values are limited to a range between 0 and 2767.
						</label>
					</div>
				</fieldset>
				<br>
			</div>
		</fieldset>
		
		<fieldset ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.allowExposeServicePort">
			<legend>Port(s)
			</legend>
			<div style="width: 30%!important;float: left;">
				<label class="switch"><input type="checkbox" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.exposeServicePort"><span class="buttonSlider round f-left"></span></label>
			</div>
			<div style="width: 60%!important;float: left;margin-top: 8px;">
				<label class="f-left fieldMsg">This recipe allows port(s) to be exposed externally.
				</label>
			</div>
			<div ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.exposeServicePort">
				<label ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.exposeServicePort">Value</label>
				<input ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.exposeServicePort" type="number" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.exposeServicePortValue" ng-disabled="false" min="1" max="2767" ng-required="true"/>
				<label class="fieldMsg">Enter a value if you want to expose this resource to a specific port;
					Port values are limited to a range between 0 and 2767 (please note that kubernetes add 30,000 to the port).
				</label>
			</div>
			<br/>
		</fieldset>
		
		<fieldset class="repos" ng-if="secrets && secretsAllowed !=='none'">
			<legend>Secret</legend>
			<div>
				<ui-select multiple theme="bootstrap" ng-model= "cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.secrets" close-on-select="false" title="Choose a Secret"  close-on-select="true" ng-required="secretsAllowed === 'required'">
					<ui-select-match placeholder="Select secret...">{{$item.name}}</ui-select-match>
					<ui-select-choices repeat="secret in secrets | filter: {name: $select.search}">
						<div ng-bind-html="secret.name | highlight: $select.search"></div>
						<small>
							id: {{secret.uid}}
						</small>
					</ui-select-choices>
				</ui-select>
			</div>
			<div class= "f-left" style="width: 100%">
				<fieldset ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.secrets && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.secrets.length > 0" >
					<legend>Mount Path</legend>
					<div ng-repeat="secret in cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.custom.secrets">
						<label class = "secretMountPathRepo" >{{secret.name}}</label><br />
						<input type="text" class="form-control secretMountPathRepo" ng-model="secret.mountPath" ng-disabled="false" ng-required="true"/>
						<label class="fieldMsg">Provide a mount path for your secret. Mount path are used from within the containers.</label>
						<br /><br/>
					</div>
				</fieldset>
			</div>
		</fieldset>
		
		<fieldset>
			<legend>Environment Scaling</legend>
			<div>
				<label>Deployment Mode</label>
				<select class="form-control" ng-disabled="deployed" ng-required="true" ng-options="mode for mode in deploymentModes" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode"></select>
				<label class="fieldMsg">Global/Daemonset mode deploys one replica of the service on each node.</label>
				<label class="fieldMsg">Replicated/Deployment mode deploys the specified number of replicas based on the
					availability of resources.</label>
				<br>
			</div>
			
			<alert type="info" ng-if="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode === 'daemonset'">Daemonsets do not support autoscaling.</alert>
			<fieldset ng-if="isAutoScalable && cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode === 'deployment'">
				<legend>Auto Scale<label class="switch"><input type="checkbox" ng-model="autoScale" ng-click="activateAutoScale()"><span class="buttonSlider round"></span></label>
				</legend>
				<fieldset ng-if="!autoScale && (cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode == 'replicated' || cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode == 'deployment')">
					<legend>Replication</legend>
					<label>Replica Count</label>
					<input type="number" ng-disabled="deployed" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.replicas" ng-required="true" style="margin-right:0"/>
					<label class="fieldMsg">Enter a Replica Count that is greater or equal to 1</label>
					<br>
				</fieldset>
				<fieldset ng-if="autoScale">
					<legend>Metrics</legend>
					<div>
						<label>CPU</label>
						<input type="number" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.autoScale.metrics.cpu.percent" ng-required="true"/>
						<label class="fieldMsg">Enter CPU percentage</label>
						<br>
					</div>
				</fieldset>
				<fieldset ng-if="autoScale">
					<legend>Replicas</legend>
					<div>
						<label>min</label>
						<input type="number" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.autoScale.replicas.min" ng-required="true"/>
						<label class="fieldMsg">Enter minimum Replica Count that is greater or equal to 1</label>
						<br>
					</div>
					<div>
						<label>max</label>
						<input type="number" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.autoScale.replicas.max" ng-required="true"/>
						<label class="fieldMsg">Enter maximum Replica Count that is greater or equal to 1</label>
						<br>
					</div>
				</fieldset>
			</fieldset>
		</fieldset>
		<fieldset ng-if="!isAutoScalable && !autoScale && (cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode == 'replicated' || cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.mode == 'deployment')">
			<legend>Replication</legend>
			<label>Replica Count</label>
			<input type="number" ng-disabled="deployed" class="form-control" ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.deployConfig.replication.replicas" ng-required="true"/>
			<label class="fieldMsg">Enter a Replica Count that is greater or equal to 1</label>
			<br>
		</fieldset>
		<fieldset ng-if="showCD">
			<legend>Continuous Delivery</legend>
			<div class="halfPage branchLabel">
				<label>Branch:</label>&nbsp;{{cdConfiguration[oneSrv][oneEnv].cdData.versions[version].options.gitSource.branch}}
			</div>
			<div class="halfPage branchLabel">
				<label>Strategy:</label>
				<select class="form-control" ng-required="true" data-ng-model="cdConfiguration[oneSrv][oneEnv].cdData.versions[version].strategy">
					<option value="notify">notify</option>
					<option value="update">update</option>
				</select>
			</div>
		</fieldset>
	</div>
</div>
<script type="text/ng-template" id="portConfiguration.tmpl">
	<div class="modal-header">
		<h3 class="modal-title">{{title}}</h3>
	</div>
	<div class="modal-body">
		<alert type="danger">{{message}}</alert>
	</div>
	<div class="modal-footer">
		<button class="btn btn-primary" ng-click="closeModal()">Cancel</button>
	</div>
</script>
