<?php
    $categories = get_the_terms($post_id,'create_taxonomy_faq');
    $post_id = get_the_ID();
    $imagefeatured = get_the_post_thumbnail_url($post_id,'featured-single');
    $author = get_field('author_news');
?>
<div id="post-<?php the_ID(); ?>" class="post l-faq">
    <section class="l-hero-single pt-lg-5">
        <div class="container">
            <div class="row">
                <div class="col-md-1"></div>
                <div class="col-md-9 col-lg-10">
                    <a class="c-arrow-prev mb-1 d-block" href="<?php echo esc_url( home_url( '/help-faqs' ) ); ?>"><i class="icon icon-left-open-big"></i>Back to Help & FAQ</a>
                    <h1 class="c-title"><?php echo the_title(); ?></h1>
                </div>
                <div class="col-md-2 col-lg-1">
                    <div class="share-bottom">
                        <?php get_template_part('templates/content', 'share'); ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <section class="l-image-single l-faq-image-single">
        <div class="container">
            <div class="c-image-single">
                <img src="<?php echo $imagefeatured; ?>" alt="<?php echo the_title(); ?>">
                <?php $video = get_field('url_video_featured');
                    if($video):
                ?>
                <a data-fancybox href="<?php echo $video; ?>" class="c-box-featured__btn is-light">Watch</a>
                    <?php  endif; ?>
            </div>
        </div>
    </section>
    <article class="l-faq-single-content">
        <div class="container">
            <div class="row">
                <div class="col-md-1">

                </div>
                <div class="col-md-11">
                    <?php
                        $postfaqs = get_field('content_faq');
                        foreach($postfaqs as $postfaq):
                            ?>
                            <div class="row l-faq-single-content__line">
                                <div class="col-md-4 col-xl-3">
                                    <?php if($postfaq['image_featured_row']): ?>
                                        <img src="<?php echo $postfaq['image_featured_row']; ?>" alt="<?php echo the_title(); ?>">
                                    <?php endif; ?>
                                </div>
                                <div class="col-md-1"></div>
                                <div class="col-md-6 col-xl-7">
                                    <?php echo $postfaq['text_row_content']; ?>
                                </div>
                            </div>
                            <?php
                        endforeach;
                    ?>
                    <?php
                        $checkapp = get_field('download_app_caribbean_digital');
                        $ios = get_field('link_app_ios');
                        $android = get_field('link_app_android');
                        if($checkapp):
                            ?>
                                <div class="row">
                                    <div class="col-md-4"></div>
                                    <div class="col-md-7 mb-2">
                                        <h3 class="c-title-app">Download the Royal Caribbean app</h3>
                                        <div class="stores">
                                            <?php if($ios): ?>
                                                <a href="<?php echo $ios; ?>" target="_blank">
                                                    <img class="pr-1" src="<?php echo get_template_directory_uri(); ?>/img/content/applestore.svg" alt="Appe Store">
                                                </a>
                                            <?php endif;?>
                                            <?php if($android): ?>
                                                <a href="<?php echo $android; ?>" target="_blank">
                                                    <img src="<?php echo get_template_directory_uri(); ?>/img/content/playstore.svg" alt="Play Store">
                                                </a>
                                            <?php endif;?>
                                        </div>
                                    </div>
                                </div>
                            <?php
                        endif;
                    ?>
                    <?php
                        $help = get_field('need_more_help');
                        if($help):
                            ?>
                                <div class="row">
                                    <div class="col-md-4"></div>
                                    <div class="col-md-7">
                                        <h3 class="c-subtitle is-dark mb-2 mt-2">Need more help?</h3>
                                        <div class="c-description is-dark-gray"><?php echo $help; ?></p>
                                    </div>
                                </div>
                            <?php
                        endif;
                    ?>
                </div>
            </div>
        </div>
    </article>
    <div class="l-single-tags">
        <div class="container">
            <div class="row">
                <div class="col-md-1"></div>
                <div class="col-md-11 pd-none">
                    <div class="row">
                        <div class="col-md-4"></div>
                        <div class="col-md-7">
                            <div class="c-single-tags tags-faq">
                                <h3 class="c-single-tags__title">Tags:</h3>
                                <p class="c-single-tags__content">
                                <?php $tags= get_the_terms($post_id, 'faq-tag');
                                    if($tags):
                                        $total = (is_array($tags) ? count($tags) : 0);
                                        foreach($tags as $i => $tag):
                                            // if($i = 2):
                                            // 	break;
                                            // endif;
                                            // if($i = 2):
                                            // 	continue;
                                            // endif;
                                            echo '<a href="'. esc_url( home_url( '/tag-faq/' ) ) . $tag->slug .'"><span>' . $tag->slug . '</span></a>';
                                            echo $i < ($total - 1) ? ', ' : '';
                                        endforeach;
                                    endif;
                                ?>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php
        $postsrelated = get_field('select_posts_related');
        if($postsrelated):
    ?>
    <section class="l-brands-news l-brands-technology py-3 py-md-3 py-xl-4">
        <div class="carousel-title d-flex justify-content-between align-items-center mb-md-1 mb-xl-3">
            <h2 class="c-subtitle is-tech">Other related topics</h2>

            <div class="d-none d-sm-flex">
                <a href="javascript:;" class="c-btn-round is-tech js-carousel-default-prev" aria-label="Prev"><i class="icon icon-left-arrow"></i></a>
                <a href="javascript:;" class="c-btn-round is-tech 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
                foreach($postsrelated as $postrel):
                    $post_id = $postrel->ID;
                    $imagefeatured = get_the_post_thumbnail_url($post_id,'list-archive');
                    $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 echo get_permalink($post_id); ?>">
                            <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 is-tech"><?php echo get_the_date('M', $post_id); ?> <?php echo get_the_date('d', $post_id); ?>, <?php echo get_the_date('Y', $post_id); ?> · <?php echo prefix_estimated_reading_time( $postrel->post_content ); ?> min read</p>
                    <a href="<?php echo get_permalink($post_id); ?>">
                        <h3 class="c-card-news__title is-tech"><?php echo get_the_title($post_id); ?></h3>
                    </a>
                </article>
            <?php
                endforeach;
            ?>
        </div>
    </section>
    <?php
       endif;
    ?>
</div><!-- .post -->