@php use App\Models\Sla; use Illuminate\Support\Facades\DB; @endphp

<script type="text/ng-template" id="clients/modals/edit-client.html">
	<div id="client-edit-modal-header" class="modal-header">
		<h3>Edit client</h3>
	</div>
	<form id="client-edit-form" name="clientForm" class="basic-form" ng-submit="save()">
		<div class="modal-body">
			<div class="row">
				<div class="col-sm-5">

					<input type="hidden" name="id" ng-model="data.id">

					<fieldset>
						<legend>Basic Details</legend>
						<div class="control-group col-sm-12">
							<label for="name" class="control-label col-sm-2">Name</label>
							<div class="controls col-sm-7 pull-right">
								<input type="text" name="name" ng-model="data.name" required class="form-control">
							</div>
						</div>

						<div class="control-group col-sm-12">
							<label for="sla" class="control-label col-sm-2">SLA</label>
							<div class="controls col-sm-7 pull-right">
								<select name="sla" ng-model="data.sla_id" class="form-control">
									<option value="">-- No SLA --</option>
									@foreach(Sla::all() as $sla)
										<option value="{{ $sla->id }}">{{ $sla->name }}</option>
									@endforeach
								</select>
							</div>
						</div>
						<div class="control-group col-sm-12">
							<label for="website" class="control-label col-sm-2">Website</label>
							<div class="controls col-sm-7 pull-right">
								<input type="text" name="website" ng-model="data.website" class="form-control">
							</div>
						</div>
					</fieldset>

					<fieldset id="contract-details-fieldset">
						<legend>Contract Details</legend>
						<div class="control-group col-sm-12">
							<label for="contract" class="control-label col-sm-2">Contract</label>
							<div class="controls col-sm-7 pull-right">
								<select name="contract" ng-model="data.contract_id" class="form-control">
									<option value="">-- No Contract --</option>
									@foreach(App\Models\Contract::all() as $contract)
										<option value="{{ $contract->id }}">{{ $contract->name }}</option>
									@endforeach
								</select>
							</div>
						</div>
						<div ng-show="data.contract_id">
							<div class="control-group col-sm-12">
								<label for="contract_price" class="control-label col-sm-2">Contract price</label>
								<div class="controls col-sm-7 pull-right">
									<input type="text" name="contract_price" ng-model="data.contract_price" class="form-control">
								</div>
							</div>
							<div class="control-group col-sm-12">
								<label for="contract_start_date" class="control-label col-sm-2">Contract start date</label>
								<div class="controls col-sm-7 pull-right">
									<input type="text" name="contract_start_date" ng-model="data.contract_start_date" class="form-control" placeholder="dd-mm-yyyy">
								</div>
							</div>
							<div class="control-group col-sm-12">
								<label for="contract_end_date" class="control-label col-sm-2">Contract end date</label>
								<div class="controls col-sm-7 pull-right">
									<input type="text" name="contract_end_date" ng-model="data.contract_end_date" class="form-control" placeholder="dd-mm-yyyy">
								</div>
							</div>
						</div>
					</div>
				</fieldset>

			<div class="col-sm-5 col-sm-offset-1">
				<fieldset>
					<legend>Site Details</legend>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-tag fa-fw"></i></span>
						<input type="text" name="name" ng-model="site.name" required class="form-control col-sm-11" placeholder="Name">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-home fa-fw"></i></span>
						<input type="text" name="address" ng-model="site.address" class="form-control col-sm-11" placeholder="Address Line 1">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-home fa-fw"></i></span>
						<input type="text" name="address2" ng-model="site.address2" class="form-control col-sm-11" placeholder="Address Line 2">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-map-marker fa-fw"></i></span>
						<input ng-model="site.postcode" required="required" class="form-control col-sm-11" placeholder="Postcode" name="postcode" type="text" value="">
						<span class="input-group-addon" ng-click="lookupPostcode(site.postcode)" title="Find the address"><i ng-class="postcode.icon" class="fa fa-crosshairs fa-fw text-primary"></i></span>
					</div>
				</fieldset>

				<fieldset>
					<legend id="site-user-legend">Site User Details</legend>

					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-tag fa-fw"></i></span>
						<input type="text" name="first_name" ng-model="site_user.first_name" required class="form-control col-sm-11" placeholder="First Name">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-tag fa-fw"></i></span>
						<input type="text" name="last_name" ng-model="site_user.last_name" required class="form-control col-sm-11" placeholder="Last Name">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
						<input type="email" name="email" ng-model="site_user.email" required class="form-control col-sm-11" placeholder="Email address">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-phone fa-fw"></i></span>
						<input type="text" name="phone" ng-model="site_user.phone" class="form-control col-sm-11" placeholder="Telephone">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-mobile fa-fw"></i></span>
						<input type="text" name="mobile" ng-model="site_user.mobile" class="form-control col-sm-11" placeholder="Mobile phone">
					</div>
					<div class="input-group margin-bottom-sm">
						<span class="input-group-addon"><i class="fa fa-dot-circle-o fa-fw"></i></span>
						<input type="text" name="position" ng-model="site_user.position" class="form-control col-sm-11" placeholder="Position within the company">
					</div>
					<div class="input-prepend col-sm-12">
						<label class="checkbox inline">
							<input type="checkbox" name="authority" ng-model="site_user.authority" ng-checked="site_user.authority == '1'"> Tick if the user has authority
						</label>
					</div>
				</fieldset>
			</div>
		</div>
	</div>
	<div class="modal-footer">
		<button class="btn" ng-click="cancel()">Cancel</button>
		<button class="btn btn-primary">Save changes</button>
	</div>
</form>
</script>
