const SearchURL = "php/FTA_Details.php";

const searchForm = document.getElementById("searchForm");

searchForm.addEventListener("submit", function (event) {
    event.preventDefault();
    var spinnerClassIcon = document.getElementById("searchSiteIdSpinner");
    spinnerClassIcon.classList.remove("d-none");
    const formdata = {
        empId: searchForm.searchText.value,
        siteVisitDate: searchForm.siteVisitDate.value,
        detailsType:"onlyRequiredFields"
    };

    postData(SearchURL, formdata).then(data => {
        // let { siteinfo } = data;

        list.innerHTML = "";
        //console.log(data);
        

        if (data == "results not found") {
            let card = `<div class="car-holder col-xs-12  col-sm-6 col-lg-4 mx-auto my-1 p-4"> <div class="card "> <div class="card-content">
  <div class="card-body ">
    <h6 class="card-title info text-center mb-0"">${data}</h6>    
  </div>  
</div>
</div>
</div>`;
            list.innerHTML += card;
        } else
            data.forEach(detailsArray => {
                let card = `<div class="car-holder col-xs-12  col-sm-6 col-lg-4 mx-auto my-1 p-4"> <div class="card "> <div class="card-content">
      <div class="card-body ">
        <table>
            <tbody>
                <tr><th>Name:</th><td>${detailsArray.name}</td></tr>
                <tr><th>Site-id:</th><td>${detailsArray.siteId}</td></tr>
                <tr><th>Visit-order:</th><td>${detailsArray.siteVisitOrder}</td></tr>
            </tbody>
        </table>
      </div>
      <div class="card-footer">
        <a href="html/Update_FTA_Details.php?empId=${detailsArray.empId}&siteVisitDate=${detailsArray.siteVisitedDate}&siteVisitOrder=${detailsArray.siteVisitOrder}" class="btn btn-outline-info">Check FTA info <i class="fa fa-arrow-right"></i></a>
      </div>
    </div>
  </div>
  </div>`;
                list.innerHTML += card;
            });
   /*     
       if (typeof(Storage) !== "undefined") {
            localStorage.FTADetailsArray=JSON.stringify(data);
        }
        */
        spinnerClassIcon.classList.add("d-none");
    });
});
;;