<?php

/**
 * Layout: More Button (Ajax).
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$pagination_settings = aiopod_get_option( 'aiopod_pagination_settings' );

$max_num_pages     = ! empty( $attributes['max_num_pages'] ) ? (int) $attributes['max_num_pages'] : 1;
$paged             = ! empty( $attributes['paged'] ) ? (int) $attributes['paged'] : aiopod_get_page_number();
$more_button_label = ! empty( $pagination_settings['more_button_label'] ) ? $pagination_settings['more_button_label'] : __( 'Load More', 'aio-podcast-studio' );

if ( $paged < $max_num_pages ) {
    $json_params = aiopod_prepare_attributes_for_ajax( $attributes );			

    echo '<div class="aiopod-pagination">';
    echo sprintf( '<aiopod-pagination is-ajax data-params="%s">', esc_attr( wp_json_encode( $json_params ) ) );
    echo sprintf( '<button type="button" class="aiopod-button aiopod-button--loadmore">%s</button>', esc_html( $more_button_label ) );
    echo '</aiopod-pagination>';
    echo '</div>';
}
