<?php
/**
 * Ajax Load More Template
 * 
 * This template displays a "Load More" button for loading additional properties via AJAX.
 * When clicked, it loads more properties without refreshing the page.
 * 
 * HOW TO OVERRIDE THIS TEMPLATE:
 * 1. Copy this file from: wp-content/plugins/havenlytics/templates/search/ajaxload-more.php
 * 2. Paste it to your theme at: wp-content/themes/your-theme/havenlytics/search/ajaxload-more.php
 * 3. Modify the copied file to customize the load more button display
 * 
 * @package     Havenlytics
 * @subpackage  Templates/search
 * @since       2.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $wp_query;

// Get current page number
$hvnly_current_page = max( 1, get_query_var( 'paged' ) );

// Get posts per page setting
$hvnly_per_page = $wp_query->get( 'posts_per_page' );

// Calculate how many properties have been loaded so far
$hvnly_loaded_count = min( $hvnly_current_page * $hvnly_per_page, $wp_query->found_posts );

// Get total number of pages
$hvnly_max_pages = $wp_query->max_num_pages;

// Determine if Load More button should be shown
$hvnly_show_load_more = $hvnly_max_pages > 1;

// Get custom button text from settings if available
$hvnly_load_more_text = __( 'Load More Properties', 'havenlytics' );
if ( function_exists( 'hvnly_get_ajax_load_more_button_text' ) ) {
    $hvnly_load_more_text = hvnly_get_ajax_load_more_button_text();
}

// Loading text shown while AJAX request is in progress
$hvnly_loading_text = __( 'Loading...', 'havenlytics' );

// Hide button if no more properties to load
$hvnly_load_more_style = ! $hvnly_show_load_more ? 'display: none;' : '';
?>

<!-- NO outer div wrapper - parent provides the container -->
<div class="hvnly-property-load-more-container" id="hvnly-load-more"
    style="<?php echo esc_attr( $hvnly_load_more_style ); ?>"
    data-load-more-text="<?php echo esc_attr( $hvnly_load_more_text ); ?>"
    data-loading-text="<?php echo esc_attr( $hvnly_loading_text ); ?>">
    <button class="hvnly-property-load-more-btn" id="hvnlyLoadMorePropertyBtn">
        <span class="hvnly-property-load-more-text"><?php echo esc_html( $hvnly_load_more_text ); ?></span>
        <i class="fas fa-plus"></i>
    </button>
    <?php hvnly_get_template_part( 'search/loaded-counter' ); ?>
</div>