<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">
    			Edit Ticket (<?php echo e($ticket->getID()); ?>)
    			<div style="font-size: 16px;padding-top: 5px;font-weight: 350;">Created: <?php echo e(date_create($ticket->created_at)->format('Y-m-d')); ?> by <?php echo e($ticket->created_by); ?></div>
    		</h1>
    	</div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <?php if(session('status')): ?>
			<div class="alert alert-success">
				<?php echo e(session('status')); ?>

			</div>
			<?php endif; ?>
			<?php if(count($errors) > 0): ?>
				<div class="alert alert-danger">
					<strong>Whoops!</strong> There were some problems with your input.<br><br>
					<ul>
						<?php foreach($errors->all() as $error): ?>
							<li><?php echo e($error); ?></li>
						<?php endforeach; ?>
					</ul>
				</div>
			<?php endif; ?>
			<div class="panel panel-default">
				<div class="panel-heading">
                    Edit Ticket
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12">
		                    <form id="theForm" class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/tickets/edit')); ?>">
								<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
								<input type="hidden" name="ticket_id" value="<?php echo e($ticket->id); ?>">

								<div class="form-group">

									<div class="col-sm-12 col-md-12" style="margin-bottom: 10px;">
										<div class="col-sm-12 col-md-8 input-item" onclick="inputFocus('title')">
											<input type="text" step="1" class="form-control" id="title" name="title" value="<?php echo e($ticket->title); ?>" title="title">
											<span id="title-label" class="label-text">Title*</span>
										</div>

										<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('parent')">
											<select class="form-control" id="parent" name="parent"  title="parent">
												<option value=" ">Select One</option>
												
												<?php foreach(\App\Ticket::where('type','=','Problem')->where('closed_at','=', null)->orderBy('created_at', 'desc')->get() as $parent_ticket): ?>
												<?php if($parent_ticket->id != $ticket->id): ?>

													<option value="<?php echo e($parent_ticket->id); ?>" <?php echo e($ticket->parent == $parent_ticket->id ? 'selected' : ''); ?>><?php echo e($parent_ticket->getID() . ' - ' . $parent_ticket->title); ?></option>

												<?php endif; ?>
												<?php endforeach; ?>
											</select>
											<span id="parent-label" class="xlabel-text hasValue">Parent Ticket (Optional)</span>	
										</div>
									</div>

									<div class="col-sm-12 col-md-12">
										<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('type')">
											<select class="form-control" id="type" name="type"  title="type">
												<option <?php echo e($ticket->type == 'Incident' ? 'selected' : ''); ?> value="Incident">Incident</option>
												<option <?php echo e($ticket->type == 'Problem' ? 'selected' : ''); ?> value="Problem">Problem</option>
												<option <?php echo e($ticket->type == 'Request' ? 'selected' : ''); ?> value="Request">Request</option>
											</select>
											<span id="type-label" class="xlabel-text hasValue">Ticket Type*</span>	
										</div>

										<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('issue_type')">
											<select class="form-control" id="issue_type" name="issue_type"  title="issue_type">
												<option <?php echo e($ticket->issue_type == 'Circuit' ? 'selected' : ''); ?> value="Circuit">Circuit</option>
												<option <?php echo e($ticket->issue_type == 'Phone' ? 'selected' : ''); ?> value="Phone">Phone</option>
												<option <?php echo e($ticket->issue_type == 'Maintenance' ? 'selected' : ''); ?> value="Maintenance">Maintenance</option>
												<option <?php echo e($ticket->issue_type == 'Other' ? 'selected' : ''); ?> value="Other">Other</option>
											</select>
											<span id="issue_type-label" class="xlabel-text hasValue">Issue Type*</span>	
										</div>

										<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('priority')">
											<select class="form-control" id="priority" name="priority"  title="priority">
												<option <?php echo e($ticket->priority == 'low' ? 'selected' : ''); ?> value="Low">Low</option>
												<option <?php echo e($ticket->priority == 'medium' ? 'selected' : ''); ?> value="Medium">Medium</option>
												<option <?php echo e($ticket->priority == 'high' ? 'selected' : ''); ?> value="High">High</option>
											</select>
											<span id="priority-label" class="xlabel-text hasValue">Priority*</span>	
										</div>
									</div>
								</div>

								<div class="form-group">
									<div class="col-sm-12 col-md-12">
										
										<div class="col-sm-12 col-md-4 morePadding morePadding2" onclick="inputFocus('customer')">
											<span id="customer-custom-label" class="xlabel-text hasValue">Company*</span>
											<input type="text" class="form-control" value="<?php echo e($ticket->customer); ?>" id="customer" name="customer" title="Company Name">
										</div>

										<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('location')">
											<span id="location-custom-label" class="xlabel-text hasValue">Location*</span>
											<input type="text" class="form-control" value="<?php echo e($ticket->location); ?>" id="location" name="location" title="Location">
										</div>
										
										<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('queue')">
											<select class="form-control" id="queue" name="queue"  title="queue">
												<option value=" ">Select One</option>
												
												<?php foreach(\App\Ticket_Queue::all()->sortBy('name') as $queue): ?>
													
													<option value="<?php echo e($queue->id); ?>" <?php echo e($ticket->queue == $queue->id ? 'selected' : ''); ?>><?php echo e($queue->name); ?></option>
												
												<?php endforeach; ?>
											</select>
											<span id="queue-label" class="xlabel-text hasValue">Queue*</span>	
										</div>

										<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('assigned_to')">
											<select class="form-control" id="assigned_to" name="assigned_to"  title="assigned_to" value="<?php echo e(old('assigned_to')); ?>">
												<option value="">Select One</option>
												
												<?php foreach(\App\User::all()->sortBy('name') as $user): ?>
													
													<option value="<?php echo e($user->id); ?>" <?php echo e($ticket->assigned_to == $user->id ? 'selected' : ''); ?>><?php echo e($user->name); ?></option>
												
												<?php endforeach; ?>
											</select>
											<span id="assigned_to-label" class="xlabel-text hasValue">Assign Employee</span>	
										</div>
									</div>
								</div>

								<div class="form-group">
									<div class="col-sm-12 col-md-12" style="margin-bottom: 20px;">
										<label class="label-control col-sm-12 col-md-12" style="margin-bottom: -5px;">Description</label>
										<div class="col-sm-12 col-md-12 morePadding morePadding2" onclick="inputFocus('description')">
											<textarea class="form-control" style="max-width: 100%; height:200px;" id="description" name="description" title="Description" placeholder="Description"><?php echo e($ticket->description); ?></textarea>
										</div>
									</div>
								</div>

								<div class="form-group">
									<div class="col-sm-12 col-md-12">
										<div class="col-sm-12" style="padding-bottom: 20px;">
											<h4>Attachments <i class="fa fa-plus-circle" style='color: #01B300; cursor: pointer;' data-toggle="modal" data-target="#addModal" title="Add Attachment"></i></h4>
											
											<?php if(count($attachments)>0): ?>
												<div class="gallery">
												<?php foreach($attachments as $attachment): ?>
													<?php if(pathinfo($attachment->filename,PATHINFO_EXTENSION) == 'xlsx' || pathinfo($attachment->filename,PATHINFO_EXTENSION) == 'pdf' || pathinfo($attachment->filename,PATHINFO_EXTENSION) == 'pcap' || pathinfo($attachment->filename,PATHINFO_EXTENSION) == 'txt'): ?>
													<div class="gallery-image" style="text-align: center;">
														<a href='<?php echo e(asset('uadmin/tickets/attachments/'.$attachment->id)); ?>' download>
															<i class="fa fa-download fa-3x" style='color: black; cursor: pointer; padding-top: 40px;'></i>
															<p style="color:black;"><?php echo e(substr($attachment->filename, 14)); ?></p>
														</a>
				                                        <button type="button" onclick="submitDelete(<?php echo e($attachment->id); ?>)" style="border: none; background: none; padding: 0px; color:red;">
				                                            <i class="fa fa-trash-o fa-fw"></i>
				                                        </button>
													</div>
													<?php else: ?>
													<div class="gallery-image hover-shadow">
														<img class="img-button" src='<?php echo e(asset('uadmin/tickets/attachments/'.$attachment->id)); ?>' data-toggle="modal" data-id="<?php echo e($attachment->id); ?>" data-target="#viewModal">
													</div>
													<?php endif; ?>
												<?php endforeach; ?>
												</div>
											<?php else: ?>
											--
											<?php endif; ?>
										</div>
									</div>
								</div>

								<div class="form-group">
									<div class="col-sm-12 col-md-12 morePadding" style="text-align: right;">

                        				<div class="col-lg-12">
											<button type="submit" class="btn btn-primary">
												Save
											</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>

			<form id="delete-form" style="display: inline;" role="form" method="POST" action="<?php echo e(url('admin/tickets/attachments/delete')); ?>">
                <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
				<input id="delete-attachment-id" type="hidden" name="attachment_id" value="">
            </form>

			<div class="panel panel-default">
				<div class="panel-heading">
                    Notes
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-12">

                        	<form id="theForm" class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/tickets/notes/add')); ?>">
								<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
								<input type="hidden" name="ticket" value="<?php echo e($ticket->id); ?>">

								<div class="col-sm-12 col-md-12 morePadding">
									<textarea class="form-control" style="max-width: 100%; height:200px;" id="notes" name="notes" title="Notes" placeholder="Note"></textarea>
								</div>

								<div class="col-sm-12 col-md-12 morePadding" style="text-align: right; margin-bottom: 10px;">
									<button type="submit" class="btn btn-primary">
										Post
									</button>
								</div>
							</form>

							<?php foreach($notes as $note): ?>
								<label class="label-control col-sm-12 col-md-12" style="margin-bottom: 5px;">
									<?php echo e($note->user !== 0 ? App\User::find($note->user)['name'] : 'System'); ?>


									<div style="display: inline-block; font-weight: 400;">( <?php echo e(date_create($note->created_at)->format('m-d-Y @ g:i A')); ?> )</div>

						            <?php if($note->updated_at != $note->created_at): ?>
						            	<div style="display: inline-block; font-weight: 400; color:grey; font-size: 12px;">Edited at <?php echo e(date_create($note->updated_at)->format('m-d-Y @ g:i A')); ?></div>
						            <?php endif; ?>

									<?php if($note->user == Auth::user()->id): ?>
						                <button style="border: none; background-color: white; padding: 0; color: grey;">
						                	<i class="fa fa-edit fa-fw edit-note" style="font-size: 12px; color: grey; cursor:pointer; padding-left: 5px;" data-id="<?php echo e($note->id); ?>" data-notes="<?php echo e($note->notes); ?>" data-toggle="modal" data-target="#editNoteModal" title="Edit Note"></i>
						                </button>

										<form style="display: inline;" role="form" method="POST" action="<?php echo e(url('admin/tickets/notes/delete')); ?>" 
											onsubmit="return confirm('Are you sure you want to remove this note?')">
											<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
											<input type="hidden" name="noteID" value="<?php echo e($note->id); ?>">
											<button type="submit" style="border: none; background-color: white; color: grey;">
                                    			<i class="fa fa-trash-o fa-fw"></i>
                                    		</button>
                                    	</form>
						            <?php endif; ?>

								</label>
								<div style="padding-left: 22px; margin-bottom: 25px;"><?php echo nl2br(e($note->notes)); ?></div>
							<?php endforeach; ?>

						</div>
					</div>
				</div>
			</div>

		</div>
	</div>


	<!-- Add Attachment Modal -->
	<div id="addModal" class="modal fade" role="dialog">
		<div class="modal-dialog">

			<!-- Modal content-->
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Add Attachments</h4>
				</div>
				<form id="theForm" class="form-horizontal" style="margin-bottom: 0px;" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/tickets/attachments/add')); ?>">
					<div class="modal-body">
						<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
						<input type="hidden" name="ticket_id" value="<?php echo e($ticket->id); ?>">

						<div class="form-group">
							<div class="col-sm-12 morePadding morePadding2">
								<input type="file" class="form-control" id="attachments" name="attachments[]" value=""  title="Attachments" multiple>
								<span id="attachments-label" class="xlabel-text hasValue">Attachments</span>
							</div>
						</div>

					</div>
					<div class="modal-footer">
						<button type="submit" class="btn btn-primary" style="float: right;">
							Upload
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>

	<!-- View/Edit Attachment Modal -->
	<div id="viewModal" class="modal fade" role="dialog">
		<div class="modal-dialog">

			<!-- Modal content-->
			<div class="modal-content" style="display: inline-block;">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Attachment</h4>
				</div>
				<div class="modal-body img-fill">
					<img id="attachmentID" src=''>
				</div>
				<div class="modal-footer">
					<form id="theForm" class="form-horizontal" style="margin-bottom: 0px;" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/tickets/attachments/delete')); ?>">
						<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
						<input id="attachment_id-input" type="hidden" name="attachment_id" value="">
						<button type="submit" class="btn btn-outline-danger" style="color:red;">Delete</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					</form>
				</div>
			</div>
		</div>
	</div>

	<!-- Edit Note Modal -->
	<div id="editNoteModal" class="modal fade" role="dialog">
		<div class="modal-dialog">

			<!-- Modal content-->
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Edit Note</h4>
				</div>
				<form id="theForm" class="form-horizontal" style="margin-bottom: 0px;" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/tickets/notes/edit')); ?>">
					<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
					<input id="noteID" type="hidden" name="noteID">
					<div class="modal-body img-fill">
						<div class="col-sm-12 col-md-12 morePadding">
							<textarea class="form-control" style="max-width: 100%; height:50px;" id="note_id-input" name="edit_note" title="Notes"></textarea>
						</div>
					</div>
					<div class="modal-footer">
							<input id="attachment_id-input" type="hidden" name="attachment_id" value="">
							<button type="submit" class="btn btn-primary">Save</button>
							<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					</div>
				</form>
			</div>
		</div>
	</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>
	
	<link rel="stylesheet" type="text/css" href="<?php echo e(asset('css/jquery.timepicker.css')); ?>" />
	<link rel="stylesheet" type="text/css" href="<?php echo e(asset('css/bootstrap-datepicker3.min.css')); ?>" />
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/css/selectize.bootstrap3.min.css" />

	<style>
		input:focus+.label-text, input:not([value=""])+.label-text, select+.label-text {
		    font-weight: normal;
		    padding: 0;
		    padding-left: 20px;
		    -webkit-transform: translateY(-2rem) scale(.7);
		    transform: translateY(-2rem) scale(.7);
		}
		input+.label-text, select+.label-text, .hasValue{
		    font-size: 1.5rem;
		    font-weight: 400;
		    position: absolute;
		    top: 0;
		    left: 0;
		    display: block;

		    padding-left: 20px;
		    padding-top: 5px;
		    padding-bottom: 5px;
		    opacity: .8;
		    transition: all .3s ease-out,opacity 150ms ease .3s;
		    -webkit-transform: translateY(0) scale(1);
		    transform: translateY(0) scale(1);
		    -webkit-transform-origin: left top;
		    transform-origin: left top;
		}
		span {
		    font-size: 1rem;
		    font-weight: 600;
		    display: block;
		    padding-top: .25rem;
		    padding-bottom: .25rem;
		    margin-left: 1rem;
		    color: #317aba;
		}
		.hasValue
		{
		    font-weight: normal;
		    padding: 0;
		    padding-left: 10px;
		    -webkit-transform: translateY(-2rem) scale(.7);
		    transform: translateY(-2rem) scale(.7);
		}
		

		@media (max-width: 959px)
		{
			.morePadding {
			    margin-top: 1.5em;
			}
		}

		@media (min-width: 960px)
		{
			.morePadding {
			    margin-top: 1em;
			}
		}
		
    	a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}

    	.checkbox-item{
    		padding-top: 7px;
    		padding-bottom: 5px;
    	}

    	.no-bold{
    		font-weight: normal;
    	}

    	.input-item{
    		padding-bottom: 5px;
    	}

    	@media (max-width: 991px)
		{
			.input-item{
	    		margin-top: 20px;
	    	}
		}

    	@media (min-width: 992px)
		{
			.input-item{
	    		margin-top: 12px;
	    	}
		}

