<?php
global $mhPagination, $mhPaginationShowInfo;
$mhPaginationPages = $mhPagination->getPages();
$mhCurrentPage = $mhPagination->getCurrentPage();
$mhPrevPageUrl = $mhPagination->getPrevUrl();
$mhNextPageUrl = $mhPagination->getNextUrl();
$mhShowInfo = true;
if (isset($mhPaginationShowInfo)) {
    $mhShowInfo = (bool) $mhPaginationShowInfo;
}
?>
<div class="myhome-pagination">
    <?php if ($mhShowInfo) : ?>
        <div class="myhome-pagination__info">
            <?php echo esc_html(tdf_string('showing')); ?>
            <span><?php echo esc_html($mhPagination->getCurrentPageFirstItem()); ?></span> <?php echo esc_html(tdf_string('to')); ?>
            <span><?php echo esc_html($mhPagination->getCurrentPageLastItem()); ?></span> <?php echo esc_html(tdf_string('of')); ?>
            <span><?php echo esc_html($mhPagination->getTotalItems()); ?></span> <?php echo esc_html(tdf_string('results_lower_case')); ?>
        </div>
    <?php endif; ?>

    <div class="myhome-pagination__list">
        <?php if ($mhPrevPageUrl) : ?>
            <a
                    class="myhome-pagination__item"
                    href="<?php echo esc_url($mhPagination->getPrevUrl()); ?>"
            >
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                     stroke-linejoin="round" class="feather feather-chevron-left" aria-hidden="true" focusable="false">
                    <polyline points="15 18 9 12 15 6"></polyline>
                </svg>
            </a>
        <?php endif; ?>

        <?php foreach ($mhPaginationPages as $mhPage) : ?>
            <?php if (!empty($mhPage['url'])) : ?>
                <a
                        href="<?php echo esc_url($mhPage['url']); ?>"
                    <?php if ($mhPage['isCurrent']) : ?>
                        class="myhome-pagination__item myhome-pagination__item--active"
                    <?php else : ?>
                        class="myhome-pagination__item"
                    <?php endif; ?>
                >
                    <?php echo esc_html($mhPage['num']); ?>
                </a>
            <?php else : ?>
                <div class="myhome-pagination__item myhome-pagination__item--separator">
                    ...
                </div>
            <?php endif; ?>
        <?php endforeach; ?>

        <?php if ($mhNextPageUrl) : ?>
            <a
                    class="myhome-pagination__item"
                    href="<?php echo esc_url($mhPagination->getNextUrl()); ?>"
            >
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"
                     fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                     stroke-linejoin="round" class="feather feather-chevron-right" aria-hidden="true" focusable="false">
                    <polyline points="9 18 15 12 9 6"></polyline>
                </svg>
            </a>
        <?php endif; ?>
    </div>
</div>
