<?php $__env->startSection('content'); ?>
<?php if($action == 'edit'): ?>
<?php 
	$account_object = new \App\Account;
	
	if(old('accounts') != "" && count(old('accounts') > 0))
	{
		$oldAccounts = array();
		foreach(old('accounts') as $key => $value)
		{
			$oldAccounts[$value] = $account_object->getName($value);
		}
	}
	elseif (count($accounts) > 0)
	{
		$oldAccounts = array();
		foreach($accounts as $key => $value)
		{
			if($value->type = 'account')
			{
				$oldAccounts[$value->account] = $account_object->getName($value->account);
			}
			
		}
		
	}
	$allocation_object = new \App\Allocation;
	
	if(old('allocations') != "" && count(old('allocations') > 0))
	{
		$oldAllocations = array();
		foreach(old('allocations') as $key => $value)
		{
			$oldAllocations[$value] = $allocation_object->getName($value);
		}
	}
	elseif (count($allocations) > 0)
	{
		$oldAllocations = array();
		foreach($allocations as $key => $value)
		{
			if($value->type = 'allocation')
			{
				$oldAllocations[$value->account] = $allocation_object->getName($value->account);
			}
			
		}
	
	}
?>
<?php endif; ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Employees</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)); ?> Employee
                        </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/employees/'.$action)); ?>">
										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<?php if($action == 'edit'): ?>
											<input type="hidden" name="employeeID" value="<?php echo e($employee->id); ?>">
										<?php endif; ?>
										<div class="form-group">
											
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('user')">
												<select class="form-control" id="user" name="user"  title="User">
													<option id="user_option"></option>
													<?php foreach(\App\User::orderBy('name')->get() as $user): ?>
													<option value="<?php echo e($user->id); ?>"
													<?php if(old('user') == $user->id || (isset($employee) && $employee->user == $user->id)): ?> 
														<?php echo e('selected'); ?> 
													<?php endif; ?>
													><?php echo e($user->name); ?></option>
													<?php endforeach; ?>
												</select>
												<span id="user-label" 
												<?php if(old('user') || isset($employee)): ?>
												class="xlabel-text hasValue"
												<?php else: ?>
												class="label-text"
												<?php endif; ?>
												>User</span>	
											</div>
											<div class="col-sm-12 col-md-3 morePadding morePadding2" onclick="inputFocus('manager')">
												<select class="form-control" id="manager" name="manager"  title="Manager">
													<option id="manager_option"></option>
													<?php foreach(\App\Employee::orderBy('number')->get() as $user): ?>
													<option value="<?php echo e($user->id); ?>"
													<?php if(old('manager') == $user->id || (isset($employee) && \App\Organization::where('employee', '=', $employee->id)->exists() && \App\Organization::where('employee', '=', $employee->id)->first()->manager == $user->id)): ?>
														<?php echo e('selected'); ?> 
													<?php endif; ?>
													><?php echo e($user->number.' | '.\App\User::find($user->user)->name); ?></option>
													<?php endforeach; ?>
												</select>
												<span id="manager-label" 
												<?php if(old('manager') || (isset($employee) && \App\Organization::where('employee', '=', $employee->id)->exists())): ?>
												class="xlabel-text hasValue"
												<?php else: ?>
												class="label-text"
												<?php endif; ?>
												>Manager</span>	
											</div>
											<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('number')">
												<input type="text" class="form-control" id="number" name="number" value="<?php echo e(old('number') ? old('number') : isset($employee) ? $employee->number : ''); ?>" title="Employee Number">
												<span id="number-label" class="label-text">Employee #</span>	
											</div>
											<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="inputFocus('type')">
												<select class="form-control" id="type" name="type"  title="Type">
													
													<option value="hourly"
													<?php if(old('type') == 'hourly' || (isset($employee) && $employee->type == 'hourly')): ?>
														<?php echo e('selected'); ?>  
													<?php endif; ?>
													>Hourly</option>
													
													<option value="salary"
													<?php if(old('type') == 'salary' || (isset($employee) && $employee->type == 'salary')): ?>
														<?php echo e('selected'); ?>  
													<?php endif; ?>
													>Salary</option>
													
													
												</select>
												<span id="type-label" 
												<?php if(true): ?>
												class="xlabel-text hasValue"
												<?php else: ?>
												class="label-text"
												<?php endif; ?>
												>Type</span>	
											</div>
											<div class="col-sm-12 col-md-2 morePadding morePadding2" onclick="" style="color: gray;">
												<input type="checkbox" class="xform-control" id="accountant" name="accountant" value="1" title="Accountant" <?php echo e(old('accountant') || (isset($employee) && $employee->accountant) == 1 ? 'checked' : ''); ?>>
												Accountant
											</div>
											
										</div>
										<?php if($action == 'edit'): ?>
										<hr>
										<div class="form-group">
									        <label class="col-md-4 control-label">Accounts</label>
									        <div class="col-md-8 component-mt-select"
									        	data-mt-max-tags="100"
									             data-mt-request-url="/uadmin/ajaxAccounts.php"
									              data-mt-tag-input-name="accounts"
									              data-mt-default-values='<?php echo e(isset($oldAccounts) ? json_encode($oldAccounts) : "{}"); ?>'>
									          <input type="text" class="form-control" id="to-message" data-mt-filter-control/>
								        	</div>
								        </div>
								        <div class="form-group">
									        <label class="col-md-4 control-label">Allocations</label>
									        <div class="col-md-8 component-mt-select"
									        	data-mt-max-tags="100"
									             data-mt-request-url="/uadmin/ajaxAllocations.php"
									              data-mt-tag-input-name="allocations"
									              data-mt-default-values='<?php echo e(isset($oldAllocations) ? json_encode($oldAllocations) : "{}"); ?>'>
									          <input type="text" class="form-control" id="to-message" data-mt-filter-control/>
								        	</div>
								        </div>
								        <?php endif; ?>
										<div class="form-group">
										<div class="col-sm-12 col-md-12 morePadding">
												<button type="submit" class="btn btn-primary" style="float: right;">
													Save
												</button>
											</div>
										</div>
										
									</form>
								</div>
							</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" href="<?php echo e(url('mt-select/css/style.css')); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>
<script type="text/javascript" src="<?php echo e(url('mt-select/js/jquery-mt-select.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>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>