<div class="page-margin mt-0">
	<div class="wow_content popular_posts_hdr">
		<h2><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.08301 13.1171C7.08301 12.2976 7.67353 11.5995 8.47606 11.4704C9.48542 11.3079 10.5139 11.3079 11.5233 11.4704C12.3258 11.5995 12.9163 12.2976 12.9163 13.1171V13.2985C12.9163 13.7778 12.531 14.1663 12.0558 14.1663H7.94359C7.4683 14.1663 7.08301 13.7778 7.08301 13.2985V13.1171Z" class="icon_main" stroke-width="1.5"/><path d="M11.7011 7.54869C11.7011 8.49624 10.9393 9.26438 9.99967 9.26438C9.06002 9.26438 8.29829 8.49624 8.29829 7.54869C8.29829 6.60115 9.06002 5.83301 9.99967 5.83301C10.9393 5.83301 11.7011 6.60115 11.7011 7.54869Z" class="icon_main" stroke-width="1.5"/><path d="M17.5 5.83333C17.5 3.99238 15.6345 2.5 13.3333 2.5M2.5 13.3333C2.5 15.6345 3.99238 17.5 5.83333 17.5M5.83333 2.5C3.99238 2.5 2.5 3.99238 2.5 5.83333M13.3333 17.5C15.6345 17.5 17.5 15.6345 17.5 13.3333" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>&nbsp;<?php echo $wo['lang']['profile_setting']; ?></h2>
	</div>
</div>

