<?php
/**
 * The Template Name: Home Page
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Shipping Company
 */

get_header(); ?>

<div id="content" >

    <?php
        $shipping_company_banner = get_theme_mod('shipping_company_banner', false);
        $shipping_company_banner_pageboxes = get_theme_mod('shipping_company_banner_pageboxes', false);

        if ($shipping_company_banner && $shipping_company_banner_pageboxes) { ?>
        <div id="banner-cat" class="position-relative">
            <div class="banner-page">
                <?php
                $shipping_company_querymed = new WP_Query(array(
                    'page_id' => esc_attr($shipping_company_banner_pageboxes)
                ));
                while ($shipping_company_querymed->have_posts()) : $shipping_company_querymed->the_post(); ?>
                    <div class="video-box">
                        <?php
                            $shipping_company_content = apply_filters('the_content', get_the_content());
                            $shipping_company_video = false;
                            if (false === strpos($shipping_company_content, 'wp-playlist-script')) {
                                $shipping_company_video = get_media_embedded_in_content($shipping_company_content, array('video', 'object', 'embed', 'iframe'));
                            }
                            if (!is_single()) {
                                if (!empty($shipping_company_video)) {
                                    foreach ($shipping_company_video as $shipping_company_video_html) {
                                        $shipping_company_video_html = str_replace('<video', '<video autoplay muted playsinline loop"', $shipping_company_video_html);
                                        $shipping_company_video_html = str_replace('controls', '', $shipping_company_video_html);
                                        echo '<div class="entry-video">' . $shipping_company_video_html . '</div>';
                                    }
                                } else {
                                    the_post_thumbnail();
                                }
                            }
                        ?>
                        <div class="container">
                            <div class="banner-main position-absolute text-center">
                                <h1 class="mb-4 text-capitalize banner-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                <?php
                                    $shipping_company_trimexcerpt = get_the_excerpt();
                                    $shipping_company_shortexcerpt = wp_trim_words($shipping_company_trimexcerpt, 38);
                                    echo '<p class="banner-content mb-4">' . esc_html($shipping_company_shortexcerpt) . '</p>';
                                ?>
                                <div class="bannerbtn">
                                    <?php
                                        $shipping_company_button_text = get_theme_mod('shipping_company_button_text', 'Get A Quote');
                                        $shipping_company_button_link_banner = esc_url(get_theme_mod('shipping_company_button_link_banner', get_permalink()));
                                        if ($shipping_company_button_text || !empty($shipping_company_button_link_banner)) { ?>
                                        <?php if ($shipping_company_button_text != '') { ?>
                                            <a href="<?php echo esc_url($shipping_company_button_link_banner); ?>" class="button">
                                                <?php echo esc_html($shipping_company_button_text); ?>
                                                <span class="screen-reader-text"><?php echo esc_html($shipping_company_button_text); ?></span>
                                            </a>
                                        <?php } ?>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                    wp_reset_postdata();
                ?>
            </div>
        </div>
    <?php } ?>

    <!-- Logistic Solution Section -->
    <?php 
        $shipping_company_hide_logistic_solution_section = get_theme_mod('shipping_company_disabled_logistic_solution_section', false);
        $shipping_company_catData = get_theme_mod('shipping_company_logistic_solution_cat', '0');
        if ($shipping_company_hide_logistic_solution_section) { ?>
        <section id="logistic-section" class="py-5 mb-5">
            <div class="container">
                <div class="blog-bx mb-2 text-center">
                    <?php if (get_theme_mod('shipping_company_logistic_solution_title')) { ?>
                        <h2 class="logistic-title pb-3 mt-1 text-capitalize"><?php echo esc_html(get_theme_mod('shipping_company_logistic_solution_title')); ?></h2>
                    <?php } ?>
                </div>
                <div class="tab_list mb-4">
                    <ul class="nav nav-tabs" role="tablist">
                        <?php 
                        for($shipping_company_i=1; $shipping_company_i<=6; $shipping_company_i++ ) {?>
                            <li class="nav-item text-center">
                                <?php if(get_theme_mod('shipping_company_logistic_tab_title'.$shipping_company_i)!=''){ ?>
                                    <a class="nav-link <?php echo ($shipping_company_i == 1) ? esc_attr('active') : ''; ?>" data-bs-toggle="tab" data-bs-target="<?php echo esc_attr('#logistic_tab' . $shipping_company_i); ?>" role="tab" aria-controls="<?php echo esc_attr('logistic_tab' . $shipping_company_i); ?>" aria-selected="<?php echo esc_attr($shipping_company_i == 1 ? 'true' : 'false'); ?>"><?php echo esc_html(get_theme_mod('shipping_company_logistic_tab_title'.$shipping_company_i)); ?></a>
                                <?php } ?>
                            </li>
                        <?php } ?>
                    </ul>
                </div>
                <div class="tab-content logistic_tab_content position-relative">
                    <?php 
                    for ($shipping_company_i = 1; $shipping_company_i <= 6; $shipping_company_i++) {
                        $shipping_company_category_name = get_theme_mod('shipping_company_posts_cat' . $shipping_company_i);

                        if (!empty($shipping_company_category_name)) { ?>
                            <div role="tabpanel" class="tab-pane <?php echo ($shipping_company_i == 1) ? 'active' : ''; ?>" id="logistic_tab<?php echo esc_attr($shipping_company_i); ?>">
                                <div class="owl-carousel">
                                    <?php
                                    $shipping_company_k = 1;
                                    $shipping_company_args = array(
                                        'post_type'      => 'post',
                                        'post_status'    => 'publish',
                                        'category_name'  => esc_html($shipping_company_category_name),
                                        'order'          => 'ASC'
                                    );  
                                    $shipping_company_query = new WP_Query($shipping_company_args); 

                                    if ($shipping_company_query->have_posts()) :  
                                        while ($shipping_company_query->have_posts()) : 
                                            $shipping_company_query->the_post(); 
                                    ?>
                                        <div class="post-items post-item<?php echo esc_attr($shipping_company_k); ?> mb-3">
                                            <div class="post-image">
                                                <?php
                                                if (has_post_thumbnail()) {
                                                    the_post_thumbnail('medium', array('class' => 'img-fluid'));
                                                } else {
                                                    echo '<img src="' . esc_url(get_template_directory_uri() . '/images/post-image.png') . '" alt="Default Image">';
                                                }
                                                ?>
                                            </div>
                                            <div class="post-content py-2 text-lg-start text-md-start text-center">
                                                <h3 class="post-title text-capitalize">
                                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                                </h3>
                                                <p class="post-excerpt">
                                                    <?php echo wp_trim_words(get_the_excerpt(), 15, '...'); ?>
                                                </p>
                                            </div>
                                        </div>
                                    <?php 
                                        $shipping_company_k++; 
                                        endwhile; 
                                    endif; 
                                    wp_reset_postdata();
                                    ?>
                                </div>
                            </div>
                        <?php }
                    } ?>
                </div>
                <?php if ( get_theme_mod('shipping_company_logistic_btn_text') || get_theme_mod('shipping_company_logistic_btn_url')) { ?> 
                    <div class="btn-box text-center">
                        <a href="<?php echo esc_url(get_theme_mod ('shipping_company_logistic_btn_url','')); ?>" class="text-capitalize"><?php echo esc_html(get_theme_mod ('shipping_company_logistic_btn_text','shipping-company')); ?></a>
                    </div>
                <?php }?>
            </div>
        </section>
    <?php } ?>
</div>
<?php get_footer(); ?>