.modal{
	padding-top: 100px;
}

.gallery img {
	height: 100%;
	width: auto;
	cursor: pointer;
}

.gallery{
    padding-bottom: 10px;
    overflow-y: hidden;
    overflow-x: auto;
    white-space: nowrap;
}

.gallery-image{
	display: inline-block;
	width:140px;
	height:140px;
	margin: 5px;
	overflow:hidden;
	text-align: center;
}

.hover-shadow:hover {
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	transition: 0.3s;
}

.img-fill{
	display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#attachmentID{
	flex-shrink: 0;
    height: 100%;
    max-height: 500px;
    width: auto;
}
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>

	<script src="<?php echo e(asset('js/jquery.datepair.min.js')); ?>"></script>
	<script src="<?php echo e(asset('js/bootstrap-datepicker.min.js')); ?>"></script>
	<script src="<?php echo e(asset('js/jquery.timepicker.min.js')); ?>"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/js/standalone/selectize.min.js"></script>

<script>
	
	$('.form-control').each(function() {
	   let elem = $(this);

	   // Save current value of element
	   elem.data('oldVal', elem.val());

	   // Look for changes in the value
	   elem.bind("propertychange change click keyup input paste", function(event){
	      // If value has changed...
	      if (elem.data('oldVal') != elem.val()) {
	       // Updated stored value
	       elem.data('oldVal', elem.val());
	       let elem2 = $('#'+elem.attr('id')+"-label");
	       elem2.addClass('hasValue');
	       elem2.removeClass('label-text');
	       if(elem.val() == "")
	       {
	    	   elem2.addClass('label-text');
		       elem2.removeClass('hasValue');
	       }
	     }
	   });
	 });

	function inputFocus(id)
	{
		document.getElementById(id).focus();
	}

	$('#due_date_container .date').datepicker({
        'format': 'yyyy-m-d',
        'autoclose': true
    });

