<?php
/* @var Tangibledesign\MyHome\Widgets\General\TestimonialsWidget $mhCurrentWidget */
global $mhCurrentWidget;

$testimonials = $mhCurrentWidget->getTestimonials();

if ($testimonials->isEmpty()) {
    return;
}
?>
<div class="myhome-testimonials-widget">
    <div class="myhome-testimonials-widget__grid">
        <?php foreach ($testimonials as $testimonial) : ?>
            <div class="myhome-testimonials-widget__card">
                <div class="myhome-testimonials-widget__content">
                    <?php if (!empty($testimonial['title'])) : ?>
                        <h3 class="myhome-testimonials-widget__title">
                            <?php echo esc_html($testimonial['title']); ?>
                        </h3>
                    <?php endif; ?>

                    <?php if (!empty($testimonial['testimonial_text'])) : ?>
                        <div class="myhome-testimonials-widget__text">
                            <?php echo nl2br(wp_kses_post($testimonial['testimonial_text'])); ?>
                        </div>
                    <?php endif; ?>
                </div>

                <div class="myhome-testimonials-widget__footer">
                    <div class="myhome-testimonials-widget__avatar-wrapper">
                        <?php if (!empty($testimonial['avatar']['id'])) : ?>
                            <div class="myhome-testimonials-widget__avatar myhome-testimonials-widget__avatar--image">
                                <img
                                    class="lazyload"
                                    src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAQAAAA3fa6RAAAADklEQVR42mNkAANGCAUAACMAA2w/AMgAAAAASUVORK5CYII="
                                    data-src="<?php echo esc_url(wp_get_attachment_image_url($testimonial['avatar']['id'], 'myhome_100_100')); ?>"
                                    alt="<?php echo esc_attr($testimonial['client_name']); ?>"
                                >
                            </div>
                        <?php else : ?>
                            <div class="myhome-testimonials-widget__avatar myhome-testimonials-widget__avatar--initials">
                                <?php echo esc_html(!empty($testimonial['initials']) ? $testimonial['initials'] : substr($testimonial['client_name'], 0, 1)); ?>
                            </div>
                        <?php endif; ?>
                    </div>

                    <div class="myhome-testimonials-widget__client-info">
                        <?php if (!empty($testimonial['client_name'])) : ?>
                            <div class="myhome-testimonials-widget__client-name">
                                <?php echo esc_html($testimonial['client_name']); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (!empty($testimonial['client_location'])) : ?>
                            <div class="myhome-testimonials-widget__client-location">
                                <?php echo esc_html($testimonial['client_location']); ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>