/** Settings JS for the Core system setup */
var save_method;
/**=======================================
 * 
 * LOAD ITEMS BACK
 ==========================================*/
 $(document).ready(function(){
	$('a[data-bs-toggle="tab"]').on('show.bs.tab', function(e) {
		localStorage.setItem('activeTab', $(e.target).attr('href'));
	});
	var activeTab = localStorage.getItem('activeTab');
	if(activeTab){
		$('#myTab a[href="' + activeTab + '"]').tab('show');
	}
});

//Change Date DB to Bootstrap format
function dateToYMD(date) {
    var d = date.getDate();
    var m = date.getMonth() + 1; //Month from 0 to 11
    var y = date.getFullYear();
    return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
}


//Delete User
function delete_user(id, name)
{
  var confirmation = confirm('Are you sure you want to delete ' + name + '?');
  if (confirmation) {
      window.location.href = base_url + 'administrator/users/delete/' + id;
  }
}

/**=============== CHANGE USER PASSWORD =================*/
function change_pwd(id, name)
{
    $('#userPwdModal').modal('show');

    $("[name ='id']").val(id);
    $("[name='name']").val(name);

    $('.modal-title').text('Update User Password');
    $('.stbitn').text('Update');

    // Dynamic message for user and group
    $('#pwdChangeMessage').html(
        `You are about to change the password for this <strong>${name}</strong>. <small><i>Make sure you verify the user information before applying this update.</i></small> `
    );
}
/**=============== CHANGE USER GROUP =================*/
 function change_group(id, group, name)
 {
    
    $("#usergroupModal").modal('show');

    $("[name ='id']").val(id);
    $("[name='name']").val(name);
    $("[name='group']").val(group);
    
    $('.modal-title').text('Change User Group');
    $('.stbitn').text('Update');

    // Dynamic message for user and group
    $('#groupChangeMessage').html(
        `You are about to change <strong>${name}’s</strong> group from <strong>${group}</strong>. <br/><small><i>Make sure the information is correct before applying this update.</i></small>`
    );
 }