$(document).ready(function(){


var url_string = window.location.href;
var url = new URL(url_string);
var searchKey = url.searchParams.get("id");

//console.log("1")
//console.log(searchKey);
var urlBase = "http://0.0.0.0:30000";

if(!searchKey)
{
// console.log("2")
// window.location.replace("href="/projectDetail?id='+data+'"");
 return;
}

  //console.log("3")
    var queryUrl = urlBase+"/queryProject";
    var queryClient = urlBase+"/queryClient";
    var queryEmployee = urlBase+"/queryEmployee";
   
    $.ajax({
      type: 'GET',
      url: queryUrl,
      data: { key: searchKey },
      crossDomain:true,
      
      success: function(data, status, jqXHR){
          let record = data.Record;
          //console.log(data);
        $("#projectID").text(data.projectID);
          $("#projectName").text(data.projectName);
          $("#descreption").text(data.descreption);
          $("#projectStatus").text(data.projectStatus);


          
         // $("#projectLeaderID").text(data.projectLeaderID);
          //$("#clientID").text(data.clientID);
          
          $("#estimatedBudget").text(data.estimatedBudget);
          $("#estimatedDuration").text(data.estimatedDuration);
          $("#deadline").text(data.deadline);
          $("#createDateTime").text(data.createDateTime);

          ajaxCall2(data.clientID);
          ajaxCall3(data.projectLeaderID);
      },
      error: function(xhr, textStatus, error){
          console.log(xhr.statusText);
          console.log(textStatus);
          console.log(error);
          alert("Error: llllllllllllllllllllll"+ xhr.responseText);
      }
    });
    
////////////////////////////////

function ajaxCall2(a){
$.ajax({
    type: 'GET',
    url: queryClient,
    //crossDomain:true,
    data: { key: a },
    success: function(data, status, jqXHR){
        let record = data.Record;
       // console.log(data);
      $("#flnameclient").text(data.firstName+" "+data.lastName);
        $("#phoneNumberclient").text(data.phoneNumber);
        $("#emailclient").text(data.email);
    },
    error: function(xhr, textStatus, error){
        console.log(xhr.statusText);
        console.log(textStatus);
        console.log(error);
        alert("Error: llllllllllllllllllllll"+ xhr.responseText);
    }
  });

}

function ajaxCall3(a){
  $.ajax({
    type: 'GET',
    url: queryEmployee,
    data: { key: a},
    success: function(data, status, jqXHR){
        let record = data.Record;
        //console.log(data);
      $("#flname").text(data.firstName+" "+data.lastName);
        $("#phoneNumber").text(data.phoneNumber);
        $("#email").text(data.email);
    },
    error: function(xhr, textStatus, error){
        console.log(xhr.statusText);
        console.log(textStatus);
        console.log(error);
        alert("Error: llllllllllllllllllllll"+ xhr.responseText);
    }
  });
}
   

//////////////////////////////////////////////////////////////////





});
