<%- 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">CMS</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">CMS</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">CMS</h3>
                        <a href="/admin/cms" class="float-right btn btn-success">Add New</a>
                      </div>
                      <div class="card-body">
                        <table id="cms_datatable" class="table table-bordered table-hover">
                          <thead>
                            <tr>
                              <th>Index</th>
                              <th>Name</th>
                              <th>Title</th>
                              <th>Updated At</th>
                              <th>Actions</th>
                            </tr>
                          </thead>
                          <tbody>
                            <% data.forEach((cms,index)=> { %>
                              <tr key="<%= index %>">
                                <td>
                                    <%= index + 1 %>
                                </td>
                                <td>
                                    <%= cms.name %>
                                </td>
                                <td class="col-3">
                                  <%= cms.title %>
                                </td>
                                <td>
                                    <%= moment(cms.updatedAt).format('MMM/Do/YY h:mm') %>
                                </td>
                                <td class="project-actions">
                                  <a class="btn btn-primary btn-sm" href="/admin/cms/view/<%=cms.slug %>">
                                    <i class="fas fa-eye">
                                    </i>
                                  </a>
                                  <a class="btn btn-info btn-sm" href="/admin/cms/<%=cms.id %>">
                                    <i class="fas fa-pencil-alt">
                                    </i>
                                  </a>
                                  <button class="btn btn-danger btn-sm deleteCMS" data-id="<%= cms.id %>" href="#"
                                    data-toggle="modal" data-target="#modal-danger">
                                    <i class="fas fa-trash">
                                    </i>
                                  </button>
                                </td>
                              </tr>
                              <% }) %>

                          </tbody>
                          <tfoot>
                            <tr>
                              <th>Index</th>
                              <th>Name</th>
                              <th>Title</th>
                              <th>Updated At</th>
                              <th>Actions</th>
                            </tr>
                          </tfoot>
                        </table>
                      </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-danger">
            <div class="modal-dialog">
              <div class="modal-content bg-danger">
                <div class="modal-header">
                  <h4 class="modal-title">Delete CMS</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>This CMS 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="deleteCMSForm" action="" method="POST" data-url="/admin/cms/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>