<?php
$enable_main_banner_section = newsmarks_get_option('enable_main_banner_section');
$banner_list_post_title = newsmarks_get_option('banner_list_post_title');
$banner_list_post_category = newsmarks_get_option('banner_list_post_category');
$banner_grid_post_category = newsmarks_get_option('banner_grid_post_category');
$banner_column_advert = newsmarks_get_option('banner_column_advert');
$banner_column_advert_url = newsmarks_get_option('banner_column_advert_url');
$banner_tab_title_1 = newsmarks_get_option('banner_tab_title_1');
$banner_tab_category_1 = newsmarks_get_option('banner_tab_category_1');
$banner_tab_title_2 = newsmarks_get_option('banner_tab_title_2');
$banner_tab_category_2 = newsmarks_get_option('banner_tab_category_2');
$banner_tab_title_3 = newsmarks_get_option('banner_tab_title_3');
$banner_tab_category_3 = newsmarks_get_option('banner_tab_category_3');
$enable_banner_author_meta = newsmarks_get_option('enable_banner_author_meta');
$select_banner_author_meta = newsmarks_get_option('select_banner_author_meta');
$banner_author_meta_title = newsmarks_get_option('banner_author_meta_title');

$enable_banner_date_meta = newsmarks_get_option('enable_banner_date_meta');
$select_banner_date = newsmarks_get_option('select_banner_date');
$select_banner_date_meta_title = newsmarks_get_option('select_banner_date_meta_title');
$select_banner_date_format = newsmarks_get_option('select_banner_date_format');

$enable_banner_category_meta = newsmarks_get_option('enable_banner_category_meta');
$banner_category_label = newsmarks_get_option('banner_category_label');
$select_banner_category_color = newsmarks_get_option('select_banner_category_color');
$select_banner_number_of_category = newsmarks_get_option('select_banner_number_of_category');
if (empty($enable_main_banner_section)) {
    return;
}