</script>

<script>
	$(window).load(function(){
	 $('.container').find('img').each(function(){
	  let imgClass = (this.width/this.height > 1) ? 'wide' : 'tall';
	  $(this).addClass(imgClass);
	 })
	})

	$(document).on("click", ".img-button", function () {
    	let myAttachmentID = $(this).data('id');
    	document.getElementById("attachment_id-input").value = myAttachmentID;
    	document.getElementById("attachmentID").src = window.location.origin+'/uadmin/tickets/attachments/'+myAttachmentID;
	});

	let notes = document.getElementsByClassName("edit-note");
	for (let i=0; i < notes.length; i++) {
	    notes[i].onclick = function () {
	    	let myNoteID = $(this).data('id');
	    	let myNoteMessage = $(this).data('notes');
	    	document.getElementById("noteID").value = myNoteID;
	    	document.getElementById("note_id-input").value = myNoteMessage;
		}
	};
</script>

<script>

	$('.form-control').each(function() {
	   let elem = $(this);

	   // Save current value of element
	   elem.data('oldVal', elem.val());

	   // Look for changes in the value
	   elem.bind("propertychange change click keyup input paste", function(event){
	      // If value has changed...
	      if (elem.data('oldVal') != elem.val()) {
	       // Updated stored value
	       elem.data('oldVal', elem.val());
	       let elem2 = $('#'+elem.attr('id')+"-label");
	       elem2.addClass('hasValue');
	       elem2.removeClass('label-text');
	       if(elem.val() == "")
	       {
	    	   elem2.addClass('label-text');
		       elem2.removeClass('hasValue');
	       }
	     }
	   });
	 });

	function inputFocus(id)
	{
		document.getElementById(id).focus();
	}

	$('#due_date_container .date').datepicker({
        'format': 'yyyy-m-d',
        'autoclose': true
    });

	let allLocations = (<?php echo json_encode($locations); ?>);
	let originalCustomer = <?php echo json_encode($ticket->customer); ?>;
    let allCustomers = (<?php echo json_encode($customers); ?>);
    let queue_members = (<?php echo json_encode($queue_members); ?>);
    let users = (<?php echo json_encode($users); ?>);
    let queue = (<?php echo json_encode($ticket->queue); ?>);
    let assigned_to = (<?php echo json_encode($ticket->assigned_to); ?>);
    
	$('#customer').selectize({
	    create: false,
	    sortField: 'customer',
	    maxItems: 1,
	    valueField: 'id',
	    labelField: 'customer',
	    searchField: ['customer'],
	    options: [
      	<?php foreach($customers as $customer): ?>
    		{customer: "<?php echo $customer->company_name; ?>", id: '<?php echo e($customer->id); ?>' },
    	<?php endforeach; ?>
    	],
    	onChange: function(){ this.$dropdown_content.removeHighlight(); },
    	onType: function(str) { str || this.$dropdown_content.removeHighlight(); },
    	onItemAdd: function(value, $item) {
    		$('#location')[0].selectize.clearOptions();
    		for(let i=0;i<allLocations.length;i++){
    			if(allLocations[i].customer == value){
    				if(allLocations[i].main_location){
    					for(let j=0;j<allCustomers.length;j++){
    						if(allCustomers[j].id == value){
    							if(allCustomers[j].directory_address){
    								$('#location')[0].selectize.addOption({name: 'Main Office', address: '', customer: allLocations[i].customer, id: allLocations[i].id});
    							}
    						}
    					}
    				}else{
    					$('#location')[0].selectize.addOption({name: allLocations[i].name, address: allLocations[i].address, customer: allLocations[i].customer, id: allLocations[i].id});
    				}
    			}
    		}
    		$('#location')[0].selectize.enable();
    	},
    	onItemRemove: function() { $('#location')[0].selectize.disable(); }
	});

	$('#location').selectize({
	    create: false,
	    sortField: 'name',
	    maxItems: 1,
	    valueField: 'id',
	    labelField: 'name',
	    searchField: ['name','address'],
	    options: [
      	<?php foreach($locations as $location): ?>
      		<?php if($location->customer == $ticket->customer): ?>
	      		<?php if($location->main_location): ?>
	    			{name: 'Main Office', address: '', customer: '<?php echo e($location->customer); ?>', id: '<?php echo e($location->id); ?>'},
	      		<?php else: ?>
	    			{name: "<?php echo $location->name; ?>", address: '<?php echo e($location->address); ?>', customer: '<?php echo e($location->customer); ?>', id: '<?php echo e($location->id); ?>'},
	      		<?php endif; ?>
      		<?php endif; ?>
    	<?php endforeach; ?>
	    ]
	});

	$( "#queue" ).change(function(){
		let $el = $("#assigned_to");
		$el.empty();
		let defaultOption = $('<option></option>').attr("value", "").text("Select One");
		$el.append(defaultOption);
		
		for(let i=0;i<queue_members.length;i++){
			if(queue_members[i].queue == $(this).val()){
				for(let j=0;j<users.length;j++){
					if(users[j].id == queue_members[i].user){
						let option = $('<option></option>').attr("value", queue_members[i].user).text(users[j].name);
						$el.append(option);
					}
				}
			}
		}
	});
	
	let $el = $("#assigned_to");
	$el.empty();
	let defaultOption = $('<option></option>').attr("value", "").text("Select One");
	$el.append(defaultOption);
	for(let i=0;i<queue_members.length;i++){
		if(queue_members[i].queue == queue){
			for(let j=0;j<users.length;j++){
				if(users[j].id == queue_members[i].user){
					let option = $('<option></option>').attr("value", queue_members[i].user).text(users[j].name);
					if(assigned_to && assigned_to==users[j].id){
						option.attr("selected", '');
					}
					$el.append(option);
				}
			}
		}
	}

	function submitDelete(id)
	{
		let r = confirm('Are you sure you want to remove this attachment?');
		if(r){
	    	document.getElementById("delete-attachment-id").value = id;
	    	document.getElementById("delete-form").submit();
		}
	}
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>