<?php

/**
* @package  os_lib
* @copyright OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru)
* @link http://ordasoft.com/
* @description OrdaSoft Library
*/

namespace OrdaSoft\os_lib;

/**
 * Pagination Class. Provides a common interface for content pagination for the Joomla! CMS.
 *
 * @since  1.5
 */
class os_libPagination
{
    /**
     * @var    integer  The record number to start displaying from.
     * @since  1.5
     */
    public $limitstart = null;

    /**
     * @var    integer  Number of rows to display per page.
     * @since  1.5
     */
    public $limit = null;

    /**
     * @var    integer  Total number of rows.
     * @since  1.5
     */
    public $total = null;

    /**
     * @var    integer  Prefix used for request variables.
     * @since  1.6
     */
    public $prefix = null;

    /**
     * @var    integer  Value pagination object begins at
     * @since  3.0
     */
    public $pagesStart;

    /**
     * @var    integer  Value pagination object ends at
     * @since  3.0
     */
    public $pagesStop;

    /**
     * @var    integer  Current page
     * @since  3.0
     */
    public $pagesCurrent;

    /**
     * @var    integer  Total number of pages
     * @since  3.0
     */
    public $pagesTotal;

    /**
     * @var    boolean  The flag indicates whether to add limitstart=0 to URL
     * @since  3.9.0
     */
    public $hideEmptyLimitstart = false;

    /**
     * @var    boolean  View all flag
     * @since  3.0
     */
    protected $viewall = false;

    /**
     * Additional URL parameters to be added to the pagination URLs generated by the class.  These
     * may be useful for filters and extra values when dealing with lists and GET requests.
     *
     * @var    array
     * @since  3.0
     */
    protected $additionalUrlParams = [];

    
    /**
     * Pagination data object
     *
     * @var    object
     * @since  3.4
     */
    protected $data;

    /**
     * Constructor.
     *
     * @param   integer         $total       The total number of items.
     * @param   integer         $limitstart  The offset of the item to start at.
     * @param   integer         $limit       The number of items to display per page.
     * @param   string          $prefix      The prefix used for request variables.
     
     *
     * @since   1.5
     */
    public function __construct($total, $limitstart, $limit, $prefix = '')
    {
        // Value/type checking.
        $this->total      = (int) $total;
        $this->limitstart = (int) max($limitstart, 0);
        $this->limit      = (int) max($limit, 0);
        $this->prefix     = $prefix;
        

        if ($this->limit > $this->total) {
            $this->limitstart = 0;
        }

        if (!$this->limit) {
            $this->limit      = $total;
            $this->limitstart = 0;
        }

        /*
         * If limitstart is greater than total (i.e. we are asked to display records that don't exist)
         * then set limitstart to display the last natural page of results
         */
        if ($this->limitstart > $this->total - $this->limit) {
            $this->limitstart = max(0, (int) (ceil($this->total / $this->limit) - 1) * $this->limit);
        }

        // Set the total pages and current page values.
        if ($this->limit > 0) {
            $this->pagesTotal   = (int) ceil($this->total / $this->limit);
            $this->pagesCurrent = (int) ceil(($this->limitstart + 1) / $this->limit);
        }

        // Set the pagination iteration loop values.
        $displayedPages   = 10;
        $this->pagesStart = $this->pagesCurrent - ($displayedPages / 2);

        if ($this->pagesStart < 1) {
            $this->pagesStart = 1;
        }

        if ($this->pagesStart + $displayedPages > $this->pagesTotal) {
            $this->pagesStop = $this->pagesTotal;

            if ($this->pagesTotal < $displayedPages) {
                $this->pagesStart = 1;
            } else {
                $this->pagesStart = $this->pagesTotal - $displayedPages + 1;
            }
        } else {
            $this->pagesStop = $this->pagesStart + $displayedPages - 1;
        }

        // If we are viewing all records set the view all flag to true.
        if ($limit === 0) {
            $this->viewall = true;
        }
    }

    /**
     * Method to set an additional URL parameter to be added to all pagination class generated
     * links.
     *
     * @param   string  $key    The name of the URL parameter for which to set a value.
     * @param   mixed   $value  The value to set for the URL parameter.
     *
     * @return  mixed  The old value for the parameter.
     *
     * @since   1.6
     */
    // public function setAdditionalUrlParam($key, $value)
    // {
    //     // Get the old value to return and set the new one for the URL parameter.
    //     $result = (isset($this->additionalUrlParams[$key])) ? $this->additionalUrlParams[$key] : null;

