<form id='repairsForm' name='repairsForm' ng-submit="form.save()" class="form-horizontal form-edit" confirm-on-exit>
			@include('bookings::templates.bookings_projects_header')
	@csrf

			@include('bookings::templates.location')

			<div customer-prebooks></div>
			<div customer-devices="data.devices" data-task="data"></div>

			<h4 class="subheader">Repair Information</h4>
			<div class="form-group checkboxes">
				<label for="return" class="col-sm-3 control-label">Is this a return:</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" name="return" value="1" ng-model="return"> Yes
					</label>
					<label class="radio-inline">
						<input type="radio" name="return" value="0" ng-model="return" ng-init="return = 0"> No
					</label>
				</div>
			</div>
			<div class="form-group" ng-show="return==1">
				<label for="return_id" class="col-sm-3 control-label label-required">Old job ID:</label>
				<div class="col-sm-9">
					<input type="text" name="return_id" ng-model="data.return_id" arch-change="validateTaskId(data.return_id)" ng-disabled="data.return == 0" ng-required="data.return == 1" autocomplete="off" class="form-control">
					<span ng-show="invalid_task_id">
						<i class="fa fa-exclamation-triangle"></i> This job id does not exist!
					</span>
				</div>
			</div>
			<div class="form-group checkboxes">
				<label for="prebook" class="col-sm-3 control-label">Prebook:</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" name="prebook" value="1" ng-model="data.prebook"> Yes
					</label>
					<label class="radio-inline">
						<input type="radio" name="prebook" value="0" ng-model="data.prebook" ng-init="data.prebook = 0"> No
					</label>
				</div>
			</div>
			<div class="form-group" ng-show="data.prebook==1" >
				<label for="prebook_date" class="col-sm-3 control-label label-required">Prebook Date:</label>
				<div class="col-sm-9">
					<div class="input-group">
						<input type="text" name="prebook_date" ng-model="data.prebook_date" class="form-control" bs-datepicker ng-required="data.prebook == 1" data-format="dd-mm-yyyy" autocomplete="off">
						<span class="input-group-btn">
							<button type="button" class="btn btn-default" data-toggle="datepicker"><i class="fa fa-calendar"></i></button>
						</span>
					</div>
				</div>
			</div>
			<div class="form-group checkboxes">
				<label for="needs_pickup" class="col-sm-3 control-label label-required">Needs Pickup:</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" name="needs_pickup" value="1" ng-model="data.needs_pickup" ng-change="data.needs_pickup == '1' && !data.pickup_by ? data.pickup_by = '{{ Auth::id() }}' : null" required> Yes
					</label>
					<label class="radio-inline">
						<input type="radio" name="needs_pickup" value="0" ng-model="data.needs_pickup" required> No
						<span ng-if="! clientManager.isClient()"><span ng-init="data.needs_pickup = 0"></span></span>
					</label>
				</div>
			</div>
			<div class="form-group" ng-show="data.needs_pickup == '1'">
				<label for="pickup_by" class="col-sm-3 control-label label-required">Who will pickup:</label>
				<div class="col-sm-9">
					<select name="pickup_by" ng-model="data.pickup_by" ng-required="data.needs_pickup == '1'" class="form-control">
						<option value="">Select User</option>
						@foreach(App\Models\User::getActiveList()->pluck('name', 'id') as $id => $name)
							<option value="{{ $id }}">{{ $name }}</option>
						@endforeach
					</select>
				</div>
			</div>
			<div class="form-group checkboxes">
				<label for="needs_delivery" class="col-sm-3 control-label label-required">Needs Delivery Back:</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" name="needs_delivery" value="1" ng-model="data.needs_delivery" ng-change="data.needs_delivery == '1' && !data.delivered_by ? data.delivered_by = '{{ Auth::id() }}' : null" required> Yes
					</label>
					<label class="radio-inline">
						<input type="radio" name="needs_delivery" value="0" ng-model="data.needs_delivery" required> No
						<span ng-if="! clientManager.isClient()"><span ng-init="data.needs_delivery = 0"></span></span>
					</label>
				</div>
			</div>
			<div class="form-group" ng-show="data.needs_delivery == '1'">
				<label for="delivered_by" class="col-sm-3 control-label label-required">Who will deliver:</label>
				<div class="col-sm-9">
					<select name="delivered_by" ng-model="data.delivered_by" ng-required="data.needs_delivery == '1'" class="form-control">
						<option value="">Select User</option>
						@foreach(App\Models\User::getActiveList()->pluck('name', 'id') as $id => $name)
							<option value="{{ $id }}">{{ $name }}</option>
						@endforeach
					</select>
				</div>
			</div>
			<div class="form-group checkboxes">
				<label for="has_password" class="col-sm-3 control-label label-required">Is there a password?:</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" name="has_password" value="1" ng-model="data.has_password" required> Yes
					</label>
					<label class="radio-inline">
						<input type="radio" name="has_password" value="0" ng-model="data.has_password" required> No
					</label>
				</div>
			</div>
			<div class="form-group" ng-show="data.has_password=='0'">
				<label for="nopassword_reason" class="col-sm-3 control-label label-required">Reason for not having a password:</label>
				<div class="col-sm-9">
					<input type="text" name="nopassword_reason" ng-model="data.nopassword_reason" class="form-control" ng-required="data.has_password == '0'">
				</div>
			</div>
			<span ng-init="data.keychains=[]"></span>
			<div data-booking-passwords task='data' ng-show="data.has_password=='1'"></div>

			<div class="form-group">
				<label for="standard_price_id" class="col-sm-3 control-label label-required">Repair type:</label>
				<div class="col-sm-9">
					<select name="standard_price_id" ng-model="data.standard_price_id" class="form-control" required>
						<option value="">Select Repair Type</option>
						@foreach(App\Models\StandardPrice::all()->pluck('name', 'id') as $id => $name)
							<option value="{{ $id }}">{{ $name }}</option>
						@endforeach
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="selected_templates" class="col-sm-3 control-label">Templates:</label>
				<div class="col-sm-9">
					<div class="templateSelector row">
						<div ng-repeat="(listName, list) in templates.lists" class="col-sm-6 ng-scope">
							<div  class="panel panel-default">
								<div class="panel-heading">
									<strong style="font-size:12px">{[{ listName }]}</strong>
								</div>
								<div class="panel-body ng-scope">
									<ul dnd-list="list" class="ng-scope">
										<li ng-repeat="item in list"
									        dnd-selected="templates.selected = item"
									        ng-class="{'selected': templates.selected === item}"
									        ng-click="changeOfList(listName, $index)"
									        >
									        {[{ item.name }]}
									    </li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>


			<div class="form-group">
				<label for="assigned_to" class="col-sm-3 control-label">Assign to:</label>
				<div class="col-sm-9">
					<select name="assigned_to" ng-model="data.assigned_to" class="form-control">
						<option value="">Select User</option>
						@foreach(App\Models\User::getActiveList()->pluck('name', 'id') as $id => $name)
							<option value="{{ $id }}">{{ $name }}</option>
						@endforeach
					</select>
					&nbsp; <span class="label label-info" ng-if="clientManager.client.id" ng-click="data.assigned_to = clientManager.client.suggested_user.id">Suggested user: {[{ clientManager.client.suggested_user.name }]}</span>
				</div>
			</div>


			<h4 class="subheader">Problem Description</h4>
			<div class="form-group">
				<label for="severity_id" class="col-sm-3 control-label label-required">Severity:</label>
				<div class="col-sm-9">
					<select name="severity_id" ng-model="data.severity_id" class="form-control" required>
						<option value="">Select Severity</option>
						@foreach($severities_dropdown as $value => $label)
							<option value="{{ $value }}">{{ $label }}</option>
						@endforeach
					</select>
				</div>
			</div>
			<div class="form-group">
				<label for="title" class="col-sm-3 control-label label-required">Title:</label>
				<div class="col-sm-9">
					<input type="text" name="title" ng-model="data.title" class="form-control" required>
				</div>
			</div>
			<div class="form-group">
				<label for="problem" class="col-sm-3 control-label label-required">Problem:</label>
				<div class="col-sm-9">
					<textarea name="problem" ng-model="data.problem" summernote summernote-height="200"></textarea>
				</div>
			</div>

	<div class="alert alert-warning" ng-if="! formIsValid()">
		<p class="lead"><i class="fa fa-warning"></i> The following are required before saving the job:</p>
		<ul>
			<li ng-if="!clientManager.isSelected()">You need to select a customer from the left hand side.</li>
			<li ng-if="!data.devices || data.devices.length == 0">You need to add/select at least one device.</li>
			<li ng-if="!data.title || data.title.trim() === ''">Title is required.</li>
			<li ng-if="!data.problem || data.problem.trim() === ''">Problem description is required.</li>
			<li ng-if="!data.severity_id">Severity is required.</li>
			<li ng-if="data.needs_pickup === undefined || data.needs_pickup === null || data.needs_pickup === ''">Please specify if pickup is needed.</li>
			<li ng-if="data.needs_pickup == '1' && (!data.pickup_by)">Please select who will pickup when pickup is needed.</li>
			<li ng-if="data.needs_delivery === undefined || data.needs_delivery === null || data.needs_delivery === ''">Please specify if delivery is needed.</li>
			<li ng-if="data.needs_delivery == '1' && (!data.delivered_by)">Please select who will deliver when delivery is needed.</li>
			<li ng-if="data.has_password === undefined || data.has_password === null || data.has_password === ''">Please specify if there is a password.</li>
			<li ng-if="data.has_password == '0' && (!data.nopassword_reason || data.nopassword_reason.trim() === '')">Please provide reason for not having a password.</li>
			<li ng-if="data.has_password == '1' && (!data.keychains || data.keychains.length == 0)">Please enter at least one password when password is required.</li>
			<li ng-if="!data.standard_price_id">Repair type is required.</li>
			<li ng-if="data.prebook == '1' && (!data.prebook_date)">Please select prebook date when prebook is enabled.</li>
		</ul>
	</div>


	<div class="form-actions">
		<input type="hidden" name="client_id" ng-model="data.client_id" required>

		<button class="btn btn-primary" data-loading-text="Saving..." ng-click="showPrintView()" ng-disabled="!formIsValid()">
			<i class="fa fa-print"></i> Save and Print
		</button>
		<div class="btn-group">
			<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#" eat-click>
				<i class="fa fa-cog"></i>
				<span class="caret"></span>
			</a>
			<ul class="dropdown-menu pull-right text-left">
				<!-- dropdown menu links -->
				<li ng-class="{disabled: !formIsValid()}"><a tabindex="-1" href="#" ng-click="form.saveOnly()" eat-click>Save</a></li>
			</ul>
		</div>
	</div>

