<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Pages</h1>
    	</div>
    </div>
    <?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-12">
                    <div class="panel panel-default">
                
						
						<div class="panel-heading">
                            Edit Page: <?php echo e($page->name); ?>

                            <a href="<?php echo e(url('uadmin/pages/'.$page->id)); ?>" style="float: right;" title="Edit Page Sections">
			                	<i class="fa fa-puzzle-piece fa-fw"></i>
			                </a>
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12">
			                        <form id="theForm" class="form-horizontal" role="form" method="POST" action="<?php echo e(url('admin/pages/edit')); ?>">
										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<input type="hidden" name="pageID" value="<?php echo e($page->id); ?>">
										<?php $cnt = 1;?>
										<?php foreach($page_sections as $page_section): ?>
										<input type="hidden" name="page_section<?php echo e($cnt); ?>" value="<?php echo e($page_section->id); ?>">
										<?php $cnt++; ?>
										<?php endforeach; ?>
										<div class="form-group">
											<label class="col-md-3 control-label">Page Name</label>
											<div class="col-md-7">
												<?php if(old('name')): ?>
												<input type="text" class="form-control" name="name" value="<?php echo e(old('name')); ?>">
												<?php else: ?>
												<input type="text" class="form-control" name="name" value="<?php echo e($page->name); ?>">	
												<?php endif; ?>
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-3 control-label">Page Title</label>
											<div class="col-md-7">
												<?php if(old('title')): ?>
												<input type="text" class="form-control" name="title" value="<?php echo e(old('title')); ?>">
												<?php else: ?>
												<input type="text" class="form-control" name="title" value="<?php echo e($page->title); ?>">
												<?php endif; ?>
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-3 control-label">Page URL</label>
											<div class="col-md-7">
												<?php if(old('url')): ?>
												<input type="text" class="form-control" name="url" value="<?php echo e(old('url')); ?>">
												<?php else: ?>
												<input type="text" class="form-control" name="url" value="<?php echo e($page->url); ?>">
												<?php endif; ?>	
											</div>
										</div>
										<?php $count = 1;?>
										<?php foreach($page_sections as $page_section): ?>
										<div class="form-group">
											
											<label class="col-md-3 control-label"><a href="<?php echo e(url('uadmin/sections/edit/'.$page_section->section)); ?>" target="_blank">Section <?php echo e($count); ?></a></label>
											<div class="col-md-7">
												<select id="section<?php echo e($count); ?>" class="form-control" name="section<?php echo e($count); ?>">
													<option value="0">Select One</option>
													<?php foreach($sections as $section): ?>
													<option 
														<?php if($page_section->section == $section->id): ?>
														selected 
														<?php endif; ?>
														value="<?php echo e($section->id); ?>">
														<?php echo e($section->name); ?>

													</option>
													<?php endforeach; ?>
												</select>
											</div>
											<div class="col-md-2" style="visibility: hidden;">
												<input type="number" min="0" max="12" class="form-control" name="width<?php echo e($count); ?>" value="<?php echo e($page_section->width); ?>">	
											</div>
										</div>
										<?php $count++; ?>
										<?php endforeach; ?>
										<div id="here"></div>
										<div class="form-group">
											<div class="col-md-8 col-md-offset-3">
												
												<button type="button" id="plus" class="btn btn-primary" onclick="addSection()" 
													<?php if(count($page_sections) >= 12): ?>
													disabled 
													<?php endif; ?>
													>
													<i class="fa fa-plus"></i>
												</button>
												<button type="button" id='minus' class="btn btn-primary" onclick="removeSection()" 
													<?php if(count($page_sections) <= 1): ?>
													disabled 
													<?php endif; ?>
													>
													<i class="fa fa-minus"></i>
												</button>
												<button type="submit" class="btn btn-primary">
													Save
												</button>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

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

<?php $__env->startSection('extras'); ?>
	<script>
		function addSection()
		{

			var allSections = document.getElementById('section1');
			var theForm = document.getElementById('theForm');
			
			var newFormGroup = document.createElement("div");
			newFormGroup.className = "form-group";
			var newLabel = document.createElement("label");
			newLabel.className = "col-md-3 control-label";
			var newColumn = document.createElement("div");
			newColumn.className = "col-md-7";
			var newSelect = document.createElement("select");
			newSelect.className = "form-control";
			var newWidth = document.createElement("div");
			newWidth.className = "col-md-2";
			var newNumber = document.createElement("input");
			newNumber.className = "form-control";
			
			var count = 1;
			while(document.getElementById('section' + count) != null)
			{
				count++;
			}

			newSelect.setAttribute("id", 'section' + count);
			newSelect.setAttribute("name", 'section' + count);
			newSelect.innerHTML = allSections.innerHTML;

			newLabel.innerHTML = 'Section ' + count;

			newNumber.setAttribute('type', 'number');
			newNumber.setAttribute('name', 'width' + count);
			newNumber.setAttribute('min', '0');
			newNumber.setAttribute('max', '12');
			newNumber.setAttribute('value', '0');

			newWidth.appendChild(newNumber);
			newWidth.style.visibility = "hidden";
			
			newFormGroup.appendChild(newLabel);
			newColumn.appendChild(newSelect);
			newFormGroup.appendChild(newColumn);
			newFormGroup.appendChild(newWidth);

			var here = document.getElementById('here');
			theForm.insertBefore(newFormGroup, here);

			if(count >= 12) document.getElementById('plus').disabled = true;
			if(count > 1) document.getElementById('minus').disabled = false;
			
		}
		function removeSection()
		{
			var theForm = document.getElementById('theForm');
			
			var count = 1;
			while(document.getElementById('section' + count) != null)
			{
				count++;
			}
			count--;
			var section = document.getElementById('section' + count).parentNode.parentNode;
			theForm.removeChild(section);
			if(count == 2) document.getElementById('minus').disabled = true;
			if(count <= 12) document.getElementById('plus').disabled = false;
			
		}
		
	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>