<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Vehicles</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">
                            <?php echo e(ucfirst($action)); ?> Vehicle
                        </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/vehicles/'.$action)); ?>">
										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<?php if($action == 'edit'): ?>
											<input type="hidden" name="vehicleID" value="<?php echo e($vehicle->id); ?>">
										<?php endif; ?>
										<div class="form-group">
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('year')">
												<input type="number" step="1" class="form-control" id="year" name="year" value="<?php echo e(old('year') ? old('year') : (isset($vehicle) ? $vehicle->year : '')); ?>" title="Year">
												<span id="year-label" class="label-text">Year</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('make')">
												<input type="text" class="form-control" id="make" name="make" value="<?php echo e(old('make') ? old('make') : (isset($vehicle) ? $vehicle->make : '')); ?>" title="Make">
												<span id="make-label" class="label-text">Make</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('model')">
												<input type="text" class="form-control" id="model" name="model" value="<?php echo e(old('model') ? old('model') : (isset($vehicle) ? $vehicle->model : '')); ?>" title="Model">
												<span id="model-label" class="label-text">Model</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('vin')">
												<input type="text" class="form-control" id="vin" name="vin" value="<?php echo e(old('vin') ? old('vin') : (isset($vehicle) ? $vehicle->vin : '')); ?>" title="VIN">
												<span id="vin-label" class="label-text">VIN</span>	
											</div>

										</div>
										<div class="form-group">
											
											
											
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('driver')">
												<select class="form-control" id="driver" name="driver"  title="Driver">
													<option id="driver_option" value="">Select One</option>
													
													<?php foreach(\App\User::all()->sortBy('name') as $user): ?>
													
														<option value="<?php echo e($user->id); ?>"
														<?php if(old('driver') == $user->id || (isset($vehicle) && $vehicle->driver == $user->id)): ?> 
															<?php echo e('selected'); ?> 
														<?php endif; ?>
														><?php echo e($user->name); ?></option>
													
													<?php endforeach; ?>
													
													
												</select>
												<span id="type-label" 
												
												class="xlabel-text hasValue"
												
												>Driver</span>	
											</div>
											
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('starting_odometer')">
												<input type="number" step=".1" class="form-control" id="starting_odometer" name="starting_odometer" value="<?php echo e(old('starting_odometer') ? old('starting_odometer') : (isset($vehicle) ? $vehicle->starting_odometer : '')); ?>" title="Starting Odometer">
												<span id="starting_odometer-label" class="label-text">Starting Odometer</span>	
											</div>
											
											<div class="col-sm-12 col-md-6 morePadding morePadding2" onclick="inputFocus('description')">
												<input type="text" class="form-control" id="description" name="description" value="<?php echo e(old('description') ? old('description') : (isset($vehicle) ? $vehicle->description : '')); ?>" title="Description">
												<span id="description-label" class="label-text">Description</span>	
											</div>

										</div>
										

										<div class="form-group">
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('renewal_month')">
												<select class="form-control" id="renewal_month" name="renewal_month"  title="renewal_month">
													<option id="renewal_month_option" value="">Select One</option>
													
													<?php for($i=1;$i<=12;$i++): ?>
													
														<option value="<?php echo e($i); ?>"
														<?php if(old('renewal_month') == $i || (isset($vehicle) && $vehicle->renewal_month == $i)): ?> 
															<?php echo e('selected'); ?> 
														<?php endif; ?>
														><?php echo e(date('F', strtotime('2017-'.$i.'-1'))); ?></option>
													
													<?php endfor; ?>
													
													
												</select>
												<span id="renewal_month-label" 
												
												class="xlabel-text hasValue"
												
												>Renewal Month</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('plate')">
												<input type="text" class="form-control" id="plate" name="plate" value="<?php echo e(old('plate') ? old('plate') : (isset($vehicle) ? $vehicle->plate : '')); ?>" title="License Plate">
												<span id="plate-label" class="label-text">License Plate</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('location')">
												<input type="text" class="form-control" id="location" name="location" value="<?php echo e(old('location') ? old('location') : (isset($vehicle) ? $vehicle->location : '')); ?>" title="Vehicle Location">
												<span id="location-label" class="label-text">Location</span>	
											</div>
											<div class="col-sm-12 col-md-1 morePadding morePadding2" onclick="inputFocus('sold')">
												<input type="checkbox" class="form-control" id="sold" name="sold" value="1" title="Sold/Traded" <?php echo e(old('sold') == 1 ? 'checked' : (isset($vehicle) && $vehicle->sold == 1 ? 'checked' : '')); ?>>
												<span id="sold-label" class="label-text">Sold/Traded</span>	
											</div>
											<div class="col-sm-12 col-md-2 morePadding">
												<button type="submit" class="btn btn-primary" style="float: right;">
													Save
												</button>
											</div>
										</div>
										
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			    <div class="row">


                   <div class="col-lg-12">
                    <div class="panel panel-default">
                    	<?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-heading">
                           Maintenance Records
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example3">
                                    <thead>
                                        <tr>
                                       		<th>Vehicle</th>
                                       		<th>Plate</th>
                                       		<th>Driver</th>
                                            <th>Type</th>
                                            <th>Odometer</th>
                                            <th>Date</th>
                                            <th>Notes</th>
                                            <th>Created By</th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php $count = 0; ?>
                                    <?php 
                                    	$maintenances = isset($vehicle) ? \App\Maintenance::where('vehicle','=',$vehicle->id)->get() : array();
                                    ?>
                                    <?php foreach($maintenances as $maintenance): ?>
                                    <?php $count++; ?>
                                    <?php if($count % 2 == 1): ?>
                                        <tr class="odd">
                                    <?php else: ?>
                                    	<tr class="even">
                                    <?php endif; ?>
                                    		<?php $vehicle = \App\Vehicle::find($maintenance->vehicle); ?>
                                            <td><?php echo e($vehicle->year . ' ' . $vehicle->make . ' ' . $vehicle->model); ?></td>
                                            <td><?php echo e($vehicle->plate); ?></td>
                                            <td><?php echo e(\App\User::find($vehicle->driver)->name); ?></td>
                                            <td><?php echo e(\App\Maintenance_type::find($maintenance->type)->description); ?></td>
                                            <td><?php echo e($maintenance->odometer); ?></td>
                                            <td><?php echo e(date('Y-m-d', strtotime($maintenance->date))); ?></td>
                                            <td><?php echo e($maintenance->notes); ?></td>
                                            <td><?php echo e($maintenance->created_by); ?></td>
                                            
                                        </tr>
                                  	<?php endforeach; ?>
                                       </tbody>
                                	</table>
                                </div>
                             </div>
                         </div>
                     </div>
                 </div>

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

