<div class="page-margin">
	<div class="row">
		<div class="col-md-2 leftcol"><?php echo Wo_LoadPage("sidebar/left-sidebar"); ?></div>
		<div class="col-md-7 middlecol">
			<div class="page-margin wow_content mt-0">
				<div class="wo_page_hdng pag_neg_padd pag_alone">
					<div class="wo_page_hdng_innr">
						<span><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M17,14H19V17H22V19H19V22H17V19H14V17H17V14M12.4,5H18V12C15.78,12 13.84,13.21 12.8,15H11L10.6,13H5V20H3V3H12L12.4,5Z"></path></svg></span> <?php echo $wo['lang']['create_new_page'];?>
					</div>
				</div>
			</div>
			
            <div class="page-margin wow_content wow_sett_content">
				<form class="create-page-form form-horizontal" method="post">
					<div class="wow_form_fields">
						<label for="page_title"><?php echo $wo['lang']['page_name']; ?></label>
						<input id="page_title" name="page_title" type="text">
						<span class="help-block"><?php echo $wo['lang']['your_page_title'];?></span>
					</div>
					<div class="wow_form_fields">
						<label for="page_name"><?php echo $wo['lang']['page'];?> URL</label>
						<div class="input-group">
							<span class="input-group-addon"><?php echo $wo['config']['site_url'];?>/</span>
							<input id="page_name" name="page_name" type="text">
						</div>
					</div>
					<div class="wow_form_fields">
						<label for="page_category"><?php echo $wo['lang']['page_category']; ?></label>
						<select name="page_category" id="page_category" onchange="GetPageSubCategory(this)">
							<?php foreach ($wo['page_categories'] as $category_id => $category_name) {?>
								<option value="<?php echo $category_id?>"><?php echo $category_name; ?></option>
							<?php } ?>
						</select>
					</div>
					<?php if (!empty($wo['page_sub_categories'])) { ?>
					<div class="wow_form_fields">
						<label for="page_sub_category"><?php echo $wo['lang']['sub_category']; ?></label>
						<select name="page_sub_category" id="page_sub_category">
							<?php
							if (!empty($wo['page_sub_categories'][array_keys($wo['page_categories'])[0]])) {
							foreach ($wo['page_sub_categories'][array_keys($wo['page_categories'])[0]] as $id => $sub_category) { ?>
								<option value="<?php echo $sub_category['id']?>"><?php echo $sub_category['lang']; ?></option>
							<?php } } ?>
						</select>
					</div>
				    <?php } ?>
					<div class="wow_form_fields">
						<label for="page_description"><?php echo $wo['lang']['page_description']; ?></label>
						<textarea name="page_description" id="page_description" rows="3"></textarea>
						<span class="help-block"><?php echo $wo['lang']['page_description_info'];?></span>
					</div>
					<?php $fields = Wo_GetCustomFields('page'); 
					if (!empty($fields)) {
						foreach ($fields as $key => $wo['field']) {
							echo Wo_LoadPage('page/fields');
						}
					}
					?>
				  	<div class="app-general-alert setting-update-alert"></div>
					<div class="text-center">
						<a class="btn btn-mat" data-ajax="?link1=pages" href="<?php echo Wo_SeoLink('index.php?link1=pages');?>">
							<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"></path></svg> <?php echo $wo['lang']['go_back'];?>
						</a>
						<button class="btn btn-main btn-mat btn-mat-raised add_wow_loader" type="submit"><?php echo $wo['lang']['create']; ?></button>
					</div>
					<input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
				</form>
			</div>
		</div>
		<!-- .col-md-8 -->
		<?php echo Wo_LoadPage('sidebar/content');?>
	</div>
   <!-- .row -->
</div>
<!-- .page-margin -->
<script type="text/javascript">
	<?php 
$js_array = json_encode($wo['page_sub_categories']);
echo "var sub_categories_array = ". $js_array . ";\n";
?>
	function GetPageSubCategory(self) {
		id = $(self).val();
		var text = "";
		if (typeof(sub_categories_array[id]) == 'undefined') {
		    $('#page_sub_category').html('');
		}
		else{
		   	sub_categories_array[id].forEach(function(entry) {
				text = text + "<option value='"+entry.id+"'>"+entry.lang+"</option>";
			});
		    $('#page_sub_category').html(text);
		}
	}
   $(function() {
     $('form.create-page-form').ajaxForm({
       url: Wo_Ajax_Requests_File() + '?f=pages&s=create_page',
       beforeSend: function() {
         $('.create-page-form').find('.add_wow_loader').addClass('btn-loading');
       },
       success: function(data) {
         scrollToTop();
         if (data.status == 200) {
           window.location.href = data.location;
         } else {
             var errors = data.errors.join("<br>");
             $('.app-general-alert').html('<div class="alert alert-danger">' + errors + '</div>');
             $('.alert-danger').fadeIn(300);
         }
         $('.create-page-form').find('.add_wow_loader').removeClass('btn-loading');
       }
     });
   });
</script>