<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Accounts</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(substr($action, 0, 3) == 'add' ? 'Add' : 'Edit'); ?> Allocation
                        </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/accounts/'.$action)); ?>">
										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<?php if($action == 'edit-allocation'): ?>
											<input type="hidden" name="allocationID" value="<?php echo e($allocation->id); ?>">
										<?php endif; ?>
										<div class="form-group">
											
											<div class="col-sm-12 col-md-4 morePadding morePadding2" onclick="inputFocus('description')">
												<input type="text" class="form-control" id="description" name="description" value="<?php echo e(old('description') ? old('description') : (isset($allocation) ? $allocation->description : '')); ?>" title="Description">
												<span id="description-label" class="label-text">Description</span>	
											</div>
											<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('year')">
												<input type="text" class="form-control" id="year" name="year" value="<?php echo e(old('year') ? old('year') : (isset($allocation) ? $allocation->year : '')); ?>" title="Year">
												<span id="year-label" class="label-text">Year</span>	
											</div>
											<div class="col-sm-12 col-md-6 morePadding">
												<button type="submit" class="btn btn-primary" style="float: right;">
													Save
												</button>
											</div>
										</div>
									
										
									</form>
								</div>
							</div>
						</div> 
						<?php if($action == 'edit-allocation'): ?>
						<hr>
						<div class="panel-body">
						<form id="theForm" class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="<?php echo e(url('admin/accounts/edit-allocation-links')); ?>">
							<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">

							<input type="hidden" name="allocationID" value="<?php echo e($allocation->id); ?>">
                            <div class="row">
                                <div class="col-lg-12">
				                    
										<div class="col-sm-12 col-md-3">
											<div class="form-group">
												<div class="xcol-sm-12 xcol-md-12 xmorePadding xmorePadding2" onclick="inputFocus('accounts')">
													<select class="form-control" id="accounts" name="accounts"  title="Accounts" onchange="selectAccount()">
														<option id="accounts_option"></option>
														<?php foreach(\App\Account::orderBy('number', 'asc')->get() as $account): ?>
														<option value="<?php echo e($account->id); ?>"
		
														><?php echo e($account->number.' ('.$account->company.') - '.$account->description); ?></option>
														<?php endforeach; ?>
													</select>
													<span id="accounts-label" 
													class="label-text hasValue"
													>Add Account</span>	
												</div>
											</div>
										</div>
										
								</div>
							</div>
							<div class="row">
                                <div class="col-lg-12">
										
										
											<?php foreach(\App\Account::orderBy('number', 'asc')->get() as $account): ?>
											<div class="form-group" id="container<?php echo e($account->id); ?>" 
												<?php if(!\App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->exists()): ?>
												style="display: none;"
												<?php endif; ?>
											>
												<label class="col-sm-12 col-md-2 morePadding morePadding2"><?php echo e($account->number.' ('.$account->company.')'); ?></label>
												<label class="col-sm-12 col-md-3 morePadding morePadding2"><?php echo e($account->description); ?></label>
												<div class="col-sm-11 col-md-2 morePadding morePadding2" onclick="inputFocus('weight<?php echo e($account->id); ?>')">
													<input type="number" min="0" step="1" class="form-control" id="weight<?php echo e($account->id); ?>" name="weight[<?php echo e($account->id); ?>]" value="<?php echo e(old('weight') ? old('weight') : \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->exists() ? \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->first()->weight : ''); ?>" title="Weight">
													<span id="weight<?php echo e($account->id); ?>-label" class="label-text">Weight</span>	
												</div>
												<div class="col-sm-11 col-md-2 morePadding morePadding2" onclick="inputFocus('time<?php echo e($account->id); ?>')">
													<input type="number" min="0" step="0.25" class="form-control" id="time<?php echo e($account->id); ?>" name="time[<?php echo e($account->id); ?>]" value="<?php echo e(old('time') ? old('time') : \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->exists() ? \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->first()->time : ''); ?>" title="Time">
													<span id="time<?php echo e($account->id); ?>-label" class="label-text">Time</span>	
												</div>
												<div class="col-sm-11 col-md-2 morePadding morePadding2" onclick="inputFocus('priority<?php echo e($account->id); ?>')">
													<input type="number" min="0" step="1" class="form-control" id="priority<?php echo e($account->id); ?>" name="priority[<?php echo e($account->id); ?>]" value="<?php echo e(old('priority') ? old('priority') : \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->exists() ? \App\Allocation_link::where('account','=',$account->id)->where('allocation','=',$allocation->id)->first()->priority : ''); ?>" title="Priority">
													<span id="priority<?php echo e($account->id); ?>-label" class="label-text">Priority</span>	
												</div>
												<div class="col-sm-1 col-md-1 morePadding morePadding2">
													<i class="fa fa-times" style="float: right; color: red; cursor: pointer;" onclick="removeAccount(<?php echo e($account->id); ?>)"></i>
												</div>
											</div>
											<?php endforeach; ?>
										
										<div class="col-sm-12 col-md-12">
											<div class="form-group">
												<button type="submit" class="btn btn-primary" style="float: right;">
													Save
												</button>
											</div>
										</div>
									
								</div>
							</div>
						</div>
						</form>
					</div>
					<?php endif; ?>
				</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>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>
<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();
	}

	function selectAccount()
	{
		var account = document.getElementById('accounts').value;

	    var elements = document.getElementById("accounts").options;

	    for(var i = 0; i < elements.length; i++){
	      elements[i].selected = false;
	    }

		document.getElementById('container'+account).style.display = '';
	}

	function removeAccount(id)
	{
		document.getElementById('container'+id).style.display = 'none';
		document.getElementById('weight'+id).value = '';
		document.getElementById('time'+id).value = '';
		document.getElementById('priority'+id).value = '';
	}
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>