<?php
/**
 * Upcoming Tours View.
 *
 * @since 1.3.8
 * @package tripzzy
 */

namespace Tripzzy\Admin\Views;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

use Tripzzy\Admin\UpcomingToursListTable;

if ( ! class_exists( 'Tripzzy\Admin\Views\UpcomingToursView' ) ) {
	/**
	 * UpcomingToursView Class.
	 *
	 * @since 1.3.8
	 */
	class UpcomingToursView {

		/**
		 * Render the upcoming tours page.
		 */
		public static function render() {
			if ( ! class_exists( 'Tripzzy\Admin\UpcomingToursListTable' ) ) {
				require_once TRIPZZY_ABSPATH . 'inc/Admin/UpcomingToursListTable.php';
			}
			$table = new UpcomingToursListTable();
			$table->prepare_items();
			?>
			<div class="wrap">
				<form method="get">
					<div class="tripzzy-upcoming-tours-header">
						<div class="tripzzy-upcoming-tours-header-left">
							<h1 class="wp-heading-inline">
								<?php esc_html_e( 'Upcoming Tours', 'tripzzy' ); ?>
							</h1>
							<?php if ( 'detail' === $table->view_mode ) : ?>
								<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=tripzzy_booking&page=tripzzy-upcoming-tours' ) ); ?>" class="page-title-action">< <?php esc_html_e( 'Back to Summary', 'tripzzy' ); ?></a>
							<?php endif; ?>
						</div>
						<div class="tripzzy-upcoming-tours-header-right">
							
						<?php
						$current_filter = isset( $_GET['filter'] ) ? sanitize_text_field( $_GET['filter'] ) : 'all'; // phpcs:ignore
						$base_url       = admin_url( 'edit.php?post_type=tripzzy_booking&page=tripzzy-upcoming-tours' );
						$filters        = array(
							'all'        => __( 'All', 'tripzzy' ),
							'today'      => __( 'Today', 'tripzzy' ),
							'this-week'  => __( 'This Week', 'tripzzy' ),
							'this-month' => __( 'This Month', 'tripzzy' ),
						);
						?>
						<ul class="subsubsub">
							<?php
							$count = 0;
							foreach ( $filters as $key => $label ) {
								$count++; // phpcs:ignore
								$class     = $current_filter === $key ? 'current' : '';
								$url       = add_query_arg( 'filter', $key, $base_url );
								$separator = $count < count( $filters ) ? ' | ' : '';
								printf( '<li><a href="%s" class="%s">%s</a></li>', esc_url( $url ), esc_attr( $class ), esc_html( $label ) );
							}
							?>
						</ul>



						<input type="hidden" name="post_type" value="tripzzy_booking" />
						<input type="hidden" name="page" value="tripzzy-upcoming-tours" />
						<?php
						if ( 'detail' === $table->view_mode ) {
							?>
							<input type="hidden" name="trip_date" value="<?php echo esc_attr( $table->selected_date ); ?>" />
							<?php
						}
						// Preserve filter in search form.
						if ( 'all' !== $current_filter ) {
							?>
							<input type="hidden" name="filter" value="<?php echo esc_attr( $current_filter ); ?>" />
							<?php
						}

						$table->search_box( __( 'Search', 'tripzzy' ), 'search-id' );
						?>
						</div>

					</div>
					<?php $table->display(); ?>
				</form>
			</div>
			<?php
		}
	}
}
