<?php defined('ABSPATH') or die('No script kiddies please!'); ?>
<div class="wpwab-field-wrap wpwab-field-page" >
    <label><?php _e('Select Page', wpwab_TD); ?></label>
    <div class="wpwab-field">
        <div id="wpwab_page_content">
            <?php
            $current_page = intval($_POST['page_num']);
            $limit = 10;
            $args = array(
                'post_type' => 'page',
                'posts_per_page' => $limit,
                'order' => 'DESC',
                'orderby' => 'ID',
                'paged' => $current_page
            );
            
            $query = new WP_Query($args);
            $selected_pages = (!empty($_POST['selected_pages'])) ? explode(',', $_POST['selected_pages']) : array();
            $rowCount = $query->found_posts;


            //Initialize Pagination class and create object
            $url = wpwab_URL . 'inc/backend/pagination/wpwab-getpaginatepage.php';

            $pagConfig = array('baseURL' => $url, 'select_type' => $select_type, 'totalRows' => $rowCount, 'perPage' => $limit, 'contentDiv' => 'wpwab_page_content', 'anchorClass' => 'wpwab-page-trigger', 'currentPage' => $current_page);
            $pagination = new wpwab_Pagination($pagConfig);
            //Get rows
            if ($rowCount > 0) {
                ?>
                <div class="wpwab-posts-list">
                    <?php
                    while ($query->have_posts()) : $query->the_post();
                        $page_id = get_the_ID();
                        $specific_page = (!empty($wpwab_settings['specific_page'])) ? $wpwab_settings['specific_page'] : array();
                        ?>
                        <div class="wpwab-list-item">
                            <label>
                                <input type="checkbox" id="wpwab-page-<?php esc_attr_e($page_id); ?>"
                                       value="<?php esc_attr_e($page_id); ?>" <?php echo (in_array($page_id, $selected_pages)) ? 'checked="checked"' : ''; ?> 
                                       data-postname="<?php the_title(); ?>" class="wpwab-pagecheckbox" /><?php the_title(); ?>
                            </label>
                        </div>
                    <?php endwhile; ?>
                </div>

                <?php
                echo $pagination->createLinks();
                ?>
                <?php
            } else {
                _e('Posts not found.', wpwab_TD);
            }
            ?>
        </div>
    </div>
</div>