    //     // If the passed parameter value is null unset the parameter, otherwise set it to the given value.
    //     if ($value === null) {
    //         unset($this->additionalUrlParams[$key]);
    //     } else {
    //         $this->additionalUrlParams[$key] = $value;
    //     }

    //     return $result;
    // }

    /**
     * Method to get an additional URL parameter (if it exists) to be added to
     * all pagination class generated links.
     *
     * @param   string  $key  The name of the URL parameter for which to get the value.
     *
     * @return  mixed  The value if it exists or null if it does not.
     *
     * @since   1.6
     */
    // public function getAdditionalUrlParam($key)
    // {
    //     return (isset($this->additionalUrlParams[$key])) ? $this->additionalUrlParams[$key] : null;
    // }

    /**
     * Return the rationalised offset for a row with a given index.
     *
     * @param   integer  $index  The row index
     *
     * @return  integer  Rationalised offset for a row with a given index.
     *
     * @since   1.5
     */
    public function getRowOffset($index)
    {
        return $index + 1 + $this->limitstart;
    }

    /**
     * Return the pagination data object, only creating it if it doesn't already exist.
     *
     * @return  \stdClass  Pagination data object.
     *
     * @since   1.5
     */
    // public function getData()
    // {
    //     if (!$this->data) {
    //         $this->data = $this->_buildDataObject();
    //     }

    //     return $this->data;
    // }

    /**
     * Create and return the pagination pages counter string, ie. Page 2 of 4.
     *
     * @return  string   Pagination pages counter string.
     *
     * @since   1.5
     */
    public function getPagesCounter()
    {
        $html = null;

        if ($this->pagesTotal > 1) {
            $html .= sprintf(os_libMain::text('OS_LIB_HTML_PAGE_CURRENT_OF_TOTAL'), $this->pagesCurrent, $this->pagesTotal);
        }

        return $html;
    }

    /**
     * Create and return the pagination result set counter string, e.g. Results 1-10 of 42
     *
     * @return  string   Pagination result set counter string.
     *
     * @since   1.5
     */
    public function getResultsCounter()
    {
        $html       = null;
        $fromResult = $this->limitstart + 1;

        // If the limit is reached before the end of the list.
        if ($this->limitstart + $this->limit < $this->total) {
            $toResult = $this->limitstart + $this->limit;
        } else {
            $toResult = $this->total;
        }

        // If there are results found.
        if ($this->total > 0) {
            $msg = sprintf(os_libMain::text('OS_LIB_HTML_RESULTS_OF'), $fromResult, $toResult, $this->total);
            $html .= "\n" . $msg;
        } else {
            $html .= "\n" . os_libMain::text('OS_LIB_HTML_NO_RECORDS_FOUND');
        }

        return $html;
    }

    /**
     * Create and return the pagination page list string, ie. Previous, Next, 1 2 3 ... x.
     *
     * @return  string  Pagination page list string.
     *
     * @since   1.5
     */
    public function getPagesLinks()
    {
        // Build the page navigation list.
        $data = $this->_buildDataObject();

        $list           = [];
        $list['prefix'] = $this->prefix;

        
        // Build the select list
        if ($data->all->base !== null) {
            $list['all']['active'] = true;
            $list['all']['data']   = $this->_item_active($data->all);
        } else {
            $list['all']['active'] = false;
            $list['all']['data']   = $this->_item_inactive($data->all);
        }

        if ($data->start->base !== null) {
            $list['start']['active'] = true;
            $list['start']['data']   = $this->_item_active($data->start);
        } else {
            $list['start']['active'] = false;
            $list['start']['data']   = $this->_item_inactive($data->start);
        }

        if ($data->previous->base !== null) {
            $list['previous']['active'] = true;
            $list['previous']['data']   = $this->_item_active($data->previous);
        } else {
            $list['previous']['active'] = false;
            $list['previous']['data']   = $this->_item_inactive($data->previous);
        }

        // Make sure it exists
        $list['pages'] = [];

        foreach ($data->pages as $i => $page) {
            if ($page->base !== null) {
                $list['pages'][$i]['active'] = true;
                $list['pages'][$i]['data']   = $this->_item_active($page);
            } else {
                $list['pages'][$i]['active'] = false;
                $list['pages'][$i]['data']   = $this->_item_inactive($page);
            }
        }

        if ($data->next->base !== null) {
            $list['next']['active'] = true;
            $list['next']['data']   = $this->_item_active($data->next);
        } else {
            $list['next']['active'] = false;
            $list['next']['data']   = $this->_item_inactive($data->next);
        }

        if ($data->end->base !== null) {
            $list['end']['active'] = true;
            $list['end']['data']   = $this->_item_active($data->end);
        } else {
            $list['end']['active'] = false;
            $list['end']['data']   = $this->_item_inactive($data->end);
        }

        if ($this->total > $this->limit) {
            return $this->_list_render($list);
        }

        return '';
    }

