<div class="content-wrapper">
  <section class="content-header">
    <h1>
      <?= $page_title ?>
      <small><?= $page_desc ?></small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
      <li><?= $menu ?></li>
      <li class="active"><?= $sub_menu ?></li>
    </ol>
  </section>
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <?php if($this->session->flashdata('message')) { 
          $flashdata = $this->session->flashdata('message'); ?>
          <div class="alert alert-<?= $flashdata['class'] ?>">
           <button class="close" data-dismiss="alert" type="button">×</button>
           <?= $flashdata['message'] ?>
         </div>
        <?php } ?>
      </div>
      <div class="col-md-12">
        <div class="box box-warning">
          <div class="box-header with-border">
            <div class="col-md-6">
              <h3 class="box-title">Scheduled Rides</h3>
            </div>
          </div>
          <div class="box-body">
            <form action="<?= base_url('Ride/scheduled_rides') ?>" method="post" class="validate" data-parsley-validate="" enctype="multipart/form-data">
              <div class="col-md-12">
                <div class="form-group has-feedback">
                  <label>Appointment Date</label>
                  <div class="input-group date" data-provide="datepicker">
                    <input id="datepicker" type="text" class="form-control required" data-parsley-trigger="change" data-parsley-minlength="2" required="" name="search_date" placeholder="Search Date" autocomplete="off">
                    <div class="input-group-addon">
                      <i class="fa fa-calendar"></i>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-12">
                <div class="col-md-2" style="float:right;padding:initial;">
                  <a class="btn btn-sm btn-primary" style="width: 150px;" href="<?= base_url('Ride/scheduled_rides') ?>">View All</a>
                </div>
                <div class="col-md-2" style="float:right;padding:initial;">
                  <button class="btn btn-sm btn-primary" style="width: 150px;" type="submit">Search</button>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>

      <div class="col-md-12">
        <div class="box box-warning">
          <div class="box-body">
            <table class="table table-bordered table-striped datatable ">
              <thead>
                <tr>
                  <th class="hidden">ID</th>
                  <th width="100px">Scheduled Time</th>
                  <th width="70px">Arrival Time</th>
                  <th width="100px">Coustomer Name</th>
                  <th width="30px">Mobility</th>
                  <th width="90px">Pick Up Address</th>
                  <th width="90px">Drop Address</th>
                  <th width="155px">Rider Status</th>
                  <th width="30px">View</th>
                </tr>
              </thead> 
            <tbody>
              <?php
                $report_data = array();
                if(!empty($ride_data)){
                  foreach($ride_data as $ride) {
                    $json_ride = json_decode($ride->data,true);
                    if(empty($json_ride)){
                      continue; 
                    } ?>
                    <tr>
                      <th class="hidden"><?= $ride->transport_id ?></th>
                      <th class="center">
                        <?= date("d-m-y G:i",$ride->appointment_time - 60 * 60) ?>
                      </th>
                      <th class="center"><?= date("d-m-y G:i",$ride->appointment_time) ?></th>
                      <th class="center"><?= $ride->patient_name ?></th>
                      <th class="center">Med</th>
                      <th class="center"><?= $ride->pickup_location ?></th>
                      <th class="center"><?= $ride->drop_location ?></th>
                      <th class="center">
                        <?php
                          if(!empty($ride->assigned_driver) && $ride->driver_assign_status == '1'){
                            echo 'Driver Cancelled,<br> Auto Assigned to Dispatcher';
                          } else if (empty($ride->assigned_driver) && $ride->driver_assign_status == '1'){
                            // echo 'No Driver Found,<br> Ride assigned to Dispatcher';
                            echo 'Ride assigned to Dispatcher';
                          } else if (empty($ride->assigned_driver) && $ride->driver_assign_status == '2'){
                            // echo 'No Driver Found,<br> Ride assigned to No Driver';
                            echo 'Ride assigned to No Driver';
                          } else if (!empty($ride->assigned_driver) && $ride->driver_assign_status == '0' && !empty($ride->assigned_driver_name) && $ride->status == 3){
                            echo 'Waiting for driver Approval<br>
                                  Driver Name - '.$ride->assigned_driver_name;
                          } else if (!empty($ride->assigned_driver) && $ride->driver_assign_status == '0' && !empty($ride->assigned_driver_name) && $ride->status == 4){
                            echo 'Driver Accepted<br> Driver Name - '.$ride->assigned_driver_name;
                          }
                        ?>
                      </th>
                      <th class="center">
                        <a id="viewRideDetails" key="<?= $ride->transport_id ?>" class="cpoint">
                          <i class="fa fa-fw fa-eye"></i>
                        </a>
                      </th>
                    </tr>
                    <?php
                    $report_data[$ride->transport_id] = $json_ride; 
                  }
                }
              ?>
            </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </section>
</div>
<script type="text/javascript">
   report_data = <?= json_encode($report_data); ?>;
</script>