<div class="wo_settings_page wow_content">

	<form  method="post" class="form-horizontal setting-profile-form">
		<div class="setting-profile-alert setting-update-alert"></div>
		
		<div class="wow_cset_cover">
            <div class="wow_cset_cover_hdr">
                <span class="btn btn-file" id="coverimage-holder" onclick="$('#cover').trigger('click'); return false;">
                    <img src="<?php echo $wo['setting']['cover'];?>" alt="<?php echo $wo['setting']['name'];?> Profile Picture">
                </span>
            </div>
			<div class="avatar-read" id="cover-form"><p></p></div>
		</div>
		<div class="wow_cset_avtr">
			<div>
				<div class="wow_cset_avtr_hdr">
					<span class="btn btn-file" id="avatarimage-holder" onclick="$('#avatar').trigger('click'); return false;" title="<?php echo $wo['lang']['avatar']; ?>">
						<img src="<?php echo $wo['setting']['avatar'];?>" alt="<?php echo $wo['setting']['name'];?> Profile Picture">
					</span>
				</div>
				<div>
					<h5><?php echo $wo['setting']['name'];?></h5>
					<p>@<?php echo $wo['setting']['username'];?></p>
				</div>
				<div class="avatar-read" id="photo-form"><p></p></div>
			</div>
			<div class="text-center">
				<button type="submit" class="btn btn-main btn-mat btn-mat-raised add_wow_loader"><?php echo $wo['lang']['save']; ?></button>
			</div>
		</div>
		
		<div class="row">
			<div class="col-md-6">
				<div class="wow_form_fields">
					<label for="first_name"><?php echo $wo['lang']['first_name']; ?></label>  
					<input id="first_name" name="first_name" type="text" value="<?php echo $wo['setting']['first_name'];?>">
				</div>
			</div>
			<div class="col-md-6">
				<div class="wow_form_fields">
					<label for="last_name"><?php echo $wo['lang']['last_name']; ?></label>  
					<input id="last_name" name="last_name" type="text" value="<?php echo $wo['setting']['last_name'];?>">
				</div>
			</div>
		</div>
		<div class="wow_form_fields">
			<label for="about"><?php echo $wo['lang']['about_me']; ?></label>  
			<?php $text = br2nl($wo['setting']['about']); ?>
			<textarea id="about" name="about" rows="4"><?php echo $text;?></textarea>
		</div>
		<div class="wow_form_fields">
			<label for="address"><?php echo $wo['lang']['location']; ?></label>  
			<input id="address" name="address" type="text" value="<?php echo $wo['setting']['address'];?>">
			<?php if ($wo['config']['yandex_map'] == 1) { ?>
          <div class="yandex_search_user"></div>
        <?php } ?>
		</div>
		<div class="wow_form_fields mb-0">
			<label for="school"><?php echo $wo['lang']['school']; ?></label>  
		</div>
		<div class="row">
			<div class="col-md-6">
				<div class="wow_form_fields mt-0">
					<input id="school" name="school" type="text" value="<?php echo $wo['setting']['school'];?>">
				</div>
			</div>
			<div class="col-md-6 round-check">
				<div><label class="mt-0"></label></div>
				<input type="checkbox" id="completed" name="completed" <?php echo ($wo['setting']['school_completed'] == 1)   ? 'checked' : '';?>>
				<label class="mt-0" for="completed"><?php echo $wo['lang']['completed']; ?></label>
			</div>
		</div>
		<hr>
		<div class="wow_form_fields mb-0">
			<label for="working"><?php echo $wo['lang']['working_at']; ?></label>  
		</div>
		<div class="row">
			<div class="col-md-6">
				<div class="wow_form_fields mt-0">
					<input id="working" name="working" type="text" value="<?php echo $wo['setting']['working'];?>">
					<span class="help-block">(e.g Apple)</span>
				</div>
			</div>
			<div class="col-md-6">
				<div class="wow_form_fields mt-0">
					<input id="working_link" name="working_link" type="text" value="<?php echo $wo['setting']['working_link'];?>">
					<span class="help-block"><?php echo $wo['lang']['company_website']; ?></span>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-6">
				<div class="wow_form_fields">
					<label for="website"><?php echo $wo['lang']['website']; ?></label>
					<input id="website" name="website" type="text" value="<?php echo $wo['setting']['website'];?>">
				</div>
			</div>
			<div class="col-md-6">
				<div class="wow_form_fields">
					<label for="relationship"><?php echo $wo['lang']['relationship']; ?></label>
					<select id="relationship" name="relationship" onchange="if(this.value > 1 && this.value <= 4){$('#choose_rel_ship').modal('show');}">
						<option value="0"><?php echo $wo['lang']['none']; ?></option>
						<?php 
							foreach ($wo['relationship'] as $relationship_ids => $relationship) { 
							$relationship_id = $wo['setting']['relationship_id'];
							$selected_relationship = ($relationship_ids == $relationship_id) ? ' selected' : '' ;
						?>
							<option value="<?php echo $relationship_ids;?>" <?php echo $selected_relationship;?> ><?php echo $relationship;?></option>
						<?php } ?>
					</select>
				</div>
			</div>
			<?php if ($wo['config']['website_mode'] == 'linkedin') { ?>
				<div class="col-md-12 skills_div">
					<div class="wow_form_fields">
						<label for="skills"><?php echo $wo['lang']['skills']; ?></label>
						<input id="skills" name="skills" type="text" value="<?php echo $wo['setting']['skills'];?>">
						<div class="skills_result"></div>
					</div>
				</div>
				<div class="col-md-12 languages_div">
					<div class="wow_form_fields">
						<label for="languages"><?php echo $wo['lang']['languages']; ?></label>
						<input id="languages" name="languages" type="text" value="<?php echo implode(",", $wo['setting']['formated_langs']);?>">
						<div class="dropdown-menu languages_result"></div>
					</div>
				</div>
		  <?php } ?>
		</div>

		<?php
			$fields = Wo_GetProfileFields('profile');
			if (count($fields) > 0) {
				foreach ($fields as $key => $wo['field']) {
					echo Wo_LoadPage('setting/profile-fields');
				}
				echo '<input name="custom_fields" type="hidden" value="1">';
			}
		?>

		<input type="hidden" name="user_id" id="user-id" value="<?php echo $wo['setting']['user_id'];?>">
		<input type="hidden" name="relationship_user" id="relationship_user_id" value="0">
		<input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
	</form>
	<form method="post" class="avatar-profile-form">
		<input type="file" class="hidden" id="avatar" accept="image/x-png, image/gif, image/jpeg" name="avatar">
		<input type="file" class="hidden" id="cover" accept="image/x-png, image/gif, image/jpeg" name="cover">
		<input type="hidden" name="user_id" id="user-id" value="<?php echo $wo['setting']['user_id'];?>">
		<input type="hidden" name="relationship_user" id="relationship_user_id" value="0">
		<input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
	</form>
</div>

