<?php $__env->startSection('content'); ?>
<div class="container-fluid parallax-six modul-bt-one" data-speed="5" data-type="background">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="big-title">
                    <h1>Edit Section</h1>
                </div>
            </div>
        </div>
	</div>
</div>

<div class="container-fluid">
	<div class="row">
		<div class="col-md-12 col-md-offset-0">
			<div class="panelX panel-defaultX">

				<div class="panel-body">
					<?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; ?>

					<form id="editForm" class="form-horizontal" role="form" method="POST" action="<?php echo e(url('admin/sections/edit')); ?>"
						onsubmit="document.getElementById('content').value = editor.getValue()">
						<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
						<input type="hidden" name="id" value="<?php echo e($section->id); ?>">
						
						<?php if(old('content')): ?>
						<input type="hidden" id="content" name="content" value="<?php echo e(old('content')); ?>">
						<?php else: ?>
						<input type="hidden" id="content" name="content" value="<?php echo e(trim($section->content)); ?>">
						<?php endif; ?>
						
						<div class="form-group">
							<label class="col-md-2 control-label" style="text-align: left;">Section Name</label>
							<div class="col-md-4">
								
								<?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(trim($section->name)); ?>">
								<?php endif; ?>
									
							</div>
							<label class="col-md-2 control-label" style="text-align: left;">Section Type</label>
							<div class="col-md-4">
								<select class="form-control" name="type">
									<option <?php if($section->type=='content'): ?> <?php echo e('selected'); ?> <?php endif; ?> 
										value="content">Content</option>
									<option <?php if($section->type=='script'): ?> <?php echo e('selected'); ?> <?php endif; ?> 
										value="script">Script</option>
									<option <?php if($section->type=='style'): ?> <?php echo e('selected'); ?> <?php endif; ?> 
										value="style">Style</option>
								</select>
							</div>
						</div>
						
						<div id="editor" class="col-md-12"></div>

						<div class="form-group">
							<input type="hidden" name="save" value="">
							<div class="col-md-6 col-md-offset-0" style="margin: 15px 0px;">
								<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>

    	<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());
        	editor.setValue(document.getElementById('content').value, -1);

        	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);

        	editor.commands.addCommand({
        	    name: 'saveCommand',
        	    bindKey: {win: 'Ctrl-S',  mac: 'Command-S'},
        	    exec: function(editor) {
        	    	document.getElementById('content').value = editor.getValue()
        	        document.getElementById('editForm').submit();
        	    }
        	});
    	</script>

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

<?php $__env->startSection('extras'); ?>
	    <style>
	    	#editor {
        		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.adminT', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>