<?php
/**
 * YAWIK
 *
 * @filesource
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
 * @license       MIT
 */
/**
 * {{rtd: Renders paginations}}
 */

if ($this->pageCount):

    //$this->headScript()->appendFile($this->basepath('modules/Core/js/core.pagination.js'));

    $query = $this->params()->fromQuery();

    $enableNextButton = true;
    $enablePrevButton = true;

    ?>
    <div class="row yk-pagination">
        <div class="col-md-9">
            <!-- First page link -->
            <ul class="pagination">
                <?php if (isset($this->previous)): ?>
                    <li><a title="<?php echo $this->translate('First') ?>" href="<?php $query['page'] = $this->first;
                        echo $this->url($this->route, array('lang' => $this->lang), array('query' => $query), true
                        ); ?>">
                            <i class="yk-icon yk-icon-pagination-start"></i>
                        </a></li>
                <?php else: ?>
                    <li class="disabled"><a title="<?php echo $this->translate('First'); ?>"><i
                                class="yk-icon yk-icon-pagination-start"></i></a></li>
                <?php endif; ?>
                <!-- Previous page link -->
                <?php if ($enablePrevButton): ?>
                    <?php if (isset($this->previous)): $query['page'] = $this->previous; ?>
                        <?php $url = $this->url($this->route, ['lang' => $this->lang], ['query' => $query], true); ?>
                        <li><a title="<?= $this->translate('Back') ?>" href="<?php echo $url ?>" rel="nofollow"><i class="fa fa-angle-left"></i>
                                <?php $this->headLink(array('rel' => 'prev', 'href' => $url), 'PREPEND'); ?>
                            </a></li>
                    <?php else: ?>
                        <li class="disabled"><a title="<?=$this->translate('Back') ?>"><i class="fa fa-angle-left"></i></a></li>
                    <?php endif; ?>
                <?php endif;?>

                <!-- Numbered page links -->
                <?php foreach ($this->pagesInRange as $page): ?>
                    <?php if ($page != $this->current): ?>
                        <?php $query['page'] = $page; ?>
                        <li>
                            <a href="<?php echo $this->url($this->route, array('lang' => $this->lang),
                                                           array('query' => $query), true
                            ); ?>" rel="nofollow">
                                <?php echo $page; ?>
                            </a>
                        </li>
                    <?php else: ?>
                        <li class="disabled">
                            <a><?php echo $page; ?></a>
                        </li>
                    <?php endif; ?>
                <?php endforeach; ?>


                <!-- Next page link -->
                <?php if ($enableNextButton): ?>
                <?php if (isset($this->next)): $query['page'] = $this->next; ?>
                    <?php $url                 =
                        $this->url($this->route, array('lang' => $this->lang), array('query' => $query), true); ?>
                    <li><a title="<?=$this->translate('Next') ?>" href="<?php echo $url ?>" rel="nofollow"><i class="fa fa-angle-right"></i>
                            <?php $this->headLink(array('rel' => 'next', 'href' => $url), 'PREPEND'); ?>
                        </a></li>
                <?php else: ?>
                    <li class="disabled"><a title="<?=$this->translate('Next') ?>"><i class="fa fa-angle-right"></i></a></li>
                <?php endif; ?>
                <?php endif; ?>
                <!-- Last page link -->
                <?php if (isset($this->next)): $query['page'] = $this->last; ?>
                    <li><a title="<?=$this->translate('Last') ?>" href="<?=$this->url($this->route,
                                                                                      ['lang' => $this->lang],
                                                                                      ['query' => $query],
                                                                                      true); ?>" rel="nofollow">
                            <i class="yk-icon yk-icon-pagination-end"></i>
                        </a></li>
                <?php else: ?>
                    <li class="disabled"><a title="<?php echo $this->translate('Last') ?>"><i
                                class="yk-icon yk-icon-pagination-end"></i></a></li>
                <?php endif; ?>
            </ul>
        </div>
        <div class="col-md-3 text-right">
            <?=sprintf($this->translate('%1$s - %2$s of %3$s'), $this->firstItemNumber, $this->lastItemNumber, $this->totalItemCount) ?>
        </div>
    </div>
<?php endif; ?>
