<?php
/**
 * Banner Blocks One
 *
 * @package Vintuna
 */
if (!function_exists('vintuna_banner_block_1_section')) :
    function vintuna_banner_block_1_section($vintuna_home_section, $repeat_times)
    {
        $section_post_tab_list_cat = esc_html(isset($vintuna_home_section->section_post_tab_list_cat) ? $vintuna_home_section->section_post_tab_list_cat : '');
        $section_post_tab_list_cat_2 = esc_html(isset($vintuna_home_section->section_post_tab_list_cat_2) ? $vintuna_home_section->section_post_tab_list_cat_2 : '');
        $section_post_offset_1 = esc_html(isset($vintuna_home_section->section_post_offset_1) ? $vintuna_home_section->section_post_offset_1 : '');
        $section_post_offset = esc_html(isset($vintuna_home_section->section_post_offset) ? $vintuna_home_section->section_post_offset : '');
        $section_category_1 = esc_html(isset($vintuna_home_section->section_category_1) ? $vintuna_home_section->section_category_1 : '');
        $section_category_2 = esc_html(isset($vintuna_home_section->section_category_2) ? $vintuna_home_section->section_category_2 : '');
        $section_category_3 = esc_html(isset($vintuna_home_section->section_category_3) ? $vintuna_home_section->section_category_3 : '');
        $section_category_4 = esc_html(isset($vintuna_home_section->section_category_4) ? $vintuna_home_section->section_category_4 : '');
        $ed_tab = esc_html(isset($vintuna_home_section->ed_tab) ? $vintuna_home_section->ed_tab : '');
        $tab_section_title = esc_html(isset($vintuna_home_section->tab_section_title) ? $vintuna_home_section->tab_section_title : '');
        $banner_post_slide_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 5, 'offset' => $section_post_offset_1, 'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html($section_post_tab_list_cat)));
        $banner_post_slide_query_2 = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 8, 'offset' => $section_post_offset, 'post__not_in' => get_option("sticky_posts"), 'category_name' => esc_html($section_post_tab_list_cat_2)));
        if ($ed_tab == 'yes' && ($section_category_1 || $section_category_2 || $section_category_3 || $section_category_4)) {
            $cat_array = array();
            if ($section_category_1) {
                $cat_array[] = $section_category_1;
            }
            if ($section_category_2) {
                $cat_array[] = $section_category_2;
            }
            if ($section_category_3) {
                $cat_array[] = $section_category_3;
            }
            if ($section_category_4) {
                $cat_array[] = $section_category_4;
            }
            $banner_query_all = new WP_Query(
                $args = array(
                    'post_type' => 'post',
                    'posts_per_page' => 5,
                    'post__not_in' => get_option("sticky_posts"),
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'category',
                            'field' => 'slug',
                            'terms' => $cat_array,
                        ),
                    ),
                )
            );
        } else {
            $banner_query_all = new WP_Query(
                $args = array(
                    'post_type' => 'post',
                    'posts_per_page' => 5,
                    'post__not_in' => get_option("sticky_posts"),
                    'category_name' => esc_html($section_category_1)
                )
            );
        }
        ?>
        <div id="theme-block-<?php echo esc_attr($repeat_times); ?>" class="theme-block theme-block-navtabs <?php
        if ($ed_tab == 'no' && (empty($section_category_1) || empty($section_category_2) || empty($section_category_3) || empty($section_category_4))) {
            echo 'no-title-slide';
        } ?>">
            <div class="column-row">
                <div class="column column-8 column-md-12 mb-md-30">
                    <?php if ($tab_section_title) { ?>
                        <header class="theme-block-header">
                            <h2 class="theme-block-title">
                                <?php echo esc_html($tab_section_title); ?>
                            </h2>
                            <span class="block-title-dash"></span>
                        </header>
                    <?php } ?>
                    <div class="column-row">
                        <div class="column column-5 column-xs-12 mb-xs-20">
                            <?php if ($banner_post_slide_query->have_posts()) : ?>
                                <?php
                                while ($banner_post_slide_query->have_posts()) {
                                    $banner_post_slide_query->the_post();
                                    ?>
                                    <article id="theme-post-<?php the_ID(); ?>" <?php post_class('news-article news-article-list article-has-border'); ?>>

                                        <?php
                                        $fallback_image_url = vintuna_get_fallback_image_url();
                                        if (has_post_thumbnail() || $fallback_image_url) : ?>
                                            <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-shine">
                                                <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                                    <?php
                                                    if (has_post_thumbnail()) {
                                                        the_post_thumbnail('medium', [
                                                            'alt' => the_title_attribute(['echo' => false]),
                                                        ]);
                                                    } else {
                                                        echo '<img src="' . esc_url($fallback_image_url) . '" alt="' . esc_attr(get_the_title()) . '" />';
                                                    }
                                                    ?>
                                                </a>
                                            </div>
                                        <?php endif; ?>

                                        <div class="article-content">
                                            <h2 class="entry-title entry-title-xsmall line-clamp-3">
                                                <a href="<?php the_permalink(); ?>" tabindex="0" rel="bookmark"
                                                   title="<?php the_title_attribute(); ?>">
                                                    <?php the_title(); ?>
                                                </a>
                                            </h2>
                                            <div class="entry-footer">
                                                <div class="entry-meta">
                                                    <?php vintuna_posted_by(); ?>
                                                </div>
                                            </div>
                                        </div>
                                    </article>
                                <?php } ?>
                                <?php
                                wp_reset_postdata();
                            endif; ?>
                        </div>
                        <div class="column column-7 column-xs-12">
                            <div class="navtabs-middle-area">
                                <?php if ($banner_post_slide_query_2->have_posts()) : ?>
                                    <?php
                                    while ($banner_post_slide_query_2->have_posts()) {
                                        $banner_post_slide_query_2->the_post();
                                        ?>
                                        <article id="theme-post-<?php the_ID(); ?>" <?php post_class('news-article news-article-tiles'); ?>>
                                            <?php
                                            $fallback_image_url = vintuna_get_fallback_image_url();
                                            if (has_post_thumbnail() || $fallback_image_url) : ?>
                                                <div class="entry-image entry-image-small image-hover-effect hover-effect-shine entry-image-overlay image-overlay-gradient">
                                                    <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                                        <?php
                                                        if (has_post_thumbnail()) {
                                                            the_post_thumbnail('medium', [
                                                                'alt' => the_title_attribute(['echo' => false]),
                                                            ]);
                                                        } else {
                                                            echo '<img src="' . esc_url($fallback_image_url) . '" alt="' . esc_attr(get_the_title()) . '" />';
                                                        }
                                                        ?>
                                                    </a>
                                                </div>
                                            <?php endif; ?>

                                            <div class="article-content">
                                                <h2 class="entry-title entry-title-medium line-clamp-3">
                                                    <a href="<?php the_permalink(); ?>" tabindex="0" rel="bookmark"
                                                       title="<?php the_title_attribute(); ?>">
                                                        <?php the_title(); ?>
                                                    </a>
                                                </h2>
                                                <div class="entry-footer">
                                                    <div class="entry-meta">
                                                        <?php vintuna_posted_by(); ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </article>
                                    <?php } ?>
                                    <?php
                                    wp_reset_postdata();
                                endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="column column-4 column-md-12 column-sm-12">
                    <?php if (($ed_tab == 'yes' && ($section_category_1 || $section_category_2 || $section_category_3 || $section_category_4))) { ?>
                        <header class="theme-block-header">
                            <?php
                            if ($ed_tab == 'yes' && ($section_category_1 || $section_category_2 || $section_category_3 || $section_category_4)) { ?>
                                <div class="theme-tab-controls">
                                    <div class="tab-posts hide-no-js">
                                        <a cat-data="all" class="active-tab" href="javascript:void(0)"><?php esc_html_e('All', 'vintuna'); ?></a>
                                        <?php
                                        if ($section_category_1 && $ed_tab == 'yes') {
                                            $catObj = get_category_by_slug($section_category_1);
                                            if (isset($catObj->name) && $catObj->name) { ?>
                                                <a cat-data="<?php echo esc_attr($section_category_1); ?>"
                                                   href="javascript:void(0)">
                                                    <?php echo esc_html($catObj->name); ?>
                                                </a>
                                            <?php }
                                        }
                                        if ($section_category_2 && $ed_tab == 'yes') {
                                            $catObj = get_category_by_slug($section_category_2);
                                            if (isset($catObj->name) && $catObj->name) { ?>
                                                <a cat-data="<?php echo esc_attr($section_category_2); ?>"
                                                   href="javascript:void(0)">
                                                    <?php echo esc_html($catObj->name); ?>
                                                </a>
                                            <?php }
                                        }
                                        if ($section_category_3 && $ed_tab == 'yes') {
                                            $catObj = get_category_by_slug($section_category_3);
                                            if (isset($catObj->name) && $catObj->name) { ?>
                                                <a cat-data="<?php echo esc_attr($section_category_3); ?>"
                                                   href="javascript:void(0)">
                                                    <?php echo esc_html($catObj->name); ?>
                                                </a>
                                            <?php }
                                        }
                                        if ($section_category_4 && $ed_tab == 'yes') {
                                            $catObj = get_category_by_slug($section_category_4);
                                            if (isset($catObj->name) && $catObj->name) { ?>
                                                <a cat-data="<?php echo esc_attr($section_category_4); ?>"
                                                   href="javascript:void(0)">
                                                    <?php echo esc_html($catObj->name); ?>
                                                </a>
                                            <?php }
                                        } ?>
                                    </div>
                                </div>
                            <?php } ?>
                        </header>
                    <?php }
                    if ($banner_query_all->have_posts()) : ?>
                        <div class="tab-contents tab-content-all content-loaded content-active">
                            <div class="tab-content-container">
                                <?php
                                $post_count = 1;
                                while ($banner_query_all->have_posts()) {
                                    $banner_query_all->the_post();
                                    ?>
                                    <article id="theme-post-<?php the_ID(); ?>" <?php post_class('news-article news-article-list article-has-border'); ?>>
                                        <?php
                                        $fallback_image_url = vintuna_get_fallback_image_url();
                                        if (has_post_thumbnail() || $fallback_image_url) : ?>
                                            <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-shine">
                                                <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                                    <?php
                                                    if (has_post_thumbnail()) {
                                                        the_post_thumbnail('medium', [
                                                            'alt' => the_title_attribute(['echo' => false]),
                                                        ]);
                                                    } else {
                                                        echo '<img src="' . esc_url($fallback_image_url) . '" alt="' . esc_attr(get_the_title()) . '" />';
                                                    }
                                                    ?>
                                                </a>
                                            </div>
                                        <?php endif; ?>

                                        <div class="article-content">
                                            <h3 class="entry-title entry-title-xsmall line-clamp-2">
                                                <a href="<?php the_permalink(); ?>" tabindex="0" rel="bookmark"
                                                   title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                                            </h3>
                                            <div class="entry-meta">
                                                <?php vintuna_posted_by(); ?>
                                            </div>
                                        </div>
                                    </article>
                                    <?php
                                    if ($post_count == 5) {
                                        break;
                                    }
                                    $post_count++;
                                } ?>
                            </div>
                        </div>
                        <?php
                        wp_reset_postdata();
                    endif; ?>
                    <?php if ($ed_tab == 'yes' && $section_category_1) { ?>
                        <div data-cat="<?php echo esc_attr($section_category_1); ?>"
                             class="tab-contents tab-content-<?php echo esc_attr($section_category_1); ?>">
                            <?php vintuna_content_loading(); ?>
                        </div>
                    <?php } ?>
                    <?php if ($ed_tab == 'yes' && $section_category_2) { ?>
                        <div data-cat="<?php echo esc_attr($section_category_2); ?>"
                             class="tab-contents tab-content-<?php echo esc_attr($section_category_2); ?>">
                            <?php vintuna_content_loading(); ?>
                        </div>
                    <?php } ?>
                    <?php if ($ed_tab == 'yes' && $section_category_3) { ?>
                        <div data-cat="<?php echo esc_attr($section_category_3); ?>"
                             class="tab-contents tab-content-<?php echo esc_attr($section_category_3); ?>">
                            <?php vintuna_content_loading(); ?>
                        </div>
                    <?php } ?>
                    <?php if ($ed_tab == 'yes' && $section_category_4) { ?>
                        <div data-cat="<?php echo esc_attr($section_category_4); ?>"
                             class="tab-contents tab-content-<?php echo esc_attr($section_category_4); ?>">
                            <?php vintuna_content_loading(); ?>
                        </div>
                    <?php } ?>
                </div>

            </div>
        </div>
        <?php
    }
endif;