<?php $__env->startSection('extras'); ?>
	
	<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: 20px;
		    -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;
			}
		}
		
	</style>
	 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.css"/>
    
    
    <style>
    	a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}

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

<?php $__env->startSection('bottom'); ?>
<script type="text/javascript" src="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.js"></script>

<script>
	

	$(document).ready(function() {
	var table2 =    $('#dataTables-example3').dataTable( {
		"pageLength": 25,
		"order": [ 5, 'desc' ],
		"stateSave" : false,
		"scrollX" : window.innerWidth < 800 ? true : false
	
		
	} ); 
	});
	$('.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();
	}

	if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
    {
        $.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
        {
     
            var table = this;
             
            //any browser, must include your own file
            //var clearSearch = $('<img src="/images/delete.png" style="vertical-align:text-bottom;cursor:pointer;" alt="Delete" title="Delete"/>');
             
            //no image file needed, css embedding must be supported by browser
            var clearSearch = $('<i class="fa fa-times-circle-o fa-fw" style="vertical-align:text-bottom;cursor:pointer;color: gray;"></i>');
            $(clearSearch).click( function ()
                    {
                          table.fnFilter('');
                    });
            $(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
            $(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
            $(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
        }
     
        //auto-execute, no code needs to be added
        $.fn.dataTable.models.oSettings['aoInitComplete'].push( {
            "fn": $.fn.dataTableExt.oApi.clearSearch,
            "sName": 'whatever'
        } );
    }


</script>

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