<% include ../partials/header.ejs %>

  <!-- MAIN CONTENT -->
  <div class="container">
    <div class="row">
      <div class="col-md-offset-1 col-md-10">
        <h3>Surveys List </h3>
        <% if(typeof displayName == 'string' && displayName) { %>
          <a href="/surveys/add" class="btn btn-primary"><i class="fa fa-plus"></i> Add a survey</a>
        <%}%>
        <br>
        <div class="table-responsive">
          <table class="table table-bordered table-striped table-hover">
            <thead>
              <!-- Header Row -->
              <tr>
                <% if(typeof displayName == 'string' && displayName) { %>
                  <th>Title</th>
                  <th class="text-center">Owner</th>
                  <th class="text-center">Questions</th>
                  <th class="text-center">Active?</th>
                  <th class="text-center">Start Date</th>
                  <th class="text-center">End Date</th>
                  <th class="text-center"></th>
                  <th class="text-center"></th>
                  <th class="text-center"></th>
                <% } else { %>
                  <th>Title</th>
                  <th class="text-center">Owner</th>
                  <th class="text-center">Questions</th>
                  <th class="text-center">Active?</th>
                  <th class="text-center">Start Date</th>
                  <th class="text-center">End Date</th>
                  <th class="text-center"></th>
                <% } %>
              </tr>
            </thead>

            <tbody>
              <!-- Template Row -->
              <% for (let count = 0; count < surveys.length; count++) { %>
                <tr>
                  <% if(typeof displayName == 'string' && displayName) { %>
                    <td><%= surveys[count].Title %></td>
                    <td class="text-center"><%= surveys[count].Owner %></td>
                    <td class="text-center"><%= surveys[count].Questions %></td>
                    <td class="text-center"><%= surveys[count].Active %></td>
                    <td class="text-center"><%= moment(surveys[count].StartDate).format('YYYY-MM-DD') %></td>
                    <td class="text-center"><%= moment(surveys[count].EndDate).format('YYYY-MM-DD') %></td>
                    <td class="text-center">
                      <a href="/surveys/<%= surveys[count]._id %>" class="btn btn-primary btn-sm"> View</a>
                    </td>
                    <% if(surveys[count].Owner == displayName) { %>
                    <td class="text-center">
                      <a href="/surveys/edit/<%= surveys[count]._id %>" class="btn btn-warning btn-sm"> Edit</a>
                    </td>
                    <td class="text-center">
                      <a href="/surveys/delete/<%= surveys[count]._id %>" class="btn btn-danger btn-sm"> Delete</a>
                    </td>
                    <% } %>
                  <% } else { %>
                    <% if(surveys[count].Active) { %>
                      <td><%= surveys[count].Title %></td>
                      <td class="text-center"><%= surveys[count].Owner %></td>
                      <td class="text-center"><%= surveys[count].Questions.length %></td>
                      <td class="text-center"><%= surveys[count].Active %></td>
                      <td class="text-center"><%= moment(surveys[count].StartDate).format('YYYY-MM-DD') %></td>
                      <td class="text-center"><%= moment(surveys[count].EndDate).format('YYYY-MM-DD') %></td>
                      <td class="text-center">
                        <a href="/surveys/<%= surveys[count]._id %>" class="btn btn-primary btn-sm"> View</a>
                      </td>
                    <% } %>
                  <% } %>
                </tr>
              <% } %>
            </tbody>
          </table>
        </div>
        <div class="col-md-offset-1 col-md-10 text-center">
          <ul class="pagination pagination-lg pager" id="myPager"></ul>
        </div>
      </div>
    </div>
  </div>

<% include ../partials/footer.ejs %>


