<?php get_header(); ?>

	<div class="content inner single">
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
			<div id="post-<?php the_ID(); ?>" class="post">
            <section class="l-brands-welcome-new pt-md-4 pt-lg-5 pt-xl-5">
                <div class="container">
                    <div class="row">
                        <div class="col-md-5 col-lg-5">
                            <img class="c-logo-brand m-md-0" src="<?php echo get_field('logo_brand'); ?>" alt="<?php echo the_title(); ?>">
                            <h1 class="c-title text-md-left mt-2 mt-lg-1"><?php echo get_field('title_welcome'); ?></h1>
                            <div class="c-description mt-2 pb-3 pb-md-5 pb-lg-5 pb-xl-5">
                                <p><?php echo get_field('description_welcome'); ?></p>
                            </div>
                        </div>
                        <div class="col-md-7 col-lg-7">
                            <div class="c-image-single-brands">
                                <img src="<?php echo get_field('imagem_welcome'); ?>" alt="<?php echo get_field('title_welcome'); ?>">
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <section class="l-brands-luxury pb-2 pb-md-4 pb-lg-4 pt-md-5 pt-lg-5">
                <div class="container text-md-center">
                    <h2 class="c-title is-dark is-special"><?php echo get_field('title_luxury'); ?></h2>
                    <div class="c-description is-dark mw-945 mt-2">
                        <p><?php echo get_field('description_luxury'); ?></p>
                    </div>
                    <div class="c-awards mt-2 mt-lg-4">
                        <?php
                            $awards = get_field('awards');
                            foreach($awards as $award):
                                ?>
                                    <img class="c-awards__item" src="<?php echo $award["logo_awards"]; ?>" alt="<?php echo $award["title_awards"]; ?>">
                                <?php
                            endforeach;
                        ?>
                    </div>
                </div>
            </section>
            <?php
                    $brands = get_the_ID();

                    $args = array(
                        'post_type'      => 'post',
                        'posts_per_page' => 12,
                        'post_status' => 'publish',
                        'meta_key' => 'select_brand',
                        'meta_value' => $brands


                    );
                    $loop = new WP_Query( $args );


                    if ( $loop->have_posts() ):
                        ?>
            <section class="l-brands-news pt-3 pt-md-3 pt-xl-5 pb-1 pb-md-1 pb-xl-5">
                <div class="carousel-title d-flex justify-content-between align-items-center">
                    <h2 class="c-subtitle">In the News</h2>

                    <div class="d-none d-sm-flex">
                        <a href="javascript:;" class="c-btn-round js-carousel-default-prev" aria-label="Prev"><i class="icon icon-left-arrow"></i></a>
                        <a href="javascript:;" class="c-btn-round js-carousel-default-next" aria-label="Next"><i class="icon icon-right-arrow"></i></a>
                    </div>
                </div>
                <div class="c-carousel-default js-carousel-default owl-carousel">
                    <?php while ( $loop->have_posts() ) : $loop->the_post();?>
                            <?php
                                $categories = get_the_category();
                                $post_id = get_the_ID();
                                $imagefeatured = get_the_post_thumbnail_url($post_id,'full');
                                $imagefeaturedmobile = get_the_post_thumbnail_url($post_id, 'list-archive');
                                $format = get_post_format( $post_id );
                                if(!$format):
                                    $format = "article";
                                endif;
                            ?>
                        <article class="c-card-news">
                            <div class="c-card-news__cover">
                                <a class="c-card-news__link" href="<?php the_permalink(); ?>">
                                    <picture  class="c-card-news__image">
                                        <source media="(max-width: 1200px)" srcset="<?php echo $imagefeaturedmobile; ?>">
                                        <img src="<?php echo $imagefeatured; ?>" alt="<?php echo the_title(); ?>">
                                    </picture>
                                    <div class="c-card-news__type"><i class="icon icon-<?php echo $format; ?>"></i></div>
                                </a>
                            </div>
                            <p class="c-card-news__meta"><?php echo get_the_date('M'); ?> <?php echo get_the_date('d'); ?>, <?php echo get_the_date('Y'); ?> · <?php echo '<a href="'. esc_url( home_url( '/category/' ) ) . $categories[0]->slug .'">'.$categories[0]->name; ?></a> · <?php echo prefix_estimated_reading_time( get_the_content() ); ?> min read</p>
                            <a href="<?php the_permalink(); ?>">
                                <h3 class="c-card-news__title"><?php echo the_title(); ?></h3>
                            </a>
                        </article>
                    <?php
                        endwhile; wp_reset_query();
                    ?>
                </div>
            </section>
            <?php
                endif;
            ?>

            <section class="m-brands-ships">
                <div class="container">
                    <div class="c-brands-ships">
                        <h3 class="c-brands-ships__title">Our Fleet</h3>
                    </div>
                    <ul class="c-ships-list">
                        <?php
                            $titleBrand = get_the_title();
                            $args = array(
                                'post_type'      => 'ships',
                                'posts_per_page' =>  -1,
                                'post_status'    => 'publish',
                                'orderby'        => 'date',
                                'order'          => 'DESC',
                            );
                            $myposts = get_posts($args);
                            foreach ($myposts as $post) : setup_postdata($post);
                            $brands = get_field('select_brand');
                            if($brands->post_title == $titleBrand):
                            ?>
                            <li class="c-ships-list__title">
                                <a href="<?php echo the_permalink(); ?>"><?php echo the_title(); ?></a>
                            </li>
                        <?php
                            endif;
                            endforeach;
                            wp_reset_postdata();
                        ?>
                    </ul>
                </div>
			</section>

            <section class="l-brands-ships">
                <div class="container">
                    <div class="row">
                        <div class="col-md-5 col-lg-4">
                            <div class="c-brands-ships">
                                <h3 class="c-brands-ships__title">Our Fleet</h3>
                            </div>
                            <div class="c-ships-scrool__before">
                            <ul class="c-ships-scrool">
                            <?php
                                $titleBrand = get_the_title();
                                $i = 1;
                                $args = array(
                                    'post_type'      => 'ships',
                                    'posts_per_page' =>  -1,
                                    'post_status'    => 'publish',
                                    'orderby'        => 'date',
                                    'order'          => 'DESC',
                                );
                                $myposts = get_posts($args);
                                foreach ($myposts as $post) : setup_postdata($post);
                                $brands = get_field('select_brand');
                                if($brands->post_title == $titleBrand):
                                    $post_id = get_the_ID();
                                ?>
                                <li class="c-ships-scrool__title <?php if($i === 1): echo 'active'; endif; ?>" data-title="<?php echo the_title(); ?>">
                                    <a href="#<?php echo 'hash-' . $post_id ?>" data-id="#<?php echo 'hash-' . $post_id ?>" data-url="<?php echo get_permalink(); ?>"><?php echo the_title(); ?></a>
                                </li>
                            <?php
                                endif;
                                $i++;
                                endforeach;
                                wp_reset_postdata();
                            ?>
                            </ul>
                            </div>
                        </div>
                        <div class="col-md-7 col-lg-8">
                            <div class="c-ships-carousel owl-carousel">
                                <?php
                                    $titleBrand = get_the_title();
                                    $args = array(
                                        'post_type'      => 'ships',
                                        'posts_per_page' =>  -1,
                                        'post_status'    => 'publish',
                                        'orderby'        => 'date',
                                        'order'          => 'DESC',
                                    );
                                    $myposts = get_posts($args);
                                    $i = 1;
                                    foreach ($myposts as $post) : setup_postdata($post);
                                    $brands = get_field('select_brand');
                                    if($brands->post_title == $titleBrand):
                                    $post_id = get_the_ID();
                                ?>
                                <div class="row item align-center" data-hash="<?php echo 'hash-' . $post_id ?>">
                                    <div class="col-md-7 col-lg-6">
                                        <div class="c-ships-carousel__image">
                                            <img data-id="<?php echo $post_id ?>" src="<?php echo get_field('photo_ship'); ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-1 col-lg-6">
                                        <div class="c-info-ships__panel">
                                            <h3 class="c-subtitle is-dark d-none d-lg-block"><?php echo get_field('subtitle_ship'); ?></h3>
                                            <div class="c-description is-dark d-none d-lg-block">
                                                <p><?php echo get_field('description_ship'); ?></p>
                                            </div>
                                            <a class="c-btn-icon is-dark  d-none d-lg-flex" href="<?php echo get_permalink(); ?>">Learn more <i class="icon icon-go"></i></a>
                                        </div>
                                    </div>
                                </div>
                                <?php
                                endif;
                                $i++;
                                endforeach;
                                wp_reset_postdata();
                                ?>
                            </div>
                        </div>
                    </div>
                </div>
            </section>


            </div>
        <?php endwhile; endif; ?>
	</div><!-- .content.inner.single -->

<?php get_footer(); ?>