    /**
     * Get the pagination links
     *
     * @param   string  $layoutId  Layout to render the links
     * @param   array   $options   Optional array with settings for the layout
     *
     * @return  string  Pagination links.
     *
     * @since   3.3
     */
    public function getPaginationLinks($layoutId = 'joomla.pagination.links', $options = [])
    {
        // Allow to receive a null layout
        $layoutId = (isset($layoutId)) ? $layoutId : 'joomla.pagination.links';

        $list = [
            'prefix'       => $this->prefix,
            'limit'        => $this->limit,
            'limitstart'   => $this->limitstart,
            'total'        => $this->total,
            'limitfield'   => $this->getLimitBox(),
            'pagescounter' => $this->getPagesCounter(),
            'pages'        => $this->getPaginationPages(),
            'pagesTotal'   => $this->pagesTotal,
        ];

        //return \JLayoutHelper::render($layoutId, ['list' => $list, 'options' => $options]);

//$list  = $displayData['list'];
$pages = $list['pages'];

$options = new \JRegistry($options);

$showLimitBox   = $options->get('showLimitBox', false);
$showPagesLinks = $options->get('showPagesLinks', true);
$showLimitStart = $options->get('showLimitStart', true);

// Calculate to display range of pages
$currentPage = 1;
$range       = 1;
$step        = 5;

if (!empty($pages['pages'])) {
    foreach ($pages['pages'] as $k => $page) {
        if (!$page['active']) {
            $currentPage = $k;
        }
    }
}

if ($currentPage >= $step) {
    if ($currentPage % $step === 0) {
        $range = ceil($currentPage / $step) + 1;
    } else {
        $range = ceil($currentPage / $step);
    }
}
?>


<?php if (!empty($pages)) { 

    ?>
    <nav class="pagination__wrapper" aria-label="<?php echo os_libMain::text('OS_LIB_HTML_PAGINATION'); ?>">
        <div class="pagination pagination-toolbar text-center">

            <?php if ($showLimitBox) : ?>
                <div class="limit float-end">
                    <?php echo os_libMain::text('OS_LIB_DISPLAY_NUM') . $list['limitfield']; ?>
                </div>
            <?php endif; ?>

            <?php if ($showPagesLinks) : ?>
                <ul class="pagination ms-auto mb-4 me-0">
                    <?php echo $this->getLinkLayout( $pages['start']['data'], $pages['start']['active']) ; ?>
                    <?php echo $this->getLinkLayout( $pages['previous']['data'], $pages['previous']['active']) ; ?>
                    <?php foreach ($pages['pages'] as $k => $page) : ?>
                        <?php $output = $this->getLinkLayout( $page['data'], $page['active']) ; ?>
                        <?php if (in_array($k, range($range * $step - ($step + 1), $range * $step), true)) : ?>
                            <?php if (($k % $step === 0 || $k === $range * $step - ($step + 1)) && $k !== $currentPage && $k !== $range * $step - $step) : ?>
                                <?php $output = preg_replace('#(<a.*?>).*?(</a>)#', '$1...$2', $output); ?>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php echo $output; ?>
                    <?php endforeach; ?>
                    <?php echo $this->getLinkLayout( $pages['next']['data'], $pages['next']['active']); ?>
                    <?php echo $this->getLinkLayout( $pages['end']['data'], $pages['end']['active']); ?>
                </ul>
            <?php endif; ?>

            <?php if ($showLimitStart) : ?>
                <input type="hidden" name="<?php echo $list['prefix']; ?>limitstart" value="<?php echo $list['limitstart']; ?>">
            <?php endif; ?>

        </div>
    </nav>
<?php } 



    }