<div class="modal fade" id="choose_rel_ship" role="dialog">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="wow_pops_head">
				<svg height="100px" preserveAspectRatio="none" version="1.1" viewBox="0 0 300 100" width="300px" xmlns="http://www.w3.org/2000/svg"><path d="M30.913,43.944c0,0,42.911-34.464,87.51-14.191c77.31,35.14,113.304-1.952,146.638-4.729 c48.654-4.056,69.94,16.218,69.94,16.218v54.396H30.913V43.944z" fill="currentColor" opacity="0.6"></path> <path d="M-35.667,44.628c0,0,42.91-34.463,87.51-14.191c77.31,35.141,113.304-1.952,146.639-4.729 c48.653-4.055,69.939,16.218,69.939,16.218v54.396H-35.667V44.628z" fill="currentColor" opacity="0.6"></path> <path d="M-34.667,62.998c0,0,56-45.667,120.316-27.839C167.484,57.842,197,41.332,232.286,30.428 c53.07-16.399,104.047,36.903,104.047,36.903l1.333,36.667l-372-2.954L-34.667,62.998z" fill="currentColor"></path></svg>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg></button>
				<h4><svg width="14" height="12" viewBox="0 0 14 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.65593 5.7404L5.07865 10.3405C6.06366 11.6643 7.93633 11.6643 8.92135 10.3405L12.3441 5.7404C13.2186 4.56499 13.2186 2.89481 12.3441 1.71939C11.0638 -0.00124529 8.10474 0.509785 7 2.36572C5.89526 0.509785 2.93619 -0.00124511 1.65593 1.71939C0.781357 2.8948 0.781355 4.56499 1.65593 5.7404Z" class="icon_main" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12.3441 5.7404L8.92135 10.3405C7.93633 11.6643 6.06366 11.6643 5.07865 10.3405L1.65593 5.7404C0.781355 4.56499 0.781357 2.8948 1.65593 1.71939C2.93619 -0.00124514 5.89526 0.509785 7 2.36572" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"></path></svg> <?php echo $wo['lang']['relationship_status']; ?></h4>
			</div>
			
			<div class="choose_rel_ship_alert">
             
			</div>
			<div class="modal-body">
				<div class="col-md-3">
					<div class="choose_rel_ship_avatar">
						<div>
							<i class="fa fa-user-circle-o"></i>
						</div>
					</div>
				</div>
				<div class="col-md-9">
					<div class="wow_form_fields">
						<label for=""><?php echo $wo['lang']['username']; ?></label>
						<input type="text" onkeyup="Wo_RelationshipSearch(this.value);" placeholder="">
						<div>
							<div class="dropdown" id="select_relationship_with">
								<ul class="dropdown-menu" style="width: 100%;">
                        
								</ul>
							</div>
						</div>
					</div>
					<div class="form-group choose_rel_ship_meta" >
						<h4></h4>
						<p class="user-lastseen"></p>  
					</div>
				</div>
				<div class="clear"></div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-main btn-mat" data-dismiss="modal"><?php echo $wo['lang']['save']; ?></button>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
<?php if ($wo['config']['website_mode'] == 'linkedin') { ?>
	$("#skills").tagsinput({});
	$("#languages").tagsinput({});

	$($('.skills_div .bootstrap-tagsinput').find('input')).on('keyup', function(event) {
			SearchSkill($(this).val())
	});

	$($('.languages_div .bootstrap-tagsinput').find('input')).on('keyup', function(event) {
			SearchLanguages($(this).val())
	});
<?php } ?>
var relationship_users = [];
var relationship_user  = 0;
function Wo_RelationshipSearch(name = ''){
  if (!name) { return false;}
  $.ajax({
    url: Wo_Ajax_Requests_File(),
    type: 'GET',
    dataType: 'json',
    data: {f: 'family',s:'search',name:name},
  })
  .done(function(data) {
    if (data.status == 200 && data.users.length > 0) {
      relationship_users = data.users
      var html = '';
      for (var i = 0; i < data.users.length; i++) {
        html += '<li class="pointer select_relationship_user" data-id="'+i+'"><a>'+data.users[i].name+'</a></li>';        
      }
      $("#select_relationship_with").addClass('open').find('ul').html(html);
    }
    else{
      $("#select_relationship_with").removeClass('open');
    }
  })
  .fail(function() {
    console.log("error");
  })
}

