<% layout('../layouts/main') -%>

<!-- DataTables -->
<% stylesheet('/css/dataTables.bootstrap.min.css') %>

<!-- DataTables -->
<% script('/js/jquery.dataTables.min.js') %> <%
script('/js/dataTables.bootstrap.min.js') %> <% block('custom_scripts', `
<script>
  $(document).ready(function() {
    $("#example1").DataTable({
      aoColumnDefs: [
        { bSortable: false, aTargets: [4] },
        //              //{"aTargets": [3], "sClass": "text-justify"},
        //              {"sClass": "center", "aTargets": [1, 2]},
        { width: "09%", targets: [0] },
        { width: "09%", targets: [1] },
        { width: "09%", targets: [2] },
        { width: "07%", targets: [3] },
        { width: "30%", targets: [4] }
        //              {"width": "8%", "targets": [8]},
        //                  //{"width": "9%", "targets": [7]},
      ],
      paging: true,
      lengthChange: true,
      searching: true,
      ordering: true,
      info: true,
      autoWidth: false,
      stateSave: true
    });
  });

  $(document).ready(function() {
    $(document).on("click", ".delete_confirmation", function(e) {
      e.preventDefault();
      if (confirm("Do you want delete this item")) {
        //alert($(this).attr('href'));
        window.location.href = $(this).attr("href");
      }
    });

    $(document).on('click', ".active_confirmation", function (e) {
        e.preventDefault();
        if (confirm("Do you want to active this item")) {
            //alert($(this).attr('href'));
            window.location.href = $(this).attr('href');
        }
    });

    $(document).on('click', ".inactive_confirmation", function (e) {
        e.preventDefault();
        if (confirm("Do you want to inactive this item")) {
            //alert($(this).attr('href'));
            window.location.href = $(this).attr('href');
        }
    });
  });
</script>
`) %>

<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    Rent A Car
    <!--<small>advanced tables</small>-->
  </h1>
  <ol class="breadcrumb">
    <li>
      <a href="/dashboard"><i class="fa fa-dashboard"></i> Home</a>
    </li>
    <li class="active">Rent A Car</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">
  <% if (Object.prototype.hasOwnProperty.call(flash, 'success')) { %>
  <div class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <%= flash.success %>
  </div>
  <% } %> <% if (Object.prototype.hasOwnProperty.call(flash, 'error')) { %>
  <div class="alert alert-danger alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
    <%= flash.error %>
  </div>
  <% } %>
  <div class="row">
    <div class="col-xs-12">
      <div class="box">
        <div class="box-header">
          <h3 class="box-title">List of Vehicles</h3>
          <div class="pull-right">
            <a href="/vehicles/add" class="btn btn-primary">Add New Vehicle</a>
          </div>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
          <table id="example1" class="table table-bordered table-hover">
            <thead>
              <tr>
                <th>Sl. No.</th>
                <th>Name</th>
                <th>Registration</th>
                <th>Use For </th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
              <% if(vehicles){ var len=vehicles.length; for(var i=0; i < len;
              i++) { %>
              <tr>
                <td>
                  <%= (i + 1) %>
                </td>
                <td>
                  <%= vehicles[i].name %>
                </td>
                <td>
                  <%= vehicles[i].registration %>
                </td>
                <td>
                  <%- vehicles[i].useFor %>
                </td>
                <td class="text-center">
                  <a
                    href="<%= '/vehicles/addImages/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Images"
                    ><span class="glyphicon glyphicon-camera"></span
                  ></a>
                  <a
                    href="<%= '/vehicles/translate/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Descriptions"
                    ><span class="glyphicon glyphicon-list-alt"></span
                  ></a>
                  <a
                    href="<%= '/vehicles/edit/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Edit"
                    ><span class="glyphicon glyphicon-edit"></span
                  ></a>
                  <!-- <a href="<%= '/vehicles/message/add/'+vehicles[i]._id %>" class="btn btn-sm btn-primary" title="Add Important Message"><span
                      class="glyphicon glyphicon-envelope"></span></a> -->
                  <a
                    href="<%= '/vehicles/message/edit/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Add/Update Important Message"
                    ><span class="glyphicon glyphicon-envelope"></span
                  ></a>
                  <% if(!noShowDeal) { %> <%
                  if(deals.includes(vehicles[i]._id.toString())) { %>
                  <a
                    href="<%= '/vehicles/deal/'+type+'/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-warning"
                    title="Remove from Deal"
                    ><span class="glyphicon glyphicon-star"></span
                  ></a>
                  <% } else { %>
                  <a
                    href="<%= '/vehicles/deal/'+type+'/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-info"
                    title="Add as Deal"
                    ><span class="glyphicon glyphicon-star-empty"></span
                  ></a>
                  <% } %> <% if(type == 'rent-a-car') { %>
                  <a
                    href="<%= '/vehicles/rent-a-car/comment/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Comment"
                    ><span class="glyphicon glyphicon-comment"></span
                  ></a>
                  <% } else if(type == 'transfer') { %>
                  <a
                    href="<%= '/vehicles/transfer/comment/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Comment"
                    ><span class="glyphicon glyphicon-comment"></span
                  ></a>
                  <% } else { %>
                  <a
                    href="<%= '/vehicles/comment/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-primary"
                    title="Comment"
                    ><span class="glyphicon glyphicon-comment"></span
                  ></a>
                  <% } %> <% } %>
                  <a
                    href="<%= '/vehicles/delete/'+vehicles[i]._id %>"
                    class="btn btn-sm btn-danger delete_confirmation"
                    title="Delete"
                    ><span class="glyphicon glyphicon-trash"></span
                  ></a>

                  <%
                  if(vehicles[i].status) {
                    %>
                    <a href="<%= '/vehicles/rent-a-car/status/'+vehicles[i]._id+'/false/'+type %>" class="btn btn-sm btn-success inactive_confirmation" title="Active">Active</a>
                  
                    <%
                  } else {
                    %>
                    <a href="<%= '/vehicles/rent-a-car/status/'+vehicles[i]._id+'/true/'+type %>" class="btn btn-sm btn-danger active_confirmation" title="In Active">Inactive</a>
                  
                    <%
                  }
                  %>
                </td>
              </tr>
              <% } } %>
            </tbody>
            <tfoot>
              <tr>
                <th>Sl. No.</th>
                <th>Name</th>
                <th>Partner</th>
                <th>Price Update</th>
                <th>Action</th>
              </tr>
            </tfoot>
          </table>
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
    <!-- /.col -->
  </div>
  <!-- /.row -->
</section>
<!-- /.content -->
