<?php
	$code = custom_design("get");
?>
<div class="container-fluid">
    <div class="block-header">
        <h2>Design > Custom Design</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="header">
                    <h2>Custom JS / CSS</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success ads-settings-alert"></div>
                    <form class="custom-design-settings" method="POST">
                        <div class="form-group">
                        	<label class="form-label">Header Custom JavaScript</small></label>
                            <textarea name="header_js" id="custom-header-js" class="form-control"><?php echo $code[0];?></textarea>
                        </div>
                       <div class="form-group">
                        	<label class="form-label">Footer Custom JavaScript</small></label>
                            <textarea name="footer_js" id="custom-footer-js" class="form-control"><?php echo $code[1];?></textarea>
                        </div>
                        <div class="form-group">
                        	<label class="form-label">Header CSS Style</small></label>
                            <textarea name="css_styles" id="custom-css-code" class="form-control"><?php echo $code[2]; ?></textarea>
                        </div>
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Save</button>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
$(function() {
    	var form_ads_settings = $('form.custom-design-settings');
        var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('custom-header-js'), {
	        mode: "javascript",
	        theme: "default",
	        lineNumbers: true,
	        readOnly: false
        });

        var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('custom-footer-js'), {
        	mode: "javascript",
        	theme: "default",
        	lineNumbers: true,
        	readOnly: false
        });

        var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('custom-css-code'), {
        	mode: "css",
        	theme: "default",
        	lineNumbers: true,
        	readOnly: false
        });   

	    form_ads_settings.ajaxForm({
	        url: '{{LINK aj/ap/save-custom-design-settings}}',
	        dataType:'json',
	        beforeSend: function() {
	            form_ads_settings.find('.waves-effect').text('Please wait..');
	        },
	        success: function(data) {
	        	if (data.status == 200) {
	                swal({
	                  title: "Changes Saved!",
	                  text: "Your changes have been saved successfully",
	                  type: "success"
	                });
		        }

	            else if (data.status == 500) {
	            	var error  = "";
	            	
	            	for (key in data.errors) {
	            		error  = data.errors[key];
	            		break;
	            	}

	                swal({
	                	title: "File Permissions Error!",
	                	text: error,
	                	type: "error"
	                });
	            }

	            setTimeout(function(){
	               swal.close();
	            }, 5000);

		        form_ads_settings.find('.waves-effect').text('Save');
	            $("html, body").animate({ scrollTop: 0 }, "slow");
	        }
	    });
});

</script>