<?php
/**
 *
 * Pagination Functions
 *
 * @package Spa Parlor
 */

/**
 * Pagination for archive.
 */
function spa_parlor_render_posts_pagination() {
    // Get the setting to check if pagination is enabled
    $spa_parlor_is_pagination_enabled = get_theme_mod( 'spa_parlor_enable_pagination', true );

    // Check if pagination is enabled
    if ( $spa_parlor_is_pagination_enabled ) {
        // Get the selected pagination type from the Customizer
        $spa_parlor_pagination_type = get_theme_mod( 'spa_parlor_theme_pagination_type', 'numeric' );

        // Check if the pagination type is "newer_older" (Previous/Next) or "numeric"
        if ( 'newer_older' === $spa_parlor_pagination_type ) :
            // Display "Newer/Older" pagination (Previous/Next navigation)
            the_posts_navigation(
                array(
                    'prev_text' => __( '&laquo; Newer', 'spa-parlor' ),  // Change the label for "previous"
                    'next_text' => __( 'Older &raquo;', 'spa-parlor' ),  // Change the label for "next"
                    'screen_reader_text' => __( 'Posts navigation', 'spa-parlor' ),
                )
            );
        else :
            // Display numeric pagination (Page numbers)
            the_posts_pagination(
                array(
                    'prev_text' => __( '&laquo; Previous', 'spa-parlor' ),
                    'next_text' => __( 'Next &raquo;', 'spa-parlor' ),
                    'type'      => 'list', // Display as <ul> <li> tags
                    'screen_reader_text' => __( 'Posts navigation', 'spa-parlor' ),
                )
            );
        endif;
    }
}
add_action( 'spa_parlor_posts_pagination', 'spa_parlor_render_posts_pagination', 10 );