<%- 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">Notifications</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">Notifications</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 Notifications</h3>
                      </div>
                      <div class="card-body">
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group col-10 float-left">
                                    <label class="float-left col-12 col-sm-3 col-md-3 pt-2">Type :</label>
                                    <select class="form-control float-left col-sm-9 col-md-9" name="type_id"
                                        id="type_notificaiton">
                                        <option value=""  disabled  selected="">Select Type</option>
                                        <option value="all" >All Types</option>
                                        <option value="new_customer" >Customer</option>
                                        <option value="new_order" >Order</option>
                                        <option value="product_update" >Product</option>
                                    </select>
                                </div>
                                <div class="col-md-2 float-right">
                                    <button class="btn btn-success radius" id="filterType">Filter</button>
                                </div>
                            </div>
                            <div class="col-6">
                                <div class="form-group col-10 float-left " >
                                    <label class="float-left col-12 col-sm-3 col-md-3 pt-2">Date:</label>
                                    <input type="text" placeholder="Select Date" class="form-control datetimepicker-input col-sm-9 col-md-9"  id="datepicker">
                                </div>
                                <div class="col-md-2 float-right">
                                    <button class="btn btn-danger radius" id="deleteNotification" data-toggle="modal" data-target="#modal-danger">Delete</button>
                                </div>
                            </div>
                        </div>
                        <br>
                        <div id="ajax_table">
                            <table id="notification_datatable" class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>Index</th>
                                        <th>Type</th>
                                        <th>Message</th>
                                        <th>Date</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <% data.forEach((itm, i)=> { %>
                                    <tr class="<%= itm.is_read == 0 ? 'bg-secondary' : ''%>" key="<%= i %>">
                                        <td>
                                            <%= i + 1 %>  
                                        </td>
                                        <td style="text-transform: capitalize">
                                            <%= itm.item.type %>
                                        </td>
                                        <td>
                                            <%= itm.item.message %>
                                        </td>
                                        <td>
                                            <%= itm.diff %>
                                        </td>
                                        <td class="project-actions">
                                            <button class="btn btn-danger btn-sm viewNotification" data-id="<%= itm.item.id %>" data-type="<%= itm.item.type %>" title="View" href="#"
                                                data-toggle="modal" data-target="#modal-view-notification">
                                                <i class="fas fa-eye">
                                                </i>
                                            </button>
                                        </td>
                                    </tr>
                                    <% }) %>

                                </tbody>
                                <tfoot>
                                    <tr>
                                        <th>Index</th>
                                        <th>Type</th>
                                        <th>Message</th>
                                        <th>Date</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 -->
          </div>
          <!-- modal -->
          <div class="modal fade" id="modal-view-notification">
            <div class="modal-dialog modal-dialog-centered modal-xl">
              <div class="modal-content ">
                <div class="modal-header">
                  <h4 class="modal-title">View Notification</h4>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                  
                </div>
                <div class="modal-body">
                  <div id="notification-data"></div>
                </div>
                <div class="modal-footer justify-content-between">
                    <div></div>
                  <button  class="btn btn-outline-warning" data-dismiss="modal">Close</button>
                </div>
              </div>
              <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
          </div>
        <!-- modal -->
        <!-- delete modal -->
        <div class="modal fade" id="modal-danger">
            <div class="modal-dialog">
              <div class="modal-content bg-danger">
                <div class="modal-header">
                  <h4 class="modal-title">Clear Notification</h4>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <p>These Notification will be deleted permanently.</p>
                </div>
                <div class="modal-footer justify-content-between">
                  <button type="button" class="btn btn-outline-light" data-dismiss="modal">Cancel</button>
                  <form class="deleteNotificationForm" action="" method="POST" data-url="/admin/notification/delete/">
                    <button type="submit" class="btn btn-outline-light">Delete</button>
                  </form>
                </div>
              </div>
              <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
          </div>
        <!-- modal -->
    </div>
    <!-- ./wrapper -->

    <!-- REQUIRED SCRIPTS -->

    <!-- jQuery -->

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

  </body>