<?php

namespace MovieEngine\Admin\Design\Tabs;

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

class PaginationTab {

    public static function render($options, $standalone = true) {
        $items_per_page = isset($options['archive_items_per_page']) ? intval($options['archive_items_per_page']) : 20;
        $search_items_per_page = isset($options['search_items_per_page']) ? intval($options['search_items_per_page']) : 20;
        $pagination_type = isset($options['pagination_type']) ? $options['pagination_type'] : 'numbers';
?>
        <?php if ($standalone) : ?>
            <input type="hidden" name="movie_engine_design_settings[active_sub_tab]" value="pagination">
        <?php endif; ?>
        <div class="movie-engine-settings-modern">
            <div class="movie-engine-section-intro me-px-3 me-pt-4 me-pb-3 me-border-bottom">
                <h3><?php esc_html_e('Pagination Settings', 'cine-movie-engine'); ?></h3>
                <p><?php esc_html_e('Control how many items appear on your pages and how users navigate through them.', 'cine-movie-engine'); ?></p>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Global Items Per Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <input class="movie-engine-input-modern" type="number" name="movie_engine_design_settings[archive_items_per_page]" value="<?php echo esc_attr($items_per_page); ?>" class="regular-text" min="1" max="100" />
                    <p class="description"><?php esc_html_e('Default number of movies/episodes to show on archive pages (Genre, Year, All Movies).', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Search Results Per Page', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <input class="movie-engine-input-modern" type="number" name="movie_engine_design_settings[search_items_per_page]" value="<?php echo esc_attr($search_items_per_page); ?>" class="regular-text" min="1" max="100" />
                    <p class="description"><?php esc_html_e('Number of results to show on the search results page.', 'cine-movie-engine'); ?></p>
                </div>
            </div>

            <div class="movie-engine-setting-row">
                <div class="movie-engine-row-label">
                    <h4><?php esc_html_e('Pagination Style', 'cine-movie-engine'); ?></h4>
                </div>
                <div class="movie-engine-row-control">
                    <?php $is_pro = apply_filters('movie_engine_is_pro', false); ?>
                    <select name="movie_engine_design_settings[pagination_type]" class="movie-engine-select-modern">
                        <option value="numbers" <?php selected($pagination_type, 'numbers'); ?>><?php esc_html_e('Standard Numbers (1 2 3 Next)', 'cine-movie-engine'); ?></option>
                        <option value="load_more" <?php selected($pagination_type, 'load_more'); ?> <?php disabled(!$is_pro); ?>>
                            <?php esc_html_e('Load More Button (AJAX)', 'cine-movie-engine');
                            echo $is_pro ? '' : ' (Pro)'; ?>
                        </option>
                        <option value="infinite" <?php selected($pagination_type, 'infinite'); ?> <?php disabled(!$is_pro); ?>>
                            <?php esc_html_e('Infinite Scroll', 'cine-movie-engine');
                            echo $is_pro ? '' : ' (Pro)'; ?>
                        </option>
                    </select>
                    <p class="description">
                        <?php esc_html_e('Choose how you want users to load more content.', 'cine-movie-engine'); ?>
                        <?php if (!$is_pro) : ?>
                            <a href="<?php echo esc_url(\MovieEngine\Admin\Upgrade::get_pro_url('pricing')); ?>" target="_blank" style="color: #e50914; text-decoration: none; font-weight: 500;">
                                <?php esc_html_e('Upgrade to Pro for AJAX Load More & Infinite Scroll.', 'cine-movie-engine'); ?>
                            </a>
                        <?php endif; ?>
                    </p>
                </div>
            </div>
        </div>
<?php
    }
}
