<!---------   
=== Theme Author : Evan Ahmed EMon
=== Theme Designed By: TWG
=== Contact Whatsapp: +8801864614704
 ----------->  
 
 <?php include 'header.php'; ?>
<style>
/* Glassy Badges */
.badge-glass-success { background-color: rgba(18, 184, 132, 0.15); color: #109f72; border: 1px solid rgba(18, 184, 132, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}
.badge-glass-info { background-color: rgba(86, 204, 242, 0.15); color: #007bb5; border: 1px solid rgba(86, 204, 242, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}
.badge-glass-warning { background-color: rgba(242, 201, 76, 0.15); color: #b28900; border: 1px solid rgba(242, 201, 76, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}
.badge-glass-danger { background-color: rgba(235, 87, 87, 0.15); color: #c9302c; border: 1px solid rgba(235, 87, 87, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}
.badge-glass-primary { background-color: rgba(47, 128, 237, 0.15); color: #0056b3; border: 1px solid rgba(47, 128, 237, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}
.badge-glass-secondary { background-color: rgba(108, 117, 125, 0.15); color: #495057; border: 1px solid rgba(108, 117, 125, 0.3); padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500;}

/* Table Card */
.custom-table-card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    border: none;
    margin-top: 15px;
}
.custom-table-card .table { margin-bottom: 0; }
.custom-table-card .table thead th {
    border-bottom: 2px solid #f0f0f0;
    color: #444;
    font-weight: 600;
    background: #fdfdfd;
}
.custom-table-card .table tbody tr { transition: background-color 0.2s; }
.custom-table-card .table tbody tr:hover { background-color: #f8f9fa; }

/* Modern Nav Tabs */
.nav-tabs.modern-tabs {
    border-bottom: none;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
}
.nav-tabs.modern-tabs > li { float: none; margin-bottom: 0; }
.nav-tabs.modern-tabs > li > button,
.nav-tabs.modern-tabs > li > a {
    border: none !important;
    background: #fff;
    border-radius: 30px !important;
    padding: 8px 16px;
    color: #555;
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
    transition: all 0.3s ease;
}
.nav-tabs.modern-tabs > li > button:hover,
.nav-tabs.modern-tabs > li > a:hover {
    background: linear-gradient(135deg, #2F80ED, #56CCF2);
    color: #fff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(47, 128, 237, 0.3);
}

.btn-pill-action {
    border-radius: 20px !important;
    padding: 4px 12px !important;
    font-weight: 500 !important;
    font-size: 12px !important;
}

/* Dark Theme */
body.dark-mode .custom-table-card {
    background: #2a2c33;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
body.dark-mode .custom-table-card .table thead th {
    background: #31343d;
    color: #fff;
    border-bottom-color: #3f424c;
}
body.dark-mode .custom-table-card .table tbody tr:hover {
    background-color: #353842;
}
body.dark-mode .nav-tabs.modern-tabs > li > button,
body.dark-mode .nav-tabs.modern-tabs > li > a {
    background: #2a2c33;
    color: #ccc;
}
body.dark-mode .nav-tabs.modern-tabs > li > button:hover,
body.dark-mode .nav-tabs.modern-tabs > li > a:hover {
    background: linear-gradient(135deg, #2F80ED, #56CCF2);
    color: #fff !important;
}
body.dark-mode .table { border-color: #3f424c !important; }
</style>
<div class="container-fluid">
   <ul class="nav nav-tabs modern-tabs">
      <li class="p-b"><button type="button" class="btn btn-default" data-toggle="modal" data-target="#modalDiv" data-action="new_ticket"><i class="bi bi-plus-circle"></i> New Ticket</button></li>
        
</li>

      <li class="pull-right custom-search">
         <form class="form-inline" action="" method="get">
            <div class="input-group">
               <input type="text" name="search" class="form-control" value="<?=$search_word?>" placeholder="Search">
               <span class="input-group-btn search-select-wrap">
                  <select class="form-control search-select" name="search_type">
                     <option value="subject" <?php if( $search_where == "subject" ): echo 'selected'; endif; ?> >Subject</option>
                     <option value="client" <?php if( $search_where == "client" ): echo 'selected'; endif; ?> >Username</option>
                  </select>
                  <button type="submit" class="btn btn-default"><span class="fa fa-search" aria-hidden="true"></span></button>
               </span>
            </div>
         </form>
      </li>
       <li class="pull-right export-li">
          <?php if($_GET["search"] == 'unread'){ ?>
         <a href="<?=site_url("admin/tickets")?>" class="export">
         <span class="export-title">Show all</span>
         </a>
         <?php }else{ ?>
                      <a href="<?=site_url("admin/tickets")?>?search=unread" class="export">
         <span class="export-title">Show Unread</span>
         </a>
             
        <?php } ?>
      </li>
   </ul>
<div class="row row-xs">

            <div class="col">
                <div class="card dwd-100">
                    <div class="card-body pd-20 table-responsive dof-inherit">
                        <div class="container-fluid pd-t-20 pd-b-20">
                            <ul class="nav nav-tabs pull-right dborder-0">
                                <li class="pull-right export-li">
                                    
                                </li>
                            </ul>
   <div class="card custom-table-card">
   <div class="card-body" style="padding: 0;">
   <table class="table" style="margin-bottom: 0;">
      <thead>
         <tr>
            <th class="checkAll-th">
               <div class="checkAll-holder">
                  <input type="checkbox" id="checkAll">
                  <input type="hidden" id="checkAllText" value="order">
               </div>
               <div class="action-block">
                  <ul class="action-list">
                     <li><span class="countOrders"></span> Tickets selected</li>
                     <li>
                        <div class="dropdown">
                           <button type="button" class="btn btn-default btn-xs dropdown-toggle btn-xs-caret" data-toggle="dropdown"> Bulk actions <span class="caret"></span></button>
                           <ul class="dropdown-menu">
                              <li>
                                 <a class="bulkorder" data-type="unread">Mark all as unread</a>
                                 <a class="bulkorder" data-type="lock">Lock all</a>
                                 <a class="bulkorder" data-type="unlock">Unlcok all</a>
                                 <a class="bulkorder" data-type="close">Close all</a>
                                 <a class="bulkorder" data-type="pending">Mark as awaiting answer</a>
                                 <a class="bulkorder" data-type="answered">Mark as answered</a>
<a class="bulkorder" data-type="delete">Delete Selected</a>
                              </li>
                           </ul>
                        </div>
                     </li>
                  </ul>
               </div>
            </th>
            <th width="5%" class="p-l">ID</th>
            <th width="15%">Member</th>
            <th width="50%">Subject</th>
            <th width="10%" class="dropdown-th">
               <div class="dropdown">
                  <button class="btn btn-th btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                  Status <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                     <li class="active"><a href="<?=site_url("admin/tickets")?>">All (<?=countRow(["table"=>"tickets"]);?>)</a></li>
                     <li><a href="<?=site_url("admin/tickets")?>?status=pending">Pending (<?=countRow(["table"=>"tickets","where"=>["status"=>"pending"]]);?>)</a></li>
                     <li><a href="<?=site_url("admin/tickets")?>?status=answered">Answered (<?=countRow(["table"=>"tickets","where"=>["status"=>"answered"]]);?>)</a></li>
                     <li><a href="<?=site_url("admin/tickets")?>?status=closed">Closed (<?=countRow(["table"=>"tickets","where"=>["status"=>"closed"]]);?>)</a></li>
                  </ul>
               </div>
            </th>
            <th width="10%">Creation Date</th>
            <th width="10%" nowrap="">Last Updated</th>
            <th></th>
         </tr>
      </thead>
      <form id="changebulkForm" action="<?php echo site_url("admin/tickets/multi-action") ?>" method="post">
        <tbody>
          <?php foreach($tickets as $ticket ): ?>
              <tr>
                 <td><input type="checkbox" class="selectOrder" name="ticket[<?php echo $ticket["ticket_id"] ?>]" value="1" style="border:1px solid #fff"></td>
                 <td class="p-l"><?php echo $ticket["ticket_id"] ?></td>
                 <td><?php echo $ticket["username"] ?></td>
                 <td class="subject"><?php  if( $ticket["canmessage"] == 1 ): echo '<i class="fa fa-lock"></i> '; endif;  ?><a href="<?=site_url("admin/tickets/read/".$ticket["ticket_id"])?>"><?php if( $ticket["client_new"] == 2 ): echo "<b>".$ticket["subject"]."</b>"; else: echo $ticket["subject"]; endif; ?></a></td>
                 <td>
                   <?php 
                     $tClass = 'secondary';
                     if($ticket["status"] == 'pending') $tClass = 'warning';
                     if($ticket["status"] == 'answered') $tClass = 'success';
                     if($ticket["status"] == 'closed') $tClass = 'danger';
                   ?>
                   <span class="badge badge-glass-<?= $tClass ?>"><?php echo ucfirst($ticket["status"]) ?></span>
                 </td>
                 <td nowrap=""><?php echo $ticket["time"] ?></td>
                 <td nowrap=""><?php echo $ticket["lastupdate_time"] ?></td>
                 <td class="service-block__action">
                   <div class="dropdown pull-right">
                     <button type="button" class="btn badge-glass-secondary btn-xs dropdown-toggle btn-pill-action" data-toggle="dropdown">Options <span class="caret"></span></button>
                     <ul class="dropdown-menu">
                       <?php if( $ticket["client_new"] == 1 ): ?>
                         <li><a href="<?php echo site_url("admin/tickets/unread/".$ticket["ticket_id"]) ?>">Mark as Unread</a></li>
                       <?php endif; if( $ticket["canmessage"] == 2 ): ?>
                         <li><a href="<?php echo site_url("admin/tickets/lock/".$ticket["ticket_id"]) ?>">Lock support request</a></li>
                       <?php else: ?>
                         <li><a href="<?php echo site_url("admin/tickets/unlock/".$ticket["ticket_id"]) ?>">Unlock support request</a></li>
                       <?php endif; if( $ticket["status"] != "closed" ): ?>
                         <li><a href="<?php echo site_url("admin/tickets/close/".$ticket["ticket_id"]) ?>">Close support request</a></li>
                       <?php endif; ?>
<li><a href="<?php echo site_url("admin/tickets/delete/".$ticket["ticket_id"]) ?>">Delete</a></li>
                     </ul>
                   </div>
                 </td>
              </tr>
            <?php endforeach; ?>
        </tbody>
        <input type="hidden" name="bulkStatus" id="bulkStatus" value="0">
      </form>
   </table>
   </div>
   </div>
   <?php if( $paginationArr["count"] > 1 ): ?>
     <div class="row">
        <div class="col-sm-8">
           <nav>
              <ul class="pagination">
                <?php if( $paginationArr["current"] != 1 ): ?>
                 <li class="prev"><a href="<?php echo site_url("admin/tickets/1".$search_link) ?>">&laquo;</a></li>
                 <li class="prev"><a href="<?php echo site_url("admin/tickets/".$paginationArr["previous"].$search_link) ?>">&lsaquo;</a></li>
                 <?php
                     endif;
                     for ($page=1; $page<=$pageCount; $page++):
                       if( $page >= ($paginationArr['current']-9) and $page <= ($paginationArr['current']+9) ):
                 ?>
                 <li class="<?php if( $page == $paginationArr["current"] ): echo "active"; endif; ?> "><a href="<?php echo site_url("admin/tickets/".$page.$search_link) ?>"><?=$page?></a></li>
                 <?php endif; endfor;
                       if( $paginationArr["current"] != $paginationArr["count"] ):
                 ?>
                 <li class="next"><a href="<?php echo site_url("admin/tickets/".$paginationArr["next"].$search_link) ?>" data-page="1">&rsaquo;</a></li>
                 <li class="next"><a href="<?php echo site_url("admin/tickets/".$paginationArr["count"].$search_link) ?>" data-page="1">&raquo;</a></li>
                 <?php endif; ?>
              </ul>
           </nav>
        </div>
     </div>
   <?php endif; ?>
</div>
<div class="modal modal-center fade" id="confirmChange" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
   <div class="modal-dialog modal-dialog-center" role="document">
      <div class="modal-content">
         <div class="modal-body text-center">
            <h4>Are you sure you want to update the status?</h4>
            <div align="center">
               <a class="btn btn-primary" href="" id="confirmYes">Yes</a>
               <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
            </div>
         </div>
      </div>
   </div>
</div>

<?php include 'footer.php'; ?>