@extends('layouts.master')
@section('page-title') 
    Permits | {{ $page_title }}
@endsection
@section('page-css')

@endsection
@section('page-content')
@include('layouts.partials.permits-navbar')

  <div class="container mt-4">
      <!-- Filter Tabs -->
      <div class="row mb-4">
        <div class="col">
          <div class="">
              <!-- <a class="btn btn-primary float-end" href="permits/addapplication">Add Permit</a> -->
          </div>
        </div>
        <div class="col-auto">
          <i class="fas fa-search text-muted"></i>
        </div>
      </div>

      <!-- Permit Applications Table -->
      
        <hr>
      <div class="table-responsive">
        @include('common.notifications')
        <table class="table table-hover">
          <thead>
            <tr>
              <th>Application #</th>
              <th>Application Date</th>
              <th>Form Type</th>
              <th>Status</th>
              <th>Permit Type</th>
              <th>Date Updated</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
          	@foreach($permits_arr['data'] as $row)
            <?php 
              $submitted_at = $row['submitted_at'];
              $updated_at = $row['updated_at'];
            // Create a DateTime object from the string
            $submittedInstance = new DateTime($submitted_at);
            $updatedInstance = new DateTime($updated_at);

            // Format the date as needed
            // Example: "Y-m-d H:i:s" for standard date format
            $submittedDate = $submittedInstance->format('Y-m-d H:i:s');
            $updatedDate = $updatedInstance->format('Y-m-d H:i:s');
            ?>
            <tr class="applicationRow" id="{{ $row['application_code'] }}">
              <td>{{ $row['application_code'] }}</td>
              <td>{{ $submittedDate }}</td>
              <td>{{ ucfirst(str_replace('_', ' ', $row['permit_form_type'])) }}</td>
              <td><span class="badge text-bg-primary">{{ $row['status'] }}</span></td>
              <td>{{ $row['permit_type'] }}</td>
              <td>{{ $updatedDate }}</td>
              
              <td><i class="fa-solid fa-eye"></i></td>              
            </tr>
            @endforeach
          </tbody>
        </table>
      </div>

      <!-- Pagination -->
      <!-- <nav aria-label="Page navigation">
        <ul class="pagination justify-content-start">
          <li class="page-item">
            <a class="page-link text-muted" href="#">First</a>
          </li>
          <li class="page-item active"><a class="page-link" href="#">1</a></li>
          <li class="page-item">
            <a class="page-link text-muted" href="#">2</a>
          </li>
          <li class="page-item">
            <a class="page-link text-muted" href="#">3</a>
          </li>
          <li class="page-item">
            <a class="page-link text-muted" href="#">Last</a>
          </li>
        </ul>
      </nav> -->
    </div>

@endsection
@section('page-js')
	<!-- <script src="{{ url('public/assets/libs/select2/dist/js/select2.full.min.js') }}" type="text/javascript" ></script> -->


	<!-- <script src="{{ url('public/assets/js/permit_tools.js') }}" type="text/javascript" ></script> -->

<script type="text/javascript">
  $(document).ready(function(){
    $('.applicationRow').click(function(){
        // onclick="viewApplication({{ $row['application_code'] }})
      var  applicationId = $(this).attr('id');
      window.location.href = "/permits/viewapplication/" + applicationId;

    });

  });
  
</script>

@endsection