<?php 
/* 
* Block Name: Testimonials 02
* Post Type: page, post
*/
?>
<?php if (isset($block['data']['previewImage'])): ?>
    <?php do_action('block_image', __FILE__); ?>
<?php else: ?>
    <?php

    // Block helper
    require \get_template_directory() . '/template-parts/base/block-helper.php';
    if (isset($disable) && $disable) {
        return;
    }

    // Load values and assing defaults
    $testimonials = get_field('testimonials') ?: false;
?>
    <section class="section testimonials-v2-section block <?php echo $className; ?>" 
        <?php if ($bgUrl): ?>
            style="background-image: url('<?php echo $bgUrl; ?>');"
            data-desktop-image="<?php echo $bgUrl; ?>"
        <?php endif; ?>
        <?php if ($mobileBgUrl): ?>
            data-mobile-image="<?php echo $mobileBgUrl; ?>"
        <?php endif; ?>
        <?php if ($sectionId): ?>
            id="<?php echo $sectionId; ?>"
        <?php endif; ?>
    >
        <div class="container">
            <div class="col-lg-8 offset-lg-2 text-content">
                <?php if ($title): ?>
                    <h2 class="h2 d-block text-center"><?php echo $title; ?></h2>
                <?php endif; ?>
                <?php if ($text): ?>
                    <div class="text text-center"><?php echo $text; ?></div>
                <?php endif; ?>
            </div>
            <div class="testimonials-container">
                <div class="testimonials-wrap ms-lg-3">
                    <div class="row g-3 testimonials me-lg-2 my-3 flex-nowrap" data-translate="0">
                        <?php if ($testimonials && is_array($testimonials)): ?>
                            <?php foreach ($testimonials as $key => $testimonial): ?>
                                <div class="col-12 col-lg-6 col-xl-4 testimonial testimonial-<?php echo $key; ?>">
                                    <div class="testimonial-container">
                                        <div class="content">
                                            <div class="quote-author row g-0">
                                                <?php if (array_key_exists('image', $testimonial) && $imageId = $testimonial['image']): ?>
                                                    <div class="col author-image">
                                                        <?php echo wp_get_attachment_image($imageId, 'profile', false, ['class' => 'image']); ?>
                                                    </div>
                                                <?php endif; ?>
                                                <div class="col author-info d-flex align-items-center">
                                                    <div class="author-data">
                                                        <?php if (array_key_exists('name', $testimonial) && $name = $testimonial['name']): ?>
                                                            <h3 class="author-name d-block"><?php echo $name; ?></h3>
                                                        <?php endif; ?>
                                                        <div class="position">
                                                            <?php if (array_key_exists('title', $testimonial) && $position = $testimonial['title']): ?>
                                                                <small><?php echo $position; ?></small>
                                                            <?php endif; ?>
                                                            <?php if (array_key_exists('company', $testimonial) && !empty($testimonial['company'])): ?>
                                                                <?php if ($position): ?>
                                                                    <span class="separator"> | </span>
                                                                <?php endif; ?>
                                                                <a href="<?php echo $testimonial['company']['url']; ?>" target="<?php echo $testimonial['company']['target']; ?>" class="author-company">
                                                                    <small><?php echo $testimonial['company']['title']; ?></small>
                                                                </a>
                                                            <?php endif; ?>
                                                        </div>
                                                        <?php if (array_key_exists('rating', $testimonial) && $rating = $testimonial['rating']): ?>
                                                            <div class="author-rating">
                                                                <?php for ($i=0; $i<5; $i++): ?>
                                                                    <i class="fas fa-star icon <?php echo $rating > $i ? 'active' : ''; ?>"></i>
                                                                <?php endfor; ?>
                                                            </div>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            </div>
                                            <?php if (array_key_exists('text', $testimonial) && $text = $testimonial['text']): ?>
                                                <div class="quote-text pt-2"><?php echo $text; ?></div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="js-controller prev btn me-1 m-lg-0 d-inline-flex justify-content-center align-items-center disabled">
                    <i class="fa fa-angle-left"></i>
                </div>
                <div class="js-controller next btn ms-1 m-lg-0 d-inline-flex justify-content-center align-items-center">
                    <i class="fa fa-angle-right"></i>
                </div>
            </div>
            <div class="text-center">
                <?php if (is_array($cta) && !empty($cta)): ?>
                    <div class="pt-5">
                        <a href="<?php echo $cta['url']; ?>" target="<?php echo $cta['target']; ?>" class="btn btn-silent"><?php echo $cta['title']; ?></a>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </section>
<?php endif; ?>

