<?php

  $view_page = $this->view_page;
  $thePageID = $this->thePageID;
  $thePageRecord = $this->recordsPerPage;
  $theTotalPage = $this->theTotalPage;
  $hideDD = $this->hideDD;
  $total =  $this->theTotalRecords;
  $limit =  $this->limit;
  $thePOS = $this->thePOS;

  if($total > 0){

?>
<div class="pull-left full-width <?php echo $thePOS == 'bottom' ? ' bottom' : '';?>">
    <div class="row">
        <?php if (!$hideDD) { ?>
            <div class="col-sm-3">
                <form>
                    <div class="form-group row">
                        <label for="Display" class="col-sm-3 top-space">Display</label>
                        <div class="col-sm-5">
                            <select class="form-control" onChange="changePerPageRecords(this.options[selectedIndex].value);">
                                <option value='20' <?php if($thePageRecord=='20'){ ?> selected  <?php }?> >20</option>
                                <option value='50' <?php if( $thePageRecord=='50'){ ?> selected  <?php }?>>50</option>
                                <option value='100' <?php if( $thePageRecord=='100' ){ ?> selected  <?php }?> >100</option>
                                <option value='200' <?php if( $thePageRecord== '200' ){ ?> selected  <?php }?>>200</option>
                                <option value='300' <?php if( $thePageRecord== '300' ){ ?> selected  <?php }?>>300</option>
                                <option value='500' <?php if( $thePageRecord== '500'){ ?> selected  <?php }?>>500</option>
                                <option value='1000' <?php if( $thePageRecord== '1000' ){ ?> selected  <?php }?>>1000</option>
                            </select> 
                        </div>
                        <div class="col-sm-4 top-space no-padding">
                           <label for="Display"> per page.</label>
                        </div>
                    </div>
                </form>
            </div>
        <?php } ?>    
        <div class="col-sm-2 top-space">
            <p>
                <?php echo (($thePageID - 1) * $thePageRecord + 1) ?>   -  
                <?php echo (($thePageID * $thePageRecord) > $total ? $total : $thePageID * $thePageRecord) ?>  of  
                <?php echo $total ?>
            </p>
        </div>
        <div class="col-sm-7 pull-right">
            <div class="pagination-panel pull-right">
                <ul class="pagination">
                    <?php if($thePageID > 1)  { ?>
                        <li class="show">
                            <a class="pagingControl" href="javascript:callTrigger('<?php echo ($thePageID - 1)?>');"><img src="/images/redesign/left-arrow-pagination.svg" /></a>
                        </li>
                    <?php } else { ?> 
                        <li class="disabled prev-arrow show"><span><img src="/images/redesign/left-arrow-pagination.svg" /></span></li>
                    <?php } ?>
                    <?php
                        $level = round($thePageID/($limit-1));
                        if ($level != 0 && $thePageID %($limit-1) != 1) {
                            $level = $level - 1;
                        }
                        $row  = $level +1;
                        $maxLimit = ($limit * $row) - $level;
                        if ($maxLimit > $theTotalPage) {
                            $maxLimit = $theTotalPage;
                        }
                        if ($thePageID < (($limit* $row) - $level) ) {
                            $startIndex = $maxLimit - ($limit-1);
                            if($startIndex < 1) {
                                $startIndex = 1;
                            }
                        } else {
                            $startIndex = $thePageID;
                        }
                        if ($theTotalPage > 1) {
                            if ($theTotalPage <= 5) { 
                                for ($i = 1; $i <= $theTotalPage; $i++) {
                                    if ($thePageID == $i) { ?>
                                        <li class="active"><span><?php echo $i  ?></span></li>
                                    <?php } else { ?>
                                        <li class="show">
                                            <a class="pagingControl" href="javascript:callTrigger('<?php echo $i ?>')"><?php echo $i  ?></a> 
                                        </li>
                                    <?php }
                                } 
                            } elseif ($theTotalPage > 5 && $thePageID == 1) { ?>
                                <li class="active"><span><?php echo $thePageID  ?> </span></li>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $thePageID + 1 ?>')"><?php echo $thePageID + 1  ?></a>
                                </li>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $thePageID+2 ?>')"><?php echo $thePageID + 2  ?></a>
                                </li>
                                <li class="show"><span><?php echo '...' ?></span></li>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $theTotalPage ?>')"><?php echo $theTotalPage  ?></a>
                                </li>
                            <?php } elseif ($thePageID > 1 && $thePageID < $theTotalPage - 3) { ?>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $thePageID - 1 ?>')"><?php echo $thePageID - 1  ?></a>
                                </li>
                                <li class="active"><span><?php echo $thePageID ?></span></li>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $thePageID+1 ?>')"> <?php echo $thePageID + 1  ?></a>
                                </li>
                                <li class="show"><span><?php echo '...' ?></span></li>
                                <li class="show">
                                    <a class="pagingControl" href="javascript:callTrigger('<?php echo $theTotalPage ?>')"><?php echo $theTotalPage  ?></a>
                                </li>
                            <?php } else {
                                for ($i = $theTotalPage-4; $i <= $theTotalPage; $i++) {
                                    if ($thePageID == $i) { ?>
                                        <li class="active"><span><?php echo $i ?></span></li>
                                    <?php } else { ?>
                                        <li class="show">
                                            <a class="pagingControl" href="javascript:callTrigger('<?php echo $i ?>')"><?php echo $i  ?></a>
                                        </li>
                                    <?php  }
                                }
                            } 
                        }
                    if ($thePageID < $theTotalPage) { ?>
                        <li class="show next-arrow">
                            <a class="pagingControl" href="javascript:callTrigger('<?php echo ($thePageID + 1)?>');"><img src="/images/redesign/right-arrow-pagination.svg" /></a>
                        </li>
                    <?php } else { ?>
                        <li class="show disabled next-arrow"><span><img src="/images/redesign/right-arrow-pagination.svg" /></span></li>
                    <?php } ?>
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
function callTrigger(value){
	$(document).trigger('GET_RELEASE_AFTER_PAGINATION',value);
}
function changePerPageRecords(pageNumber){
	$(document).trigger('CHANGE_PAGERECORDS_PAGINATION',pageNumber);
}
</script>
<?php } ?>