    /**
     * Create and return the pagination pages list, ie. Previous, Next, 1 2 3 ... x.
     *
     * @return  array  Pagination pages list.
     *
     * @since   3.3
     */
    public function getPaginationPages()
    {
        $list = [];

        if ($this->total > $this->limit) {
            // Build the page navigation list.
            $data = $this->_buildDataObject();

            // All
            $list['all']['active'] = $data->all->base !== null;
            $list['all']['data']   = $data->all;

            // Start
            $list['start']['active'] = $data->start->base !== null;
            $list['start']['data']   = $data->start;

            // Previous link
            $list['previous']['active'] = $data->previous->base !== null;
            $list['previous']['data']   = $data->previous;

            // Make sure it exists
            $list['pages'] = [];

            foreach ($data->pages as $i => $page) {
                $list['pages'][$i]['active'] = $page->base !== null;
                $list['pages'][$i]['data']   = $page;
            }

            $list['next']['active'] = $data->next->base !== null;
            $list['next']['data']   = $data->next;

            $list['end']['active'] = $data->end->base !== null;
            $list['end']['data']   = $data->end;
        }

        return $list;
    }

    /**
     * Return the pagination footer.
     *
     * @return  string  Pagination footer.
     *
     * @since   1.5
     */
    public function getListFooter()
    {
        
        return $this->getPaginationLinks();
    }

    /**
     * Creates a dropdown box for selecting how many records to show per page.
     *
     * @return  string  The HTML for the limit # input box.
     *
     * @since   1.5
     */
    public function getLimitBox()
    {
        $limits = [];

        // Make the option list.
        for ($i = 5; $i <= 30; $i += 5) {
            $limits[] = os_libHtmlInputs::option("$i");
        }

        $limits[] = os_libHtmlInputs::option('50', '50');
        $limits[] = os_libHtmlInputs::option('100', '100');
        $limits[] = os_libHtmlInputs::option('200 ', '200');
        $limits[] = os_libHtmlInputs::option('500', '500');
        $limits[] = os_libHtmlInputs::option('0', os_libMain::text('OS_LIB_LABEL_SELECT_ALL'));

        $selected = $this->viewall ? 0 : $this->limit;

        // Build the select list.
        // if ($this->app->isClient('administrator')) {
            $html = os_libHtmlInputs::genericlist(
                $limits,
                $this->prefix . 'limit',
                'class="form-select" onchange="Joomla.submitform();"',
                'value',
                'text',
                $selected
            );
        // } else {
        //     $html = JHTML::_(
        //         'select.genericlist',
        //         $limits,
        //         $this->prefix . 'limit',
        //         'class="form-select" onchange="this.form.submit()"',
        //         'value',
        //         'text',
        //         $selected
        //     );
        // }

        return $html;
    }

