<?php
/**
 * Global Blocks Pagination Template.
 *
 * @var $display - display pagination
 * @var $query - custom Query for pagination
 *
 * @package cyberpress/templates
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

if ( $display ) {
    $total_pages = $query->max_num_pages;

    if ( $total_pages > 1 ) {
        $current_page = max( 1, get_query_var( 'paged' ) );
        ?>
        <nav class="cyberpress-pagination navigation pagination" role="navigation">
            <div class="nav-links">
                <?php
                echo wp_kses_post(
                    paginate_links(
                        array(
                            'current'            => $current_page,
                            'total'              => $total_pages,
                            'prev_text'          => '<span class="screen-reader-text">' . esc_html__( 'Previous page', 'cyberpress' ) . '</span>',
                            'next_text'          => '<span class="screen-reader-text">' . esc_html__( 'Next page', 'cyberpress' ) . '</span>',
                            'before_page_number' => '<span class="meta-nav screen-reader-text">' . esc_html__( 'Page', 'cyberpress' ) . ' </span>',
                        )
                    )
                );
                ?>
            </div>
        </nav>
        <?php
    }
}
