<div class="tab-pane fade" id="booking-history" role="tabpanel" aria-labelledby="bookings-history-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
                $wpbookit_paged = (get_query_var('paged')) && isset($_REQUEST['history_booking']) ? get_query_var('paged') : 1;
                $wpbookit_per_page = 10; // You can set this to any number you want

                $wpbookit_data = array(
                    'status' => array('wpb-completed'),
                    'user_id' => $args['user_id'],
                    'paged' => $wpbookit_paged,
                    'per_page' => $wpbookit_per_page,
                );

             
                $wpbookit_bookings = wpbookit_get_bookings($wpbookit_data);
                $wpbookit_num_results = 0;
                if (!empty($wpbookit_bookings->results) && isset($wpbookit_bookings->results) && is_array($wpbookit_bookings->results)) {
                    $wpbookit_num_results = count($wpbookit_bookings->results);
                }
                if ($wpbookit_num_results === 0) {
                    return do_action('wpbookit_booking_no_history_hook' , $args);
                } ?>

                <h5><?php 
                // translators: Booking Label in singular or plural placeholder:0, Number of Booking placeholder:1
                esc_html(sprintf(esc_html__("%1\$d Completed %2\$s",'wpbookit'), $wpbookit_num_results, _n("Booking", "Bookings", $wpbookit_num_results, 'wpbookit'))) ?>
                </h5>
                <p class="mb-0">
                    <?php esc_html_e('Your all Completed 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_booking_id => $wpbookit_booking):
                    $wpbookit_booking_name = $wpbookit_booking->get_booking_name();
                    $wpbookit_booking_id_val = $wpbookit_booking->get_id();
                    $wpbookit_booking_type = $wpbookit_booking->get_booking_type();
                    $wpbookit_btype_name = isset($wpbookit_booking_type["name"]) ? $wpbookit_booking_type["name"] : ''; 
                    $wpbookit_booking_date = $wpbookit_booking->get_booking_date();
                    $wpbookit_booking_time = $wpbookit_booking->get_timeslot();
                    $wpbookit_booked_timestamp = strtotime($wpbookit_booking_date.' '.$wpbookit_booking_time);
                    ?>
                    <div class="col-lg-6" data-val="<?php echo esc_attr($wpbookit_booking_id_val); ?>">
                        <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>
                                </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_inner = $wpbookit_booking->get_booking_date();
                                                $wpbookit_booking_time_inner = $wpbookit_booking->get_timeslot();
                                                $wpbookit_fbooking_date = wpbookit_get_formated_date_time($wpbookit_booking_date_inner, $wpbookit_booking_time_inner);
                                                $wpbookit_booking_duration = $wpbookit_booking->get_meta('booking_duration'); ?>
                                                <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_inner); ?>">
                                                <?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_inner))); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date ?>"
                                        startTime="<?php echo esc_html(date('H:i', strtotime($wpbookit_booking_time_inner))); // 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>
                                    <?php do_action('wpbookit_after_calendar_button', $wpbookit_booking); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endforeach;?>
                <div>
                    <nav aria-label="Page navigation example">
                        <ul class="pagination">
                            <?php
                            $wpbookit_total_pages = ceil($wpbookit_bookings->total / $wpbookit_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['history_booking'])  ? get_query_var('paged') :1);

                            if ($wpbookit_current_page > 1) {
                                echo wp_kses_post('<li class="page-item"><a class="page-link" href="' . wpbookit_clear_pagination_link( get_pagenum_link($wpbookit_current_page - 1),'history_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 wp_kses_post('<li class="page-item' . $wpbookit_active_class . '"><a class="page-link" href="' . wpbookit_clear_pagination_link(get_pagenum_link($wpbookit_i),'history_booking')  . ' ">' . $wpbookit_i . '</a></li>');
                            }

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