<div class="page-margin mt-0">
	<div class="wow_content popular_posts_hdr">
		<h2><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>&nbsp;<?php echo $wo['lang']['general_setting'];?></h2>
	</div>
</div>

<div class="wo_settings_page wow_content">
	<form class="setting-general-form form-horizontal" method="post">
		<div class="setting-general-alert"></div>
		<div class="row">
			<div class="col-md-7">
				<div class="wow_form_fields">
					<label for="group_title"><?php echo $wo['lang']['group_name']; ?></label>
					<input name="group_title" id="group_title" type="text" value="<?php echo $wo['setting']['group_title']?>" autocomplete="off">
				</div>
			</div>
			<div class="col-md-5">
				<div class="wow_form_fields">
					<label for="group_category"><?php echo $wo['lang']['category'] ?></label>
					<select id="group_category" name="group_category" onchange="GetGroupSubCategory(this)">
						<?php 
							foreach ($wo['group_categories'] as $categorie_id => $category) {
							$selected_contry = ($categorie_id == $wo['setting']['category_id']) ? ' selected' : '' ;
						?>
						<option value="<?php echo $categorie_id;?>" <?php echo $selected_contry;?> ><?php echo $category;?></option>
						<?php } ?>
					</select>
				</div>
			</div>
			<div class="col-md-5">
				<div class="wow_form_fields page_sub_category_c" style="<?php echo (!empty($wo['group_sub_categories'][array_keys($wo['group_categories'])[0]]) ? '' : 'display: none;'); ?>">
					<label for="group_sub_category"><?php echo $wo['lang']['sub_category'] ?></label>
					<select id="group_sub_category" name="group_sub_category">
						<?php
						if (!empty($wo['group_sub_categories'][array_keys($wo['group_categories'])[0]])) {
						foreach ($wo['group_sub_categories'][array_keys($wo['group_categories'])[0]] as $id => $sub_category) { 
							$sub_selected = ($sub_category['id'] == $wo['setting']['sub_category']) ? ' selected' : '' ;
							?>
							<option value="<?php echo $sub_category['id']?>" <?php echo $sub_selected; ?>><?php echo $sub_category['lang']; ?></option>
						<?php } } ?>
					</select>
				</div>
			</div>
		</div>
		<div class="wow_form_fields">
			<label for="group_name"><?php echo $wo['lang']['group'];?> URL</label>
			<div class="input-group">
				<span class="input-group-addon"><?php echo $wo['config']['site_url'];?>/</span>
				<input id="group_name" name="group_name" type="text" value="<?php echo $wo['setting']['group_name']?>" onkeyup="Wo_CheckGroupname(this.value, <?php echo $wo['setting']['id'];?>);" autocomplete="off">
			</div>
			<span class="help-block checking"></span>
		</div>
		<div class="wow_form_fields">
			<label for="about"><?php echo $wo['lang']['description'];?></label>
			<?php 
				$text = br2nl($wo['setting']['about']);
			?>  
			<textarea id="about" name="about" rows="4"><?php echo $text;?></textarea>
		</div>
		<?php $fields = Wo_GetCustomFields('group'); 
		if (!empty($fields)) {
			foreach ($fields as $key => $wo['field']) {
				echo Wo_LoadPage('group-setting/fields');
			}
		}
		?>
		<div class="text-center">
			<button class="btn btn-main btn-mat btn-mat-raised add_wow_loader" type="submit"><?php echo $wo['lang']['save']; ?></button>
		</div>
		<input type="hidden" name="group_id" value="<?php echo $wo['setting']['id'];?>">
		<input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
	</form>
</div>

<script type="text/javascript">
	<?php 
$js_array = json_encode($wo['group_sub_categories']);
echo "var sub_categories_array = ". $js_array . ";\n";
?>
	function GetGroupSubCategory(self) {
		id = $(self).val();
		var text = "";
		if (typeof(sub_categories_array[id]) == 'undefined') {
		    $('#group_sub_category').html('');
		    $('.page_sub_category_c').slideUp();
		}
		else{
			$('.page_sub_category_c').slideDown();
		   	sub_categories_array[id].forEach(function(entry) {
				text = text + "<option value='"+entry.id+"'>"+entry.lang+"</option>";
			});
		    $('#group_sub_category').html(text);
		}
	}
$(function() {
  $('form.setting-general-form').ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=groups&s=update_general_settings',
    beforeSend: function() {
      $('.setting-general-form').find('.add_wow_loader').addClass('btn-loading');
    },
    success: function(data) {
      scrollToTop();
      if (data.status == 200) {
        $('.setting-general-alert').html('<div class="alert alert-success">' + data.message + '</div>');
        $('.alert-success').fadeIn('fast', function() {
           $(this).delay(2500).slideUp(500, function() {
              $(this).remove();
            });
        });
      } else {
          var errors = data.errors.join("<br>");
          $('.setting-general-alert').html('<div class="alert alert-danger">' + errors + '</div>');
          $('.alert-danger').fadeIn(300);
      }
      $('.setting-general-form').find('.add_wow_loader').removeClass('btn-loading');
    }
  });
});
</script>