<%- include('../partials/head.ejs') %>
  <!--
`body` tag options:

  Apply one or more of the following classes to to the body tag
  to get the desired effect

  * sidebar-collapse
  * sidebar-mini
-->

  <body class="hold-transition sidebar-mini">
    <div class="wrapper">
      <!-- Navbar -->
      <%- include('../partials/navigation.ejs') %>
        <!-- /.navbar -->

        <!-- Main Sidebar Container -->

        <%- include('../partials/sidebar.ejs') %>

          <!-- Content Wrapper. Contains page content -->
          <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <div class="content-header">
              <div class="container-fluid">
                <div class="row mb-2">
                  <div class="col-sm-6">
                    <h1 class="m-0">Manage Withdrawals</h1>
                  </div><!-- /.col -->
                  <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                      <li class="breadcrumb-item"><a href="/admin">Home</a></li>
                      <li class="breadcrumb-item active">Manage Withdrawals</li>
                    </ol>
                  </div><!-- /.col -->
                </div><!-- /.row -->
              </div><!-- /.container-fluid -->
            </div>
            <!-- /.content-header -->

            <!-- Main content -->
            <div class="content">
              <div class="container-fluid">
                <div class="row">

                  <!-- /.col-md-6 -->
                  <div class="col-lg-12">
                    <div class="pt-20">
                      <% if(errors.length> 0){ %>
                        <div class="alert alert-danger">
                          <% errors.forEach(function(error){ %>
                            <% if(error !='' ){ %>
                                <%= error %>
                              <% }}); %>
                        </div>
                        <% } %>
                          <% if(success.length> 0){ %>
                            <div class="alert alert-success">
                                <%=success %>
                            </div>
                            <% } %>
                    </div>
                    <div class="card">
                      <div class="card-header">
                        <h3 class="card-title">All Withdrawals</h3>
                      </div>
                      <div class="card-body">

                        <br>
                        <div id="ajax_table">
                        <table id="withdraw_datatable" class="table table-bordered table-hover float-left">
                          <thead>
                            <tr>
                              <!-- <th></th> -->
                              <th>Index</th>
                              <th>Name</th>
                              <th>Withdraw Address</th>
                              <th>Withdraw Amount</th>
                              <th>Current Balance</th>
                              <th>Status</th>
                              <th>Updated At</th>
                              <th>Actions</th>
                            </tr>
                          </thead>
                          <tbody id="tablebody">
                            <% data.forEach((itm, index)=> { %>
                              <tr key="<%= index %>">
                                <!-- <td>
                                  <input type="checkbox" id="readyForDeliveryCheck" class="readyForDeliveryCheck" name="readyForDeliveryCheck" value="<%= itm.id %>">
                                </td> -->
                                <td>
                                    <%= index + 1 %>
                                </td>
                                <td>
                                  <%= itm.User.name %>
                                </td>
                                <td>
                                  <%= itm.withdraw_address %>
                                </td>
                                <td>
                                  <%= itm.withdraw_amount %>
                                </td>
                                <td>
                                  <%= itm.before_withdraw_balance %>
                                </td>
                                <td class="text-center">
                                  <% if(itm.status == 0){ %> 
                                    <b class="text-warning">Pending</b> 
                                  <% } %>
                                  <% if(itm.status == 1){ %> 
                                      <b class="text-success">Transferred</b>
                                  <% } %>
                                  <% if(itm.status == 2){ %> 
                                      <b class="text-danger">Cancelled</b>
                                  <% } %>
                                </td>
                                <td>
                                    <%= moment(itm.updatedAt).format('MMM/Do/YY h:mm') %>
                                </td>
                                <% if(itm.status == 0){ %> 
                                  <td class="project-actions">
                                    <button class="btn btn-success btn-sm acceptWithdraw" data-id="<%= itm.id %>" title="Accept" href="#"
                                      data-toggle="modal" data-target="#modal-accept">
                                      <i class="fas fa-check">
                                      </i>
                                    </button>
                                    <button class="btn btn-danger btn-sm cancelWithdraw" data-id="<%= itm.id %>" title="Cancel" href="#"
                                      data-toggle="modal" data-target="#modal-cancel">
                                      <i class="fas fa-times">
                                      </i>
                                    </button>
                                  </td>
                                <% }else{ %>
                                  <td class="project-actions">
                                  </td>
                                <% } %>
                              </tr>
                              <% }) %>
                          </tbody>
                          <!-- <tfoot>
                            <tr>
                              <th>Index</th>
                              <th>Category</th>
                              <th>Name</th>
                              <th>Description</th>
                              <th>Updated At</th>
                              <th>Actions</th>
                            </tr>
                          </tfoot> -->
                        </table>
                        </div>
                      </div>
                    </div>

                  </div>
                  <!-- /.col-md-6 -->
                </div>
                <!-- /.row -->
              </div>
              <!-- /.container-fluid -->
            </div>
            <!-- /.content -->
          </div>
          <!-- /.content-wrapper -->

          <!-- Control Sidebar -->
          <aside class="control-sidebar control-sidebar-dark">
            <!-- Control sidebar content goes here -->
          </aside>
          <!-- /.control-sidebar -->

          <!-- Main Footer -->
          <!-- modal -->
          <div class="modal fade" id="modal-accept">
            <div class="modal-dialog modal-dialog-centered">
              <div class="modal-content bg-success">
                <div class="modal-header">
                  <h4 class="modal-title">Accept Withdraw</h4>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <form class="acceptWithdrawForm" action="" method="POST" data-url="/admin/withdrawals/accept/">
                  <div class="modal-body">
                    <h4 class="">You want to accept this withdraw.</h4>
                    <p>Transaction Details :</p>
                    <textarea row="4" name="transactionDetail" class="form-control" placeholder="Add Transaction Details"></textarea>
                  </div>
                  <div class="modal-footer justify-content-between">
                    <!-- <button type="button" class="btn btn-outline-light" data-dismiss="modal"></button> -->
                      <button type="submit" class="btn btn-outline-light">Accept</button>
                  </div>
                </form>
              </div>
              <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
          </div>
          <div class="modal fade" id="modal-cancel">
            <div class="modal-dialog modal-dialog-centered">
              <div class="modal-content bg-danger">
                <div class="modal-header">
                  <h4 class="modal-title">Cancel Withdraw</h4>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <form class="cancelWithdrawForm" action="" method="POST" data-url="/admin/withdrawals/cancel/">
                  <div class="modal-body">
                    <h4>You really want to cancel this withdraw.</h4>
                    <p>Transaction Details :</p>
                    <textarea row="4" name="transactionDetail" class="form-control" required placeholder="Add Transaction Details"></textarea>
                  </div>
                  <div class="modal-footer justify-content-between">
                    <!-- <button type="button" class="btn btn-outline-light" data-dismiss="modal"></button> -->
                      <button type="submit" class="btn btn-outline-light ">Cancelled</button>
                  </div>
                </form>
              </div>
              <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
          </div>
          <!-- /.modal -->
    </div>
    <!-- ./wrapper -->

    <!-- REQUIRED SCRIPTS -->

    <!-- jQuery -->

    <%- include('../partials/scripts.ejs') %>

  </body>