    /**
     * Return the icon to move an item UP.
     *
     * @param   integer  $i          The row index.
     * @param   boolean  $condition  True to show the icon.
     * @param   string   $task       The task to fire.
     * @param   string   $alt        The image alternative text string.
     * @param   boolean  $enabled    An optional setting for access control on the action.
     * @param   string   $checkbox   An optional prefix for checkboxes.
     *
     * @return  string   Either the icon to move an item up or a space.
     *
     * @since   1.5
     */
    public function orderUpIcon($i, $condition = true, $task = 'orderup', $alt = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb')
    {
        if (($i > 0 || ($i + $this->limitstart > 0)) && $condition) {
            return \JHTML::_('jgrid.orderUp', $i, $task, '', $alt, $enabled, $checkbox);
        }

        return '&#160;';
    }

    /**
     * Return the icon to move an item DOWN.
     *
     * @param   integer  $i          The row index.
     * @param   integer  $n          The number of items in the list.
     * @param   boolean  $condition  True to show the icon.
     * @param   string   $task       The task to fire.
     * @param   string   $alt        The image alternative text string.
     * @param   boolean  $enabled    An optional setting for access control on the action.
     * @param   string   $checkbox   An optional prefix for checkboxes.
     *
     * @return  string   Either the icon to move an item down or a space.
     *
     * @since   1.5
     */
    public function orderDownIcon($i, $n, $condition = true, $task = 'orderdown', $alt = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb')
    {
        if (($i < $n - 1 || $i + $this->limitstart < $this->total - 1) && $condition) {
            return \JHTML::_('jgrid.orderDown', $i, $task, '', $alt, $enabled, $checkbox);
        }

        return '&#160;';
    }

    /**
     * Create the HTML for a list footer
     *
     * @param   array  $list  Pagination list data structure.
     *
     * @return  string  HTML for a list footer
     *
     * @since   1.5
     */
    // protected function _list_footer($list)
    // {
    //     $html = "<div class=\"list-footer\">\n";

    //     $html .= "\n<div class=\"limit\">" . os_libMain::text('OS_LIB_DISPLAY_NUM') . $list['limitfield'] . "</div>";
    //     $html .= $list['pageslinks'];
    //     $html .= "\n<div class=\"counter\">" . $list['pagescounter'] . "</div>";

    //     $html .= "\n<input type=\"hidden\" name=\"" . $list['prefix'] . "limitstart\" value=\"" . $list['limitstart'] . "\">";
    //     $html .= "\n</div>";

    //     return $html;
    // }

    /**
     * Create the html for a list footer
     *
     * @param   array  $list  Pagination list data structure.
     *
     * @return  string  HTML for a list start, previous, next,end
     *
     * @since   1.5
     */
    protected function _list_render($list)
    {
//        return \JLayoutHelper::render('joomla.pagination.list', ['list' => $list]);

?>
<nav class="pagination__wrapper" aria-label="<?php echo os_libMain::text('OS_LIB_HTML_PAGINATION'); ?>">
    <ul class="pagination ms-0 mb-4">
        <?php echo $list['start']['data']; ?>
        <?php echo $list['previous']['data']; ?>

        <?php foreach ($list['pages'] as $page) : ?>
            <?php echo $page['data']; ?>
        <?php endforeach; ?>

        <?php echo $list['next']['data']; ?>
        <?php echo $list['end']['data']; ?>
    </ul>
</nav>
<?php
    }



    /**
     * Method to create an active pagination link to the item
     *
     * @param   os_libPaginationObject  $item  The object with which to make an active link.
     *
     * @return  string  HTML link
     *
     * @since   1.5
     */
    protected function _item_active(os_libPaginationObject $item)
    {
        return $this->getLinkLayout( $item, true);
        // return \JLayoutHelper::render('joomla.pagination.link', ['data' => $item, 'active' => true]);
    }

    /**
     * Method to create an inactive pagination string
     *
     * @param   os_libPaginationObject  $item  The item to be processed
     *
     * @return  string
     *
     * @since   1.5
     */
    protected function _item_inactive(os_libPaginationObject $item)
    {
        return $this->getLinkLayout( $item, false);
        // return \JLayoutHelper::render('joomla.pagination.link', ['data' => $item, 'active' => false]);
    }

    /**
     * Create and return the pagination data object.
     *
     * @return  \stdClass  Pagination data object.
     *
     * @since   1.5
     */
    protected function _buildDataObject()
    {
        $data = new \stdClass();

        // Build the additional URL parameters string.
        $params = '';

        if (!empty($this->additionalUrlParams)) {
            foreach ($this->additionalUrlParams as $key => $value) {
                $params .= '&' . $key . '=' . $value;
            }
        }

        $data->all = new os_libPaginationObject(os_libMain::text('OS_LIB_HTML_VIEW_ALL'), $this->prefix);

        if (!$this->viewall) {
            $data->all->base = '0';
            $data->all->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=');
        }

        // Set the start and previous data objects.
        $data->start    = new os_libPaginationObject(os_libMain::text('OS_LIB_HTML_START'), $this->prefix);
        $data->previous = new os_libPaginationObject(os_libMain::text('OS_LIB_PREV'), $this->prefix);

        if ($this->pagesCurrent > 1) {
            $page = ($this->pagesCurrent - 2) * $this->limit;

            if ($this->hideEmptyLimitstart) {
                $data->start->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=');
            } else {
                $data->start->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=0');
            }

            $data->start->base    = '0';
            $data->previous->base = $page;

            if ($page === 0 && $this->hideEmptyLimitstart) {
                $data->previous->link = $data->start->link;
            } else {
                $data->previous->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $page);
            }
        }

        // Set the next and end data objects.
        $data->next = new os_libPaginationObject(os_libMain::text('OS_LIB_NEXT'), $this->prefix);
        $data->end  = new os_libPaginationObject(os_libMain::text('OS_LIB_HTML_END'), $this->prefix);

        if ($this->pagesCurrent < $this->pagesTotal) {
            $next = $this->pagesCurrent * $this->limit;
            $end  = ($this->pagesTotal - 1) * $this->limit;

            $data->next->base = $next;
            $data->next->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $next);
            $data->end->base  = $end;
            $data->end->link  = \JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $end);
        }

        $data->pages = [];
        $stop        = $this->pagesStop;

