<?php

add_shortcode('mostrar_banners', 'carregar_banners');
function carregar_banners()
{

    //"assets/js/owl.carousel.min.js"

    wp_enqueue_script('wpos-slick-jquery');
    global $post;
    ob_start();
    // WP Query Parameters
    $args = array(
        'post_type' => 'banners',
        'post_status' => array('publish')
    );

    $query = new WP_Query($args);
    $post_count = $query->post_count;
    if ($query->have_posts()) :
        $indice = 0;
        ?>

        <section id="banner2">


            <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
                <!-- Wrapper for slides -->

                <ol class="carousel-indicators">
                    <?php $i = 0; ?>
                    <?php while ($query->have_posts()) : $query->the_post(); ?>
                        <li data-target="#carousel-example-generic" data-slide-to="<?= $i ?>"
                            class="<?= $i == 0 ? 'active' : ''; ?>"></li>
                        <?php $i++; endwhile; ?>
                </ol>


                <div class="carousel-inner">

                    <?php while ($query->have_posts()) : $query->the_post();

                        $titulo = get_the_title();
                        $descricao = get_the_content();
                        $newBlank = get_post_meta(get_the_ID(), 'alt_banner_nova_guia', true) == 'sim' ? '_blank' : '_parent';
                        $url_imagem = get_post_meta(get_the_ID(), 'alt_banner_imagem', true) ?? null;

                        $url_video = get_post_meta(get_the_ID(), 'alt_banner_video', true) ?? null;
                        $link = get_post_meta(get_the_ID(), 'alt_banner_link', true) ?? null;
                        $exibir_texto = get_post_meta(get_the_ID(), 'alt_banner_exibir_texto', true) ?? false;

                        if (empty($url_imagem)) {
                            continue;
                        }


                        include('template/banner_slides.php');


                        $indice++;
                    endwhile;
                    ?>

                </div>

                <!-- Controls -->
                <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
                    <div class="icon-prev"></div>
                </a>
                <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
                    <div class="icon-next"></div>
                </a>
            </div>

        </section>


    <?php

    endif;
    wp_reset_query();
    return ob_get_clean();


}
