<?php
/**
 * Template: Tour Destination Archive
 */
// Don't load directly
defined( 'ABSPATH' ) || exit;

use Tourfic\App\Templates\Components\Shared\Archive\Banner;
use \Tourfic\Classes\Helper;

 if(wp_is_block_theme()){
    wp_head();
    block_header_area();
}else{
    get_header();
}

if ( !Helper::tf_is_woo_active() ) {
	?>
    <div class="tf-container">
        <div class="tf-notice tf-notice-danger">
			<?php esc_html_e( 'Please install and activate WooCommerce plugin to use this feature.', 'tourfic' ); ?>
        </div>
    </div>
	<?php
	get_footer();
	return;
}

$term = get_queried_object();
$post_type = 'tf_tours';
$taxonomy = $term->taxonomy;
$taxonomy_name = $term->name;
$taxonomy_slug = $term->slug;
$max = '2';

$tf_tour_arc_selected_template = ! empty( Helper::tf_data_types(Helper::tfopt( 'tf-template' ))['tour-archive'] ) ?  Helper::tf_data_types(Helper::tfopt( 'tf-template' ))['tour-archive'] : 'design-1';

if( $post_type == "tf_tours" && $tf_tour_arc_selected_template=="design-1" ){
?>
<div class="tf-archive-page tf-archive-design-1 tf-archive-template__one">
    <div class="tf-container">
		<h3><?php echo esc_html($taxonomy_name); ?></h3>
        <div class="tf-row tf-archive-inner tf-flex">
		<?php require_once TF_TEMPLATE_PART_PATH . 'archive.php'; ?>
		<!-- SideBar-->
		<div class="tf-sidebar tf-archive-right">
			<?php 
            if($taxonomy == 'tour_destination'){
                Helper::tf_archive_sidebar_search_form($post_type, $taxonomy, $taxonomy_name, $taxonomy_slug);
            } else {
                Helper::tf_archive_sidebar_search_form($post_type, '', '', '');
            }
            ?>
		</div>
		</div>
	</div>
</div>
<?php } elseif( $post_type == "tf_tours" && $tf_tour_arc_selected_template=="design-2" ){ ?>

<div class="tf-archive-template__two">
    <?php Banner::render(); ?>

    <!--Content section end -->
    <div class="tf-content-wrapper">
        <div class="tf-container">

            <!-- Hotel details Srart -->
            <div class="tf-archive-details tf-details" id="tf-hotel-overview">

                <div class="tf-details-left tf-result-previews">
                    <span class="tf-modify-search-btn">
                        <?php esc_html_e("Modify search", "tourfic"); ?>
                    </span>
                    <?php 
                    if($taxonomy == 'tour_destination'){
                        Helper::tf_archive_sidebar_search_form($post_type, $taxonomy, $taxonomy_name, $taxonomy_slug);
                    } else {
                        Helper::tf_archive_sidebar_search_form($post_type, '', '', '');
                    }
                    ?>
					<?php require_once TF_TEMPLATE_PART_PATH . 'archive.php'; ?>
                </div>
                <div class="tf-details-right tf-sitebar-widgets tf-archive-right">
                    <div class="tf-filter-wrapper">
                        <div class="tf-close-sidebar">
                            <i class="fa-solid fa-xmark"></i>
                        </div>
                        <div class="tf-filter-title">
                            <h2 class="tf-section-title"><?php esc_html_e("Filter", "tourfic"); ?></h2>
                            <button class="filter-reset-btn"><?php esc_html_e("Reset", "tourfic"); ?></button>
                        </div>
                        <?php if ( is_active_sidebar( 'tf_archive_booking_sidebar' ) ) { ?>
                        <div id="tf__booking_sidebar">
                            <?php dynamic_sidebar( 'tf_archive_booking_sidebar' ); ?>
                        </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
            <!-- Hotel details End -->

        </div>
    </div>
    <!--Content section end -->

    <!-- Hotel PopUp Starts -->
    <div class="tf-popup-wrapper tf-hotel-popup">
        <div class="tf-popup-inner">
            <div class="tf-popup-body">

            </div>
            <div class="tf-popup-close">
                <i class="fa-solid fa-xmark"></i>
            </div>
        </div>
    </div>
    <!-- Hotel PopUp end -->
</div>

<?php } elseif( $post_type == "tf_tours" && $tf_tour_arc_selected_template=="design-3" ){ ?>
    <div class="tf-archive-template__three">

        <div class="tf-content-wrapper">
            <?php
            do_action('tf_before_container');
            $post_count = $GLOBALS['wp_query']->post_count;
            $tf_map_settings = !empty(Helper::tfopt('google-page-option')) ? Helper::tfopt('google-page-option') : "default";
            $tf_map_api = !empty(Helper::tfopt('tf-googlemapapi')) ? Helper::tfopt('tf-googlemapapi') : '';
            ?>

            <div class="tf-archive-search-form tf-booking-form-wrapper">
                <div class="tf-container">                    
                    <?php 
                    if($taxonomy == 'tour_destination'){
                        Helper::tf_archive_sidebar_search_form($post_type, $taxonomy, $taxonomy_name, $taxonomy_slug);
                    } else {
                        Helper::tf_archive_sidebar_search_form($post_type, '', '', '');
                    }
                    ?>
                </div>
            </div>

            <?php require_once TF_TEMPLATE_PART_PATH . 'archive.php'; ?>
        </div>
        <!--Content section end -->

    </div>

<?php } else{ ?>
<div class="tf-main-wrapper tf-archive-template__legacy" data-fullwidth="true">
	<?php do_action( 'tf_before_container' ); ?>
	<div class="tf-container">
		<h3><?php echo esc_html($taxonomy_name); ?></h3>
		<div class="search-result-inner">
			<div class="tf-search-left">
				<?php require_once TF_TEMPLATE_PART_PATH . 'archive.php'; ?>
			</div>

			<div class="tf-search-right">
				<?php 
                if($taxonomy == 'tour_destination'){
                    Helper::tf_archive_sidebar_search_form($post_type, $taxonomy, $taxonomy_name, $taxonomy_slug);
                } else {
                    Helper::tf_archive_sidebar_search_form($post_type, '', '', '');
                }
                ?>
                <?php if ( is_active_sidebar( 'tf_archive_booking_sidebar' ) ) { ?>
                    <div id="tf__booking_sidebar">
                        <?php dynamic_sidebar( 'tf_archive_booking_sidebar' ); ?>
                    </div>
                <?php } ?>
            </div>
		</div>
	</div>
	<?php do_action( 'tf_after_container' ); ?>
</div>
<?php
}

if(wp_is_block_theme()){
    wp_footer();
    block_footer_area();
 }else{
	get_footer('tourfic');
 }