<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Posts</h1>
    	</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">
                            Edit Post
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12">
				                    <form class="form-horizontal" role="form" method="POST" action="<?php echo e(url('admin/posts/edit')); ?>"
				                    onsubmit="document.getElementById('content').value = editor.getValue()">
										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<input type="hidden" id="content" name="content" value="">
										<input type="hidden" name="postID" value="<?php echo e($post->id); ?>">
										<div class="form-group">
											<label class="col-md-2 control-label">Post Name</label>
											<div class="col-md-8">
												<input type="text" class="form-control" name="name" value="<?php echo e(old('name') ? old('name') : $post->name); ?>">	
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-2 control-label">Post Date</label>
											<div class="col-md-3">
												<input type="date" class="form-control" name="date" value="<?php echo e(old('date') ? old('date') : $post->date); ?>">	
											</div>
											<label class="col-md-2 control-label">Expiration Date</label>
											<div class="col-md-3">
												<input type="date" class="form-control" name="expiration" value="<?php echo e(old('expiration') ? old('expiration') : $post->expiration); ?>">	
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-2 control-label">Category</label>
											<div class="col-md-3">
												<select  class="form-control" name="category">
													<option>None</option>
													<?php foreach($categories as $category): ?>
													<option value="<?php echo e($category->id); ?>" 
													<?php if(old('category') == $category->id || $post->category == $category->id): ?> 
														<?php echo e('selected'); ?> 
													<?php endif; ?>
													>
														<?php echo e($category->name); ?>

													</option>
													<?php endforeach; ?>
												</select>
											</div>
											<label class="col-md-2 control-label">Main Photo</label>
											<div class="col-md-3">
												<select  class="form-control" name="photo">
													<option value="">None</option>
													<?php foreach($photos as $photo): ?>
													<option value="<?php echo e($photo->id); ?>"
													<?php if(old('photo') == $photo->id || $post->photo == $photo->id): ?> 
														<?php echo e('selected'); ?> 
													<?php endif; ?>
													>
														<?php echo e($photo->name); ?>

													</option>
													<?php endforeach; ?>
												</select>
											</div>
										</div>
										<div class="form-group">
											<label class="col-md-2 control-label">Description</label>
											<div class="col-md-8">
												<textarea rows="2" name="description" class="form-control"><?php echo e(old('description') ? old('description') : $post->description); ?></textarea>
											</div>
										</div>
										
										<div id="editor" class="col-md-8"><?php echo e(old('content') ? old('content') : $post->content); ?></div>

										<div class="form-group">
											<div class="col-md-6 col-md-offset-0">
												<button type="submit" name="save" value="stay" class="btn btn-primary">
													Save
												</button>
												<button type="submit" name="save" value="close" class="btn btn-primary">
													Save & Close
												</button>
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
    	<script>
        	var editor = ace.edit("editor");
        	editor.setTheme("ace/theme/eclipse");
        	editor.setShowPrintMargin(false);
        	editor.setOption('wrap', true);
        	var phpMode = ace.require("ace/mode/php").Mode;
        	editor.getSession().setMode(new phpMode());
        	var heightUpdateFunction = function() {
            	var newHeight =
                    editor.getSession().getScreenLength()
                    * editor.renderer.lineHeight
                    + editor.renderer.scrollBar.getWidth();
            	document.getElementById('editor').setAttribute("style", "height:"+ newHeight +"px");
          		editor.resize();
            	};

            	heightUpdateFunction();
            	editor.getSession().on('change', heightUpdateFunction);
    	</script>

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

<?php $__env->startSection('extras'); ?>
	    <style>
	    	#editor {
	    	
	    		margin: 30px 10px 20px 0px;
        		position: relative;
        		width: 100%;
        		height: 500px;
    		}

    	</style>
    	<script src="<?php echo e(asset('js/ace/ace.js')); ?>" type="text/javascript" charset="utf-8"></script>
    	<script src="<?php echo e(asset('js/ace/mode-php.js')); ?>" type="text/javascript" charset="utf-8"></script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>