$(function() {
  $(document).on('click', '.select_relationship_user', function(event) {
    event.preventDefault();
    var user_data     = relationship_users[$(this).attr('data-id')];
    $("#relationship_user_id").val(user_data.user_id);
    $(".choose_rel_ship_meta").find('h4').text(user_data.name);
    $(".choose_rel_ship_meta").find('p').html(user_data.lastseen);
    $(".choose_rel_ship_avatar").html('<img src="'+user_data.avatar+'" alt="Picture">');
    $("#select_relationship_with").removeClass('open').find('ul').empty();
  });

  $('form.setting-profile-form').ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=update_profile_setting',
    beforeSend: function() {
      $('.wo_settings_page').find('.add_wow_loader').addClass('btn-loading');
    },
    success: function(data) {
    	$('form.avatar-profile-form').submit();
    	$('.skills_result').html('');
      if (data.status == 200) {
        <?php if($wo['user']['user_id'] == $wo['setting']['user_id']) { ?>
        if (data.first_name != '' || data.last_name != '') {
        	<?php if ($wo['config']['node_socket_flow'] == "1") { ?>
            socket.emit("on_name_changed", {from_id: _getCookie("user_id"), name: data.first_name + ' ' + data.last_name});
            <?php } ?>
          $('[id^=user-full-name]').text(data.first_name + ' ' + data.last_name);
        }
        <?php } ?>
        scrollToTop();
        $('.setting-profile-alert').html('<div class="alert alert-success">' + data.message + '</div>');
        $('.alert-success').fadeIn('fast', function() {
          $(this).delay(2500).slideUp(500, function() {
            $(this).remove();
          });
        });
      } else if (data.errors) {
        var errors = data.errors.join("<br>");
        scrollToTop();
        $('.setting-profile-alert').html('<div class="alert alert-danger">' + errors + '</div>');
        $('.alert-danger').fadeIn(300);
      }
      $('.wo_settings_page').find('.add_wow_loader').removeClass('btn-loading');
    }
  });
});
  var pac_input = document.getElementById('address');
  (function pacSelectFirst(input) {
    // store the original event binding function
    var _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent;
    function addEventListenerWrapper(type, listener) {
      // Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected,
      // and then trigger the original listener.
      if(type == "keydown") {
        var orig_listener = listener;
        listener = function (event) {
          var suggestion_selected = $(".pac-item-selected").length > 0;
          if(event.which == 13 && !suggestion_selected) {
            var simulated_downarrow = $.Event("keydown", {
              keyCode: 40,
              which: 40
            });
            orig_listener.apply(input, [simulated_downarrow]);
          }
          orig_listener.apply(input, [event]);
        };
      }
      // add the modified listener
      _addEventListener.apply(input, [type, listener]);
    }
    if(input.addEventListener)
      input.addEventListener = addEventListenerWrapper;
    else if(input.attachEvent)
      input.attachEvent = addEventListenerWrapper;
  })(pac_input);

  <?php if ($wo['config']['google_map']) { ?>
  $(function () {
     var autocomplete = new google.maps.places.Autocomplete(pac_input);
  });
  <?php }?>
<?php if ($wo['config']['yandex_map'] == 1) { ?>
  $(function() {
    $('#address').on( "keydown", function() {
      let self = this;
      var myGeocoder = ymaps.geocode($(this).val());
      myGeocoder.then(
          function (res) {
            if (res.geoObjects.getLength() == 0) {
              $('.yandex_search_user').html('');
            }
            else{
              let html = '';
              for (var i = 0; i < res.geoObjects.getLength(); i++) {
                html += '<p class="pointer" onclick="AddYandexResult(\'#address\',this,\'.yandex_search_user\')">'+res.geoObjects.get(i).properties.get('name')+'</p>';
              }
              $('.yandex_search_user').html(html);
            }
          },
          function (err) {
              $('.yandex_search_user').html('');
          }
      );
    });
  });
<?php } ?>
$(document).ready(function() {
	$("#cover").on('change', function() {
	//Get count of selected files
	$("#coverimage-holder").html("<img src='" + window.URL.createObjectURL(this.files[0]) + "' alt='Picture'>");
	});
});

$(document).ready(function() {
	$("#avatar").on('change', function() {
	//Get count of selected files
	$("#avatarimage-holder").html("<img src='" + window.URL.createObjectURL(this.files[0]) + "' alt='Picture'>");
	});
});

$(function() {
  $("#cover").change(function() {
            var filename = $(this).val().replace(/C:\\fakepath\\/i, '');
            $("#cover-form p").html(filename);
            $("#cover-form").fadeIn(200);
        });
  $('form.avatar-profile-form').ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=update_images_setting',
    beforeSend: function() {
      $('.wo_settings_page').find('.add_wow_loader').addClass('btn-loading');
    },
    success: function(data) {
      if (data.status == 200) {
        scrollToTop();
        $(".cover-read, .avatar-read").slideUp(200);
        if (data.avatar) {
          <?php if ($wo['config']['node_socket_flow'] == "1") { ?>
            socket.emit("on_avatar_changed", {from_id: _getCookie("user_id"), name: data.avatar});
          <?php } ?>
          var user_id = $('form.setting-profile-form').find('#user-id').val();
          $('[id^=updateImage-' + user_id + ']').fadeOut(300, function () { $('[id^=updateImage-' + user_id + ']').attr("src", data.avatar)}).fadeIn(300);
        }
        if (data.cover) {
          $('[id^=cover-image]').fadeOut(300, function () { $('[id^=cover-image]').attr("src", data.cover)}).fadeIn(300);
        }
        $('.setting-profile-alert').html('<div class="alert alert-success">' + data.message + '</div>');
        $('.alert-success').fadeIn('fast', function() {
          $(this).delay(2500).slideUp(500, function() {
            $(this).remove();
          });
        });
      } 
      $('.wo_settings_page').find('.add_wow_loader').removeClass('btn-loading');
    }
  });
});
</script>