<!--start main wrapper-->
  <main class="main-wrapper">
    <div class="main-content">
      <button class="btn guestBtn d-flex gap-2 align-items-center" id="backBtn"><img src="<?php echo base_url(); ?>assets/images/arowleft.svg"
          alt="" width="15px"> Back</button>
<?php
//  echo "<pre>";
// print_r($userinfo);
// echo "</pre>";



?>
<input type="hidden" id="chatusername" value="<?php echo $userinfo['fullName'];?>">

      <div class="row">
        <div class="col-md-8 my-2">
          <div class="d-flex align-items-center gap-2 mb-2">

            <h3 class="fmon m-0 fw-bolder">Case No. <?php echo $id; ?></h3>
          </div>
        </div>
        <div class="col-md-4 my-2 d-flex justify-content-end">
          <?php if($issue['isOpen']==true){ ?>
          <a href="<?php echo base_url('site/closecase/'.$id); ?>" class="btn btnClose d-flex gap-5 align-items-center" 
          id="backBtn">Close Case <img
              src="<?php echo base_url(); ?>assets/images/close.png" alt=""></a>
          <?php } ?>
        </div>

      </div>
      <div class="row">
        <div class="col-md-5 my-2">
          <div class="card border-15">
            <div class="card-body">
              <div class="row">
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">House</p>
                </div>
                <div class="col-md-6 my-2">
                  <div class="d-flex gap-2 align-items-center">
                    <div class="numBox wfit"><?php echo $unitinfo['unit']; ?></div>
                    <p class="fc2 mb-0">Zone:<?php echo $unitinfo['zone']; ?></p>
                  </div>
                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">Created at</p>
                </div>
                <div class="col-md-6 my-2">
                  <p class="fc2"><?php echo date('d/m/Y H:i',$issue['createdAt']/1000); ?>
                  </p>
                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">Created by</p>
                </div>
                <div class="col-md-6 my-2">
                  <p class="fc2">
                  <?php if($issue['createdBy']=="admin"){ ?>
                  Admin
                  <?php }else{ ?>
                  <?php echo $userinfo['fullName']; ?>
                  <?php } ?>

                  </p>
                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">Status</p>
                </div>
                <div class="col-md-6 my-2">
                  <div class="hNum">
                    <?php if($issue['isOpen']==true){ ?>
                    Active
                    <?php }else{ ?>
                   Closed
                    <?php } ?>
                  </div>

                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">Category
                  </p>
                </div>
                <div class="col-md-6 my-2">
                  <select class="form-select fcSelect" name="" id="">
                    <option class="fc2" value="Cuentas por cobrar" selected>
                      <?php echo $issue['category']; ?>
                    </option>
                  </select>

                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">User Type</p>
                </div>
                <div class="col-md-6 my-2">
                  <p class="fc2"><?php echo $userinfo['userType'];?>
                  </p>
                </div>
                <div class="col-md-6 my-0">
                  <p class="fc1 mb-0">Last Update</p>
                </div>
                <div class="col-md-6 my-2">
                  <p class="fc2">
                  <?php echo date('d/m/Y H:i A',$issue['updatedAt']/1000); ?>
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-md-7 my-2">
          <div class="card border-15">
            <div class="card-body">
              <p class="ft1 text-black"><?php echo $issue['subject']; ?></p>
              <p class="fc1 mb-0">Entry: <span class="fc2">
              <?php echo date('d F Y H:i A',$issue['createdAt']/1000); ?>
              </span></p>
              <hr>
              <div class="my-2">
                <p class="fc1 mb-0"><span class="fc2">From:</span>
                <?php if($issue['createdBy']=="admin"){ ?>
                Admin
                <?php }else{ ?>
                <?php echo $userinfo['fullName']; ?>
                <?php } ?>
                </p>
                <p class="fc2"> To: <span class="fc1">
                <?php if($issue['createdBy']=="admin"){ ?>
            <?php echo $userinfo['fullName']; ?>
                <?php }else{ ?>
                  Admin
                <?php } ?>
                </span></p>
                <div class="my-2">
                  <p class="fc2"><?php echo $issue['note']; ?></p>
                  <p class="fc1 mb-0">regards,</p>
                </div>
              </div>
              <div>
                <input class="d-none" type="file" name="" id="file">
                <label class="d-flex gap-2 align-items-center" for="file">
                    <img src="<?php echo base_url(); ?>assets/images/atachP2.png" alt="">
                    <p class="fc2 mb-0">documents</p>
                </label>
                
                <!-- Document Icons -->
                <div class="mt-3 d-flex gap-3">
                    <?php if(!empty($issue['imageUrl'])): ?>
                    <a href="<?php echo $issue['imageUrl']; ?>" target="_blank" class="text-decoration-none">
                        <div class="d-flex align-items-center gap-2">
                            <img src="<?php echo base_url(); ?>assets/images/atachP2.png" alt="Image" width="">
                            <span class="text-primary">View Image</span>
                        </div>
                    </a>
                    <?php endif; ?>
                    
                    <?php if(!empty($issue['pdfUrl'])): ?>
                    <a href="<?php echo $issue['pdfUrl']; ?>" target="_blank" class="text-decoration-none">
                        <div class="d-flex align-items-center gap-2">
                            <img src="<?php echo base_url(); ?>assets/images/atachP2.png" alt="PDF" width="">
                            <span class="text-primary">View PDF</span>
                        </div>
                    </a>
                    <?php endif; ?>
                </div>
              </div>
            </div>

          </div>
          

      <h3 class="fmon m-0 fw-bolder">Replies</h3>
         <div class="card border-15">
            <div id="replies-container">
              <!-- Messages will be loaded here dynamically -->
            </div>
          </div>
          <div class="mt-3">
            <form id="replyForm" enctype="multipart/form-data">
              <label for="replyText" class="fc2">Reply</label>
              <textarea class="form-control" name="replyText" id="replyText" placeholder="Enter your message" rows="5" ></textarea>
              
              <input class="d-none" type="file" name="replyFile" id="replyFile" accept="image/*,.pdf">
              <label class="d-flex align-items-center gap-2 mt-2 labl" for="replyFile">
                <img src="<?php echo base_url(); ?>assets/images/pdf.png" alt="">
                <div class="d-flex gap-1 align-items-center">
                  <img src="<?php echo base_url(); ?>assets/images/atachP2.png" alt="">
                  <p class="fc1 mb-0">Add documents</p>
                  <span id="selectedFileName"></span>
                </div>
              </label>

              <div class="my-3 d-flex justify-content-end">
                <button type="submit" class="btn guestBtn px-5 py-2">Send</button>
              </div>
            </form>
          </div>

        </div>


      </div>
    </div>
    </div>

  </main>