        for ($i = $this->pagesStart; $i <= $stop; $i++) {
            $offset = ($i - 1) * $this->limit;

            $data->pages[$i] = new os_libPaginationObject($i, $this->prefix);

            if ($i != $this->pagesCurrent || $this->viewall) {
                $data->pages[$i]->base = $offset;

                if ($offset === 0 && $this->hideEmptyLimitstart) {
                    $data->pages[$i]->link = $data->start->link;
                } else {
                    $data->pages[$i]->link = \JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $offset);
                }
            } else {
                $data->pages[$i]->active = true;
            }
        }

        return $data;
    }

    protected function getLinkLayout($item, $active){
        $display = $item->text;
        $app = \JFactory::getApplication();

        switch ((string) $item->text) {
            // Check for "Start" item
            case os_libMain::text('OS_LIB_HTML_START'):
                $icon = $app->getLanguage()->isRtl() ? 'icon-angle-double-right' : 'icon-angle-double-left';
                $aria = \JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
                break;

            // Check for "Prev" item
            case os_libMain::text('OS_LIB_PREV'):
                $item->text = os_libMain::text('JPREVIOUS');
                $icon = $app->getLanguage()->isRtl() ? 'icon-angle-right' : 'icon-angle-left';
                $aria = \JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
                break;

            // Check for "Next" item
            case os_libMain::text('OS_LIB_NEXT'):
                $icon = $app->getLanguage()->isRtl() ? 'icon-angle-left' : 'icon-angle-right';
                $aria = \JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
                break;

            // Check for "End" item
            case os_libMain::text('OS_LIB_HTML_END'):
                $icon = $app->getLanguage()->isRtl() ? 'icon-angle-double-left' : 'icon-angle-double-right';
                $aria = \JText::sprintf('JLIB_HTML_GOTO_POSITION', strtolower($item->text));
                break;

            default:
                $icon = null;
                $aria = \JText::sprintf('JLIB_HTML_GOTO_PAGE', strtolower($item->text));
                break;
        }

        if ($icon !== null) {
            $display = '<span class="' . $icon . '" aria-hidden="true"></span>';
        }

        if ($active) {
            if ($item->base > 0) {
                $limit = 'limitstart.value=' . $item->base;
            } else {
                $limit = 'limitstart.value=0';
            }

            $class = 'active';

            if (!os_libMain::is_site()) {
                $link = 'href="#" onclick="document.adminForm.' . $item->prefix . $limit . '; Joomla.submitform();return false;"';
            } elseif (os_libMain::is_site()) {
                $link = 'href="' . $item->link . '"';
            }
        } else {
            $class = (property_exists($item, 'active') && $item->active) ? 'active' : 'disabled';
        }


        $html = '';
        // ob_start();
        if ($active) {
            $html = '<li class="page-item"><a aria-label="'.$aria.'" '.$link.' class="page-link">'.$display.'</a></li>';

        } elseif (isset($item->active) && $item->active) {
            $aria = \JText::sprintf('JLIB_HTML_PAGE_CURRENT', strtolower($item->text));
            $html = '<li class="'.$class.' page-item"><a aria-current="true" aria-label="'.$aria.'" href="#" class="page-link">'.$display.'</a></li>';
        }else{
            $html = '<li class="'.$class.' page-item"><span class="page-link" aria-hidden="true">'.$display.'</span></li>';

        }
        // $html = ob_get_contents();
        // ob_clean();
        return $html;
    }
}


class os_libPaginationObject
{
    /**
     * @var    string  The link text.
     * @since  1.5
     */
    public $text;

    /**
     * @var    integer  The number of rows as a base offset.
     * @since  1.5
     */
    public $base;

    /**
     * @var    string  The link URL.
     * @since  1.5
     */
    public $link;

    /**
     * @var    integer  The prefix used for request variables.
     * @since  1.6
     */
    public $prefix;

    /**
     * @var    boolean  Flag whether the object is the 'active' page
     * @since  3.0
     */
    public $active;

    /**
     * Class constructor.
     *
     * @param   string   $text    The link text.
     * @param   string   $prefix  The prefix used for request variables.
     * @param   integer  $base    The number of rows as a base offset.
     * @param   string   $link    The link URL.
     * @param   boolean  $active  Flag whether the object is the 'active' page
     *
     * @since   1.5
     */
    public function __construct($text, $prefix = '', $base = null, $link = null, $active = false)
    {
        $this->text   = $text;
        $this->prefix = $prefix;
        $this->base   = $base;
        $this->link   = $link;
        $this->active = $active;
    }
}
