<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">
    			<?php echo e($ticket->title); ?>

    			<div style="display: inline;font-size: 24px;position:relative; bottom:5px;">(<?php echo e($ticket->getID()); ?>)</div>
    			<a href='<?php echo e(url('uadmin/tickets/edit/'.$ticket->id)); ?>'>
	                <i class="fa fa-edit fa-fw" style="float: right; font-size: 18px; color: black;"></i>
	            </a>
    		</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="row">
				<div class="col-lg-2 section">
					<label>Created</label>
					<p><?php echo e(date_create($ticket->created_at)->format('Y-m-d')); ?> by <?php echo e($ticket->created_by); ?></p>	
				</div>
				<div class="col-lg-2 section">
					<label>Type</label>
					<p><?php echo e($ticket->type); ?></p>	
				</div>
				<div class="col-lg-2 section">
					<label>Issue Type</label>
					<p><?php echo e($ticket->issue_type); ?></p>	
				</div>
				<div class="col-lg-2 section">
					<label>Priority</label>
					<p><?php echo e(ucfirst($ticket->priority)); ?></p>	
				</div>
				<div class="col-lg-2 section">
					<label>Queue</label>
					<p><?php echo e(App\Ticket_Queue::find($ticket->queue)['name']); ?></p>	
				</div>
				<?php if($ticket->assigned_to): ?>
				<div class="col-lg-2 section">
					<label>Assigned To</label>
					<p><?php echo e(App\User::find($ticket->assigned_to)['name']); ?></p>	
				</div>
				<?php endif; ?>
			</div>

			<div class="row">
				<div class="col-lg-2 section">
					<label>Company</label>
					<p><?php echo e($customer->company_name); ?></p>	
				</div>
				<div class="col-lg-4 section">
					<label>Location</label>
					<?php if(App\Customer_Location::find($ticket->location)['main_location']): ?>
						<p>Main Office - <?php echo e($customer->directory_address.' '.$customer->directory_city.', '.$customer->directory_state.' '.$customer->directory_zip); ?></p>
					<?php else: ?>
						<p><?php echo e(App\Customer_Location::find($ticket->location)['name']); ?> - <?php echo e(App\Customer_Location::find($ticket->location)['address']); ?></p>
					<?php endif; ?>
				</div>
				<div class="col-lg-3 section">
					<label>Phone Number</label>
					<?php if(App\Customer_Location::find($ticket->location)['main_location']): ?>
						<?php if($customer->directory_phone): ?>
							<p><?php echo e($customer->directory_phone); ?></p>
						<?php else: ?>
						<p>--</p>
						<?php endif; ?>
					<?php else: ?>
						<?php if(App\Customer_Location::find($ticket->location)['phone_number']): ?>
						<p><?php echo e(App\Customer_Location::find($ticket->location)['phone_number']); ?></p>
						<?php else: ?>
						<p>--</p>
						<?php endif; ?>
					<?php endif; ?>
				</div>
			</div>

			<div class="row">
				<?php if($ticket->parent!=0): ?>
				<div class="col-lg-2 section">
					<label>Parent Ticket</label>
					<p><?php echo e(App\Ticket::where('id','=',$ticket->parent)->first()['title']); ?></p>	
				</div>
				<?php endif; ?>
			</div>

			<div class="row">
				<div class="col-lg-12 section">
					<label>Description</label>
					<p><?php echo nl2br(e($ticket->description)); ?></p>	
				</div>
			</div>

			<?php if(count($attachments)>0): ?>
			<div class="row">
				<div class="col-sm-12" style="padding-bottom: 20px;">
					<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>
						</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>
				</div>
			</div>
			<?php endif; ?>

			<div class="row">
				<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/complete')); ?>">
					<div class="col-sm-12 col-md-4 section">
						<label>Attachments</label>
						<input type="file" class="form-control" id="attachments" name="attachments[]" value="<?php echo e(old('attachments')); ?>"  title="Attachments" multiple>
					</div>
					<div class="col-sm-12 col-md-12 section">
						<label>Resolution</label>
						<div onclick="inputFocus('resolution')">
							<textarea class="form-control" style="max-width: 100%;" id="resolution" name="resolution" title="Resolution" placeholder=""><?php echo e(isset($ticket->resolution) ? $ticket->resolution : ''); ?></textarea>
						</div>
					</div>
					<div class="col-lg-12 section">
						<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
						<input type="hidden" name="ticketID" value="<?php echo e($ticket->id); ?>">
						<button type="submit" class="btn btn-primary" style="float:right;">
							Mark as Completed
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>

	<div class="panel panel-default" style="margin-top: 20px;">
		<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; padding: 0; 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>

	<!-- View/Edit Attachment Modal -->
	<div id="viewModal" 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">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="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')); ?>" />

	<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;
		}

		.section{
			margin-bottom: 20px;
		}
    </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>
	
	$('.form-control').each(function() {
	   var 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());
	       var 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();
	}

</script>

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

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

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

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

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