<div class="tab-pane fade" id="pending-bookings" role="tabpanel" aria-labelledby="pending-bookings-tab">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-center flex-wrap mb-3 tab-content-container">
            <div class="tab-content-inner">
                <?php
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is for pagination display, not processing form data
                $paged = (get_query_var('paged')) && isset($_REQUEST['pending_booking']) ? get_query_var('paged') : 1;
                $per_page = 10; // You can set this to any number you want

                $wpbookit_data = array(
                    'status' => array('wpb-pending'),
                    'user_id' => $args['user_id'],
                    'paged' => $paged,
                    'per_page' => $per_page,
                );
   
                $wpbookit_bookings = wpbookit_get_bookings($wpbookit_data);
                $wpbookit_numResults = 0;
                if (!empty($wpbookit_bookings->results) && isset($wpbookit_bookings->results) && is_array($wpbookit_bookings->results)) {
                    $wpbookit_numResults = count($wpbookit_bookings->results);
                }
                if ($wpbookit_numResults === 0) {
                    return do_action('wpbookit_booking_no_pending_hook', $args);
                }
                ?>
                <h5><?php esc_html(sprintf("%d Pending %s", $wpbookit_numResults, _n("Booking", "Bookings", $wpbookit_numResults, 'wpbookit'))) ?>
                </h5>
                <p class="mb-0">
                    <?php esc_html_e('Your all pending bookings schedule is here. Check now!', 'wpbookit'); ?>
                </p>
            </div>
            
        </div>
        <div class="row">
            <?php
            if (!empty($wpbookit_bookings->results)):
                foreach ($wpbookit_bookings->results??[] as $wpbookit_bookingID => $wpbookit_booking):
                    $wpbookit_booking_name = $wpbookit_booking->get_booking_name();
                    $wpbookit_booking_id = $wpbookit_booking->get_id();
                    $wpbookit_booking_type = $wpbookit_booking->get_booking_type();
                    $wpbookit_btype_name = isset($wpbookit_booking_type["name"]) ? $wpbookit_booking_type["name"] : ''; ?>
                    <div class="col-lg-6" data-val="<?php echo esc_html($wpbookit_booking_id); ?>">
                        <div class="card bg-body">
                            <div class="card-body">
                                <div class="d-flex align-items-center justify-content-between mb-3">
                                    <h6 class="mb-0"><?php echo esc_html($wpbookit_btype_name); ?></h6>
                                    <button type="button" data-id="<?php echo esc_attr($wpbookit_booking_id); ?>" class="btn-close btn-close-icon-white booking-cancel-btn flex-shrink-0" style="display: inline-block;"></button>
                                </div>
                                <div class="d-flex align-items-center justify-content-between flex-wrap gap-3">
                                    <div>
                                        <div class="d-flex align-items-center gap-2 flex-wrap mb-2">
                                            <div class="d-inline-flex align-items-center gap-1">
                                                <img src="<?php echo esc_attr(IQWPB_PLUGIN_URL . "/core/shortcodes/assets/images/calender.svg"); // phpcs:ignore  PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage  ?>"
                                                    alt="checked">
                                                    
                                                <?php 
                                                $wpbookit_booking_date = $wpbookit_booking->get_booking_date();
                                                $wpbookit_booking_time = $wpbookit_booking->get_timeslot();
                                                $wpbookit_fbooking_date = wpbookit_get_formated_date_time($wpbookit_booking_date, $wpbookit_booking_time);
                                                $wpbookit_booking_time = $wpbookit_booking->get_timeslot();
                                                $wpbookit_booking_duration = $wpbookit_booking->get_meta('booking_duration');
                                                $wpbookit_booked_timestamp= strtotime($wpbookit_booking_date.' '.$wpbookit_booking_time);
    
                                                ?>
                                                <span class="title-text"><?php esc_html_e('Booking:','wpbookit'); ?></span>
                                            </div>
                                            <span id="booking_date" data-val="<?php echo esc_html($wpbookit_booking_date); ?>">
                                                <?php echo esc_html($wpbookit_fbooking_date); ?>
                                            </span>
                                        </div>
                                        <div class="d-flex align-items-center gap-2 flex-wrap">
                                            <div class="d-inline-flex align-items-center gap-1">
                                                <img src="<?php echo esc_attr(IQWPB_PLUGIN_URL . "/core/shortcodes/assets/images/subtotal-icon.svg"); // phpcs:ignore  PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage  ?>"
                                                    alt="checked">
                                                <span class="title-text"><?php esc_html_e('Total:', 'wpbookit'); ?></span>
                                            </div>
                                            <?php $wpbookit_booking_type_id = $wpbookit_booking->get_booking_type_id();
                                            $wpbookit_price = $wpbookit_booking->get_booking_price(); ?>
                                            <span class="text-primary fw-bold"><?php echo esc_html( $wpbookit_price ); ?></span>
                                        </div>
                                    </div>
                                    
                                    <add-to-calendar-button
                                        name="<?php echo esc_html($wpbookit_btype_name); ?>"
                                        startDate="<?php echo esc_html(date('Y-m-d', strtotime($wpbookit_booking_date))); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date ?>"
                                        startTime="<?php echo esc_html(date('H:i', strtotime($wpbookit_booking_time))); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date?>"
                                        endTime="<?php echo esc_html(date('H:i', strtotime('+' . $wpbookit_booking_duration . ' minutes', $wpbookit_booked_timestamp))); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date ?>"
                                        options="'Apple','Google','iCal','Microsoft365','Outlook.com','Yahoo'" 
                                        timeZone="<?php echo esc_attr(wp_timezone_string()); ?>"
                                        trigger="hover"
                                        label="Add to Calendar"  
                                        buttonStyle="default" 
                                        lightMode="bodyScheme"
                                        listStyle="dropdown"
                                        hideBackground='true'
                                        iCalFileName="<?php echo esc_html($wpbookit_btype_name); ?>"
                                        debug>
                                    </add-to-calendar-button>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
                <div>
                    <nav aria-label="Page navigation example">
                        <ul class="pagination">
                            <?php
                            $wpbookit_total_pages = ceil($wpbookit_bookings->total / $per_page); // Assuming $wpbookit_bookings->total gives the total number of bookings
                            // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is for pagination display, not processing form data
                            $wpbookit_current_page = max(1, isset($_REQUEST['pending_booking'])  ? get_query_var('paged') :1);
                            if ($wpbookit_current_page > 1) {
                                echo esc_html('<li class="page-item"><a class="page-link" href="' . wpbookit_clear_pagination_link( get_pagenum_link($wpbookit_current_page - 1),'pending_booking') . ' ">Previous</a></li>');
                            }

                            for ($wpbookit_i = 1; $wpbookit_i <= $wpbookit_total_pages && $wpbookit_total_pages>1; $wpbookit_i++) {
                                $wpbookit_active_class = ($wpbookit_i == $wpbookit_current_page) ? ' active' : '';
                                echo esc_html('<li class="page-item' . $wpbookit_active_class . '"><a class="page-link" href="' . wpbookit_clear_pagination_link(get_pagenum_link($wpbookit_i),'pending_booking')  . ' ">' . $wpbookit_i . '</a></li>');
                            }

                            if ($wpbookit_current_page < $wpbookit_total_pages) {
                                echo esc_html('<li class="page-item"><a class="page-link" href="' . wpbookit_clear_pagination_link(get_pagenum_link($wpbookit_current_page + 1),'pending_booking') . ' ">Next</a></li>');
                            }
                            ?>
                        </ul>
                    </nav>
                </div>
                <?php endif; ?>
        </div>
    </div>
</div>