?>
    <section class="wpi-section wpi-banner-section">
        <div class="wrapper">
            <div class="row-group">
                <div class="column-lg-6 column-md-12 column-sm-12 order-lg-2 border-lg-lr">
                    <?php
                    // post grid middle section
                    $post_grid_args = array(
                        'post_type' => 'post',
                        'posts_per_page' => 5,
                        'post_status' => 'publish',
                        'no_found_rows' => 1,
                        'ignore_sticky_posts' => 1,
                    );
                    // Check for category.
                    if (!empty($banner_grid_post_category)) :
                        $post_grid_args['tax_query'] = array(
                            array(
                                'taxonomy' => 'category',
                                'field' => 'term_id',
                                'terms' => $banner_grid_post_category,
                            ),
                        );
                    endif;
                    $counts = 1;
                    $grid_posts = new WP_Query($post_grid_args);
                    if ($grid_posts->have_posts()) :
                        while ($grid_posts->have_posts()) :
                            $grid_posts->the_post(); ?>
                            <?php
                            $image_class = "";
                            $title_class = "";
                            switch ($counts) {
                                case "1":
                                    $image_class = "entry-image-large";
                                    $title_class = "entry-title-big";
                                    break;
                                case "2":
                                    $image_class = "entry-image-medium";
                                    $title_class = "entry-title-medium";
                                    break;
                                case "3":
                                    $image_class = "entry-image-medium";
                                    $title_class = "entry-title-medium";
                                    break;
                                default:
                                    $image_class = "entry-image-small";
                                    $title_class = "entry-title-medium";
                            }
                            ?>
                            <?php if ($counts == 1) {
                                echo "<div class='banner-center-top'>";
                            } ?>
                            <?php if ($counts <= 3) { ?>
                            <article id="banner-center-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-tile-post'); ?>>
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="entry-image <?php echo esc_attr($image_class); ?> image-hover-effect hover-effect-shine">
                                        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"
                                           tabindex="-1">
                                            <?php
                                            the_post_thumbnail(
                                                'medium_large',
                                                array(
                                                    'alt' => the_title_attribute(
                                                        array(
                                                            'echo' => false,
                                                        )
                                                    ),
                                                )
                                            );
                                            ?>
                                        </a>
                                    </div>
                                <?php endif; ?>
                                <div class="entry-details">
                                    <?php
                                    if ($enable_banner_category_meta) {
                                        newsmarks_post_category($select_banner_category_color, $banner_category_label, $select_banner_number_of_category);
                                    }
                                    ?>
                                    <h3 class="entry-title <?php echo esc_attr($title_class); ?>">
                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="entry-meta-wrapper">

                                        <?php
                                        if ($enable_banner_date_meta) {
                                            newsmarks_posted_on($select_banner_date_format, $select_banner_date_meta_title, $select_banner_date);
                                        }
                                        ?>

                                        <?php
                                        if ($enable_banner_author_meta) {
                                            newsmarks_posted_by($select_banner_author_meta, $banner_author_meta_title);
                                        }
                                        ?>

                                    </div>
                                </div>
                            </article>
                            <?php $counts++;

                             if (($grid_posts->current_post + 1 == $grid_posts->post_count) || $counts == 4) {
                                echo "</div>";
                            }
                        } else { ?>
                            <article id="banner-center-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-post-list wpi-post-list-reverse'); ?>>
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="entry-image <?php echo esc_attr($image_class); ?> image-hover-effect hover-effect-shine">
                                        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"
                                           tabindex="-1">
                                            <?php
                                            the_post_thumbnail(
                                                'medium',
                                                array(
                                                    'alt' => the_title_attribute(
                                                        array(
                                                            'echo' => false,
                                                        )
                                                    ),
                                                )
                                            );
                                            ?>
                                        </a>
                                    </div>
                                <?php endif; ?>
                                <div class="entry-details">
                                    <?php
                                    if ($enable_banner_category_meta) {
                                        newsmarks_post_category($select_banner_category_color, $banner_category_label, $select_banner_number_of_category);
                                    }
                                    ?>
                                    <h3 class="entry-title <?php echo esc_attr($title_class); ?>">
                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="entry-meta-wrapper">

                                        <?php
                                        if ($enable_banner_date_meta) {
                                            newsmarks_posted_on($select_banner_date_format, $select_banner_date_meta_title, $select_banner_date);
                                        }
                                        ?>

                                        <?php
                                        if ($enable_banner_author_meta) {
                                            newsmarks_posted_by($select_banner_author_meta, $banner_author_meta_title);
                                        }
                                        ?>

                                    </div>
                                </div>
                            </article>
                        <?php } ?>
                        <?php
                        endwhile;
                        wp_reset_postdata();
                    endif; ?>
                </div>
                <div class="column-lg-3 column-md-6 column-sm-12 order-lg-1">
                    <?php
                    // post list middle section
                    $post_list_args = array(
                        'post_type' => 'post',
                        'posts_per_page' => 5,
                        'post_status' => 'publish',
                        'no_found_rows' => 1,
                        'ignore_sticky_posts' => 1,
                    );
                    // Check for category.
                    if (!empty($banner_list_post_category)) :
                        $post_list_args['tax_query'] = array(
                            array(
                                'taxonomy' => 'category',
                                'field' => 'term_id',
                                'terms' => $banner_list_post_category,
                            ),
                        );
                    endif;
                    $count = 1;
                    $list_posts = new WP_Query($post_list_args); ?>

                    <header class="wpi-section-header">
                        <h2 class="section-header-title">
                            <?php echo esc_html($banner_list_post_title); ?>
                        </h2>
                    </header>

                    <?php
                    if ($list_posts->have_posts()) :
                        while ($list_posts->have_posts()) :
                            $list_posts->the_post(); ?>
                            <?php if ($count == 1) { ?>
                            <article id="banner-left-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-post-default wpi-post-prime'); ?>>
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="entry-image entry-image-medium image-hover-effect hover-effect-shine">
                                        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true"
                                           tabindex="-1">
                                            <?php
                                            the_post_thumbnail(
                                                'medium',
                                                array(
                                                    'alt' => the_title_attribute(
                                                        array(
                                                            'echo' => false,
                                                        )
                                                    ),
                                                )
                                            );
                                            ?>
                                        </a>
                                    </div>
                                <?php endif; ?>
                                <div class="entry-details">
                                    <?php
                                    if ($enable_banner_category_meta) {
                                        newsmarks_post_category($select_banner_category_color, $banner_category_label, $select_banner_number_of_category);
                                    }
                                    ?>
                                    <h3 class="entry-title entry-title-medium">
                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="entry-meta-wrapper">

                                        <?php
                                        if ($enable_banner_date_meta) {
                                            newsmarks_posted_on($select_banner_date_format, $select_banner_date_meta_title, $select_banner_date);
                                        }
                                        ?>

                                        <?php
                                        if ($enable_banner_author_meta) {
                                            newsmarks_posted_by($select_banner_author_meta, $banner_author_meta_title);
                                        }
                                        ?>

                                    </div>
                                </div>
                            </article>
                            <?php $count++;
                        } else { ?>
                            <article id="banner-left-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-post-list'); ?>>
                                <?php if (has_post_thumbnail()) : ?>
                                    <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-zoom">
                                        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                                            <?php
                                            the_post_thumbnail(
                                                'medium',
                                                array(
                                                    'alt' => the_title_attribute(
                                                        array(
                                                            'echo' => false,
                                                        )
                                                    ),
                                                )
                                            );
                                            ?>
                                        </a>
                                    </div>
                                <?php endif; ?>
                                <div class="entry-details">
                                    <?php
                                    if ($enable_banner_category_meta) {
                                        newsmarks_post_category($select_banner_category_color, $banner_category_label, $select_banner_number_of_category);
                                    }
                                    ?>
                                    <h3 class="entry-title entry-title-small">
                                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h3>
                                    <div class="entry-meta-wrapper">

                                        <?php
                                        if ($enable_banner_date_meta) {
                                            newsmarks_posted_on($select_banner_date_format, $select_banner_date_meta_title, $select_banner_date);
                                        }
                                        ?>

                                        <?php
                                        if ($enable_banner_author_meta) {
                                            newsmarks_posted_by($select_banner_author_meta, $banner_author_meta_title);
                                        }
                                        ?>

                                    </div>
                                </div>
                            </article>
                        <?php } ?>
                        <?php
                        endwhile;
                        wp_reset_postdata();
                    endif;
                    ?>
                </div>
                <div class="column-lg-3 column-md-6 column-sm-12 order-lg-3">
                    <?php if (!empty($banner_column_advert)) { ?>
                        <div class="wpi-banner-promote">
                            <a href="<?php echo esc_url($banner_column_advert_url); ?>" class="wpi-promote-center" target="_blank">
                                <img src="<?php echo esc_url($banner_column_advert); ?>">
                            </a>
                        </div>
                    <?php } ?>

                    <div class="wpi-tabbed-widget">
                        <ul class="tabbed-widget-header reset-list-style" role="tablist" aria-label="<?php esc_attr_e('Tab Navigation', 'newsmarks'); ?>">
                            <li tab-data="banner-tab-1" class="header-tab-1 tabbed-header-item active">
                                <a href="javascript:void(0)" aria-controls="banner-tab-1-block" role="tab">
                                    <?php echo esc_html(newsmarks_get_option('banner_tab_title_1')); ?>
                                </a>
                            </li>

                            <li tab-data="banner-tab-2" class="header-tab-2 tabbed-header-item">
                                <a href="javascript:void(0)" aria-controls="banner-tab-2-block" role="tab">
                                    <?php echo esc_html(newsmarks_get_option('banner_tab_title_2')); ?>
                                </a>
                            </li>

                            <li tab-data="banner-tab-3" class="header-tab-3 tabbed-header-item">
                                <a href="javascript:void(0)" aria-controls="banner-tab-3-block" role="tab">
                                    <?php echo esc_html(newsmarks_get_option('banner_tab_title_3')); ?>
                                </a>
                            </li>
                        </ul>
                        <div class="tabbed-widget-content">
                            <div id="banner-tab-1-block" class="content-banner-tab-1 tabbed-content-item wpi-widget-list active" role="tabpanel">
                                <?php
                                $banner_tab_category = newsmarks_get_option('banner_tab_category_1');
                                newsmarks_get_tab_content($banner_tab_category); ?>
                            </div>
                            <div id="banner-tab-2-block" class="content-banner-tab-2 tabbed-content-item wpi-widget-list" role="tabpanel">
                                <?php
                                $banner_tab_category = newsmarks_get_option('banner_tab_category_2');
                                newsmarks_get_tab_content($banner_tab_category); ?>
                            </div>
                            <div id="banner-tab-3-block" class="content-banner-tab-3 tabbed-content-item wpi-widget-list" role="tabpanel">
                                <?php
                                $banner_tab_category = newsmarks_get_option('banner_tab_category_3');
                                newsmarks_get_tab_content($banner_tab_category); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php
