<!DOCTYPE html>
<html lang="en">
<head>
  <%- include('./partials/head') %>
</head>
<body>
  <%- include('./partials/navbar1') %>

  <div class="jumbotron jumbotron-fluid" style="background-image: url(background2.svg); background-repeat: no-repeat; background-position: center;" >
    <div class="container">
      <div class="row" style="margin-top: 100px; margin-bottom: 50px;">
        <div class="col-lg-12">
          <h1 style="text-align: center; margin-top: 0px;  justify-content: center; font-weight: 800;">Welcome !!</h1>
        </div> 
      </div>
    </div>
  </div>

    <div class="jumbotron" style="background-color: white;" >
      <% if (projects.length > 0) { %>
        <% projects.forEach(pp => { %>
          <% if(pp.status==1) {%>
          <div class="jumbotron" style="background-color: rgba(255, 174, 0, 0.863);">
            <div class="">
              <div class="row">
                <div class="col-lg-6 col-md-12 col-sm-12">
                  <img src="data:image/<%=pp.project_image.contentType%>;base64,
                  <%=pp.project_image.data.toString('base64')%>" style="width: 90%; height: auto;" >
                </div>
                <div class="col-lg-6 col-md-12 col-sm-12">
                  <h2 style="text-align: center; text-transform: capitalize; color: crimson; font-weight: 800;">
                    <%= pp.title %>
                  </h2>
                  <ul>
                    <li>
                      <h5 style="text-transform: capitalize;"></p><%=pp.point1%></h5>
                    </li>
                    <li>
                      <h5 style="text-transform: capitalize;"></p><%=pp.point2%></h5>
                    </li>
                  </ul>
                  <br>
                  <div  >
                  <a href="/admineditproject/<%=pp._id%>"><button type="submit" class="btn btn-outline-dark" style="transition: 0.4s; margin-right: 30px; margin-left: 50px;">Readmore</button></a>
                  <a class="delete" data-doc="<%= pp._id %>">
                    <img src="/trashcan.svg" alt="delete icon">
                  </a>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <%}%>
          <% }) %>
          <% } else { %>
            <p style="text-align: center; font-weight: 800; "><span style="text-align:center">There are no projects to display at this Moment :)</span></p>
          <% } %>

  </div>


  

   






  <%- include('./partials/footer') %>

  <script>
    const trashcan = document.querySelector('a.delete');
    trashcan.addEventListener('click', (e) => {
      const endpoint = `/admineditproject/${trashcan.dataset.doc}`;
      fetch(endpoint, {
        method: 'DELETE',
      })
      .then(response => response.json())
      .then(data => window.location.href = data.redirect)
      .catch(err => console.log(err));
    });
  </script>


    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>