<div class="wo_settings_page sun_sett_page">
	<h3><?php echo $wo['lang']['general_setting'];?></h3>

	<form class="setting-general-form form-horizontal" method="post">
		<div class="setting-general-alert setting-update-alert"></div>
		
		<div class="setting-panel row">
			<!-- Text input-->
			<div class="sun_input col-lg-6">
				<input name="group_title" id="group_title" type="text" class="form-control input-md" value="<?php echo $wo['setting']['group_title']?>" autocomplete="off" placeholder="<?php echo $wo['lang']['group_name'];?>">
				<label class="plr15" for="group_title"><?php echo $wo['lang']['group_name'];?></label>  
			</div>
			
			<!-- Select Basic -->
			<div class="sun_input col-lg-6">
				<select id="group_category" name="group_category" class="form-control" 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>
				<label class="plr15" for="group_category"><?php echo $wo['lang']['category'];?></label>
			</div>
			<!-- Select Basic -->
			<div class="sun_input col-lg-6">
				<select id="group_sub_category" name="group_sub_category" class="form-control">
					<?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>
				<label class="plr15" for="group_sub_category"><?php echo $wo['lang']['sub_category'];?></label>
			</div>
			
			<!-- Textarea -->
			<div class="sun_input col-lg-12">
				<?php $text = br2nl($wo['setting']['about']); ?>  
				<textarea class="form-control" id="about" name="about" cols="20" rows="3" placeholder="<?php echo $wo['lang']['about'];?>"><?php echo $text;?></textarea>
				<label class="plr15" for="about"><?php echo $wo['lang']['about'];?></label>
			</div>
			
			<div class="form-group col-lg-12">
				<label class="col-md-12" for="group_name"><?php echo $wo['lang']['group'];?> URL</label>  
				<div class="col-md-12 input-group">
					<span class="input-group-addon"><?php echo $wo['config']['site_url'];?>/</span>
					<input id="group_name" name="group_name" type="text" class="form-control input-md" 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" style="padding: 0px 20px;"></span>
			</div>
			<?php $fields = Wo_GetCustomFields('group'); 
			if (!empty($fields)) {
				foreach ($fields as $key => $wo['field']) {
					echo Wo_LoadPage('group-setting/fields');
				}
			}
			?>
		</div>
		
		<div class="form-group last-sett-btn modal-footer">
			<div class="ball-pulse"><div></div><div></div><div></div></div>
			<button type="submit" class="btn btn-main setting-panel-mdbtn"><?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('');
		}
		else{
		   	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() {
      $('.wo_settings_page').find('.last-sett-btn .ball-pulse').fadeIn(100);
    },
    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);
      }
      $('.wo_settings_page').find('.last-sett-btn .ball-pulse').fadeOut(100);
    }
  });
});
</script>