function newsmarks_get_tab_content($banner_tab_category)
{
    $enable_banner_author_meta = newsmarks_get_option('enable_banner_author_meta');
    $select_banner_author_meta = newsmarks_get_option('select_banner_author_meta');
    $banner_author_meta_title = newsmarks_get_option('banner_author_meta_title');

    $enable_banner_date_meta = newsmarks_get_option('enable_banner_date_meta');
    $select_banner_date = newsmarks_get_option('select_banner_date');
    $select_banner_date_meta_title = newsmarks_get_option('select_banner_date_meta_title');
    $select_banner_date_format = newsmarks_get_option('select_banner_date_format');

    $enable_banner_category_meta = newsmarks_get_option('enable_banner_category_meta');
    $banner_category_label = newsmarks_get_option('banner_category_label');
    $select_banner_category_color = newsmarks_get_option('select_banner_category_color');
    $select_banner_number_of_category = newsmarks_get_option('select_banner_number_of_category');

    // post grid middle section
    $post_tab_args = array(
        'post_type' => 'post',
        'posts_per_page' => 6,
        'post_status' => 'publish',
        'no_found_rows' => 1,
        'ignore_sticky_posts' => 1,
    );
    // Check for category.
    if (!empty($banner_tab_category)) :
        $post_tab_args['tax_query'] = array(
            array(
                'taxonomy' => 'category',
                'field' => 'term_id',
                'terms' => $banner_tab_category,
            ),
        );
    endif;
    $tab_posts = new WP_Query($post_tab_args);
    if ($tab_posts->have_posts()) :
        while ($tab_posts->have_posts()) :
            $tab_posts->the_post(); ?>
            <article id="popular-post-<?php the_ID(); ?>" <?php post_class('wpi-post wpi-post-list'); ?>>
                <?php if (has_post_thumbnail()) : ?>
                    <div class="entry-image entry-image-thumbnail image-hover-effect hover-effect-slide">
                        <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
                            <?php
                            the_post_thumbnail(
                                'medium',
                                array(
                                    'alt' => the_title_attribute(
                                        array(
                                            'echo' => false,
                                        )
                                    ),
                                )
                            );
                            ?>
                        </a>
                    </div>
                <?php endif; ?>
                <div class="entry-details">
                    <?php
                    if ($enable_banner_category_meta) {
                        newsmarks_post_category($select_banner_category_color, $banner_category_label, $select_banner_number_of_category);
                    }
                    ?>
                    <h3 class="entry-title entry-title-small">
                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    </h3>
                    <div class="entry-meta-wrapper">
                        <?php
                        if ($enable_banner_date_meta) {
                            newsmarks_posted_on($select_banner_date_format, $select_banner_date_meta_title, $select_banner_date);
                        }
                        ?>

                        <?php
                        if ($enable_banner_author_meta) {
                            newsmarks_posted_by($select_banner_author_meta, $banner_author_meta_title);
                        }
                        ?>
                    </div>
                </div>
            </article>
        <?php
        endwhile;
        wp_reset_postdata();
    endif;
}