</form>

{{-- Modal of a print view --}}
<div modal="modal.showPrintView" modal-options="opts" custom-class="container">
    <div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		<h3><i class="fa fa-paperclip"></i> Booking in sheet</h3>
	</div>
	<div class="modal-body" ng-controller="BookingsRepairCtrl">
		{{-- <iframe ng-src="{!! URL::action('App\Modules\Bookings\BookingsController@getConfirmationSheet') !!}/{[{ modal.id }]}" style="zoom:0.60" width="99.6%" frameborder="0" iframe-autoheight></iframe>--}}
	</div>
	<div class="modal-footer" ng-controller="BookingsRepairCtrl">
		<button class="btn btn-primary" ng-click="redirectToSales()">Create Sales Receipt</button>
		<button class="btn" data-dismiss="modal">Close</button>
	</div>
</div>
<script type="text/ng-template" id="bookings/passwords.html">
	@include('bookings::templates.passwords')
</script>
<script type="text/ng-template" id="bookings/repairs/prebooks.html">
	<div ng-if="prebooks.length > 0" class="alert alert-warning">
		<h4><i class="fa fa-exclamation-triangle"></i> This {[{ client_type }]} has some prebooks:</h4>
		<p>
			<div ng-repeat="task in prebooks">
				<strong><a ng-href="tasks/{[{task | taskUrl }]}">{[{ task.id }]}: </strong></a>{[{ task.title }]} for {[{ task.prebook_date }]}
			</div>
		</p>
	</div>
</script>
@include('bookings::templates.modals.no-preview-confirmation')
