<% 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': [6]},
//              //{"aTargets": [3], "sClass": "text-justify"},
//              {"sClass": "center", "aTargets": [1, 2]},
              {"width": "8%", "targets": [0]},
              {"width": "25%", "targets": [6]},
//              {"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>
    <%= hotel.name %>
    <!--<small>advanced tables</small>--> 
    <!-- <% if(hotel.status) { %>
      <a href="<%= '/hotels/status/'+hotel._id+'/false' %>" class="btn btn-sm btn-success inactive_confirmation" title="Active">Active</a>
    <% } else { %>
      <a href="<%= '/hotels/status/'+hotel._id+'/true' %>" class="btn btn-sm btn-danger active_confirmation" title="In Active">In Active</a>
    <% } %> -->
  </h1>
  <ol class="breadcrumb">
    <li><a href="/dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
    <li><a href="/hotels"> Hotel</a></li>
    <li class="active"><%= hotel.subspace ? "Sub-space" : "Spaces" %></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"><%= hotel.subspace ? "list of Sub-Spaces" : "List of Spaces"  %></h3>
          <div class="pull-right">
            <a href="/hotels/rooms/add/<%= hotel._id %>" class="btn btn-primary"><%= hotel.subspace ? "Add New Sub-space" : "Add New Space"  %></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>No of Units</th>
                <th>Max No of Adults</th>
                <th>Max No of Children</th>
                <th>Price</th>
                <th>Space Type</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
              <% 
              if(rooms){
              for(var i=0; len=rooms.length, i < len; i++) {%>
              <tr>
                <td>
                  <%= (i+1) %>
                </td>
                <td>
                  <%= rooms[i].no_of_rooms %>
                </td>
                <td>
                  <%= rooms[i].no_of_adult %>
                </td>
                <td>
                  <%= rooms[i].no_of_child %>
                </td>
                <td>
                  <%= rooms[i].price %>
                </td>
                <td>
                  <%= rooms[i].room_type ? rooms[i].room_type.slug ? rooms[i].room_type.slug : rooms[i].room_type.name : '' %>
                </td>
                <td class="text-center">
                  <%
                  if(hotel.subspace) {
                    %>
                  <a href="<%= '/hotels/rooms/subspace/'+rooms[i]._id %>" class="btn btn-sm btn-primary" title="subspace"><span
                    class="glyphicon glyphicon-bed"></span></a>
                    <%
                  } 
                    %>
                  
                  <a href="<%= '/hotels/rooms/image/'+rooms[i]._id+'/'+hotel._id %>" class="btn btn-sm btn-primary"
                    title="Add Image"><span class="glyphicon glyphicon-camera"></span></a>
                  <a href="<%= '/hotels/rooms/edit/'+rooms[i]._id %>" class="btn btn-sm btn-primary" title="Edit"><span
                      class="glyphicon glyphicon-edit"></span></a>
                  <a href="<%= '/hotels/rooms/message/edit/'+hotel._id+'/'+rooms[i]._id %>"
                    class="btn btn-sm btn-primary" title="Add/Update Important Message"><span
                      class="glyphicon glyphicon-envelope"></span></a>
                  <a href="<%= '/hotels/rooms/delete/'+rooms[i]._id %>"
                    class="btn btn-sm btn-danger delete_confirmation" title="Delete"><span
                      class="glyphicon glyphicon-trash"></span></a>
                  <%
                  if(rooms[i].status) {
                    %>
                    <a href="<%= '/hotels/rooms/status/'+rooms[i].hotel+'/'+rooms[i]._id+'/false' %>" class="btn btn-sm btn-success inactive_confirmation" title="Active">Active</a>
                  <!-- <a href="<%= '/hotels/rooms/status/'+rooms[i].hotel+'/'+rooms[i]._id+'/false' %>" class="btn btn-sm btn-danger inactive_confirmation" title="In Active">In Active</a> -->
                    <%
                  } else {
                    %>
                    <a href="<%= '/hotels/rooms/status/'+rooms[i].hotel+'/'+rooms[i]._id+'/true' %>" class="btn btn-sm btn-danger active_confirmation" title="Inactive">Inactive</a>
                  <!-- <a href="<%= '/hotels/rooms/status/'+rooms[i].hotel+'/'+rooms[i]._id+'/true' %>" class="btn btn-sm btn-success active_confirmation" title="Active">Active</a> -->
                    <%
                  }
                  %>
                </td>
              </tr>
              <% 
              }
              }
              %>
            </tbody>
            <tfoot>
              <tr>
                <th>Sl. No.</th>
                <th>No of Rooms</th>
                <th>No of Adults</th>
                <th>No of Children</th>
                <th>Price</th>
                <th>Room Type</th>
                <th>Action</th>
              </tr>
            </tfoot>
          </table>
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
    <!-- /.col -->
  </div>
  <!-- /.row -->
</section>
<!-- /.content -->