<?php

?>
<div class="content-wrapper">
          <div class="row">
          <div class="col-lg-12 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">Contact Messages</h4>
                  <div class="table-responsive">
                    <table class="table table-striped">
                      <thead>
                        <tr>
                          <th>
                            Email Address
                          </th>
                          <th>
                            Name
                          </th>
                          <th>
                            Subject
                          </th>
                          <th>
                            Message
                          </th>
                          <th>
                            Date
                          </th>
                          <th>
                            Action
                          </th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
          $contacts = $bankdata->get_contact_data();
          // print_r($contacts);
          foreach($contacts as $x_contact){
                        ?>
                        <tr>
                          <td class="py-1">
                            <?php echo $x_contact['contact_email']?>
                          </td>
                          <td>
                          <?php echo $x_contact['contact_name']?>
                          </td>
                          <td>
                          <?php echo $x_contact['contact_subject']?>
                          </td>
                          <td>
                          <?php echo $x_contact['contact_msg']?>
                          </td>  
                          <td>
                          <?php echo format_d_date_full($x_contact['created_at'])?>
                          </td> 
                          <td>
                          <button type="button" data-toggle="modal" data-target="#deleteProduct" onclick="deletePxd('<?php echo $x_contact['contact_id']?>')" class="btn btn-danger bg-white btn-icon mr-3 mt-2 mt-xl-0">
                    <i class="mdi mdi-trash-can text-muted"></i>
                  </button>
                          </td>                         
                        </tr>
          <?php } ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
          
        </div>	
        <script>
function deletePxd(data){
  document.querySelector('#delete_pxholder').value = data;
  }
  function deletePxdfn(){
    var data = document.querySelector('#delete_pxholder').value;
    $('#deleteProduct').modal('toggle');
    $.post(
    "../app/check_acct.php",
    {'contact_id':data,'poster':'contact','delete_message':true},
    function(data,status){
        if(status == 'success'){
                      console.log('data: '+data+', status:'+status);
          if(data == 'true'){
          Swal.fire({
     icon: 'success',
     title: 'Congratulations',
     text: 'New Client Added successfully!',
   }).then(()=>{
    location.href = '/admin/contact';
   });
  }
      
        }
    }
);
  }
</script>
<!-- Modal -->
<div class="modal fade" id="deleteProduct" tabindex="-1" role="dialog" aria-labelledby="deleteProductTitle" aria-hidden="true" data-backdrop="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content rounded-0 border-0">
      <div class="modal-body">
        <p>Are you Sure you want to Delete the Message?</p>
        <input type="hidden" id="delete_pxholder">
        <button type="submit" class="btn btn-danger mr-2" onclick="deletePxdfn()">Yes, Delete</button>
        <button class="btn btn-light" data-dismiss="modal">Cancel</button>
      </div>
    </div>
  </div>
</div>
        <!-- content-wrapper ends -->