<?php

$userId = 1;
$count = (count($data)-1);   
?>
  <div class="main-content">

   <div class="page-content">
     <div class="container-fluid">

        <div class="row">
    <div class="col-sm-8 card p-0">

      <div class="card-header mb-4">         
        <h4 class="card-title text-primary p-3"><b>Chat</b></h4>
      </div>
      <div class="card-body">  
        <div class="chat-scroll height500">   
        <?php 
        if($data) {
          foreach ($data as $chat) { ?>
            <div class="row alert_css">
            <div class="col-lg-6 col-md-6  col-sm-6<?= ($chat['user_id'] == $userId || $chat['status'] == 2) ? 'offset-lg-6 offset-md-6 offset-sm-6': ''; ?>">
              <div class="alert <?= ($chat['user_id'] == $userId || $chat['status'] == 2) ? 'alert-success': 'alert-danger'; ?>"><?= $chat['message']; ?></div>
              <small><?= ($chat['user_id'] == $userId || $chat['status'] == 2) ? 'You': Helpers::get_user_fullname($chat['user_id']); ?></small>
            </div>
</div>
            <div class="clear"></div>
        <?php } } ?>
        </div>
       <?php if($data[0]['status'] != 1){ ?>
     <form method="POST" action="<?= Helpers::adminLink('send_reply'); ?>">
      <div class="row fixeddiv">
        
          <div class="col-lg-8">
            <input type="hidden" name="token" value="<?= ($data[0]['ticket_no']) ?: ''; ?>">
            <input type="hidden" name="user_id" value="<?= ($data[0]['user_id']) ?: ''; ?>">
            <input type="hidden" name="subject" value="<?= ($data[0]['subject']) ?: ''; ?>">  
            <input type="hidden" value="<?= $path; ?>" name="path">

            <textarea class="form-control input-type-1" name="message" placeholder="Type a message" /></textarea>
          </div>
          <div class="col-lg-4">
            <input class="btn btn-primary btn-round" type="submit" value="Send Message" name="submit">
          </div>
       
        
      </div>
       </form>
       <?php } ?>
    </div>
    </div>




    <div class="col-sm-4">
      <h5 class="text-primary">Ticket Number</h5>
      <p><?= ($data[0]['ticket_no']) ?: ''; ?></p>
      <h5 class="text-primary">Start Date</h5>
      <p><?= Helpers::date($data[0]['created_at']) ?: ''; ?></p>
      <!-- <h5 class="text-primary">Status</h5>
      <p><?= ($data[$count]['status'] == 1) ? 'Resolved': 'Not Resolved'; ?></p> -->
    
    <?php if($data[$count]['status'] != 1){ ?>
        <form method="POST" action="<?= Helpers::adminLink('ticket_status'); ?>">

     <div class="row">
         <div class="col-sm-10">
            <select class="form-control ticket_dropdown" name="status" >
              <option value="0" <?= ($data[$count]['status'] == 0) ? 'selected': ''; ?>>Not resolved</option>
              <option value="1" <?= ($data[$count]['status'] == 1) ? 'selected': ''; ?>>Resolved</option>
            </select>
            <input type="hidden" value="<?= $data[$count]['id']; ?>" name="ticket_id">
            <input type="hidden" value="<?= $data[$count]['ticket_no']; ?>" name="ticket_no">
            <input type="hidden" value="<?= $path; ?>" name="path">


          </div>
         <div class="col-sm-2" style="padding: 0">
          <input type="submit" style="margin: 0" class="btn btn-primary ticket_btn" value="Go">
         </div>
      </div> 
      </form>
      <?php } ?>
    </div>
  </div>
    </div>
  </div>




