<?php

use Tangibledesign\MyHome\Widgets\General\TeamRosterWidget;

/* @var TeamRosterWidget $mhCurrentWidget */
global $mhCurrentWidget;

$members = $mhCurrentWidget->getTeamMembers();
if ($members->isEmpty()) {
    return;
}
?>
<div class="myhome-team-roster">
    <?php foreach ($members as $member) : ?>
        <div class="myhome-team-roster__member">
            <?php if (!empty($member['link']['url'])) : ?>
                <a href="<?php echo esc_url($member['link']['url']); ?>"
                   <?php if (!empty($member['link']['is_external'])) : ?>
                       target="_blank"
                   <?php endif; ?>
                   <?php if (!empty($member['link']['nofollow'])) : ?>
                       rel="nofollow"
                   <?php endif; ?>
                   class="myhome-team-roster__link">
            <?php endif; ?>
            
            <div class="myhome-team-roster__image">
                <?php if (!empty($member['image']['id'])) : ?>
                    <img
                        class="lazyload"
                        src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAQAAAA3fa6RAAAADklEQVR42mNkAANGCAUAACMAA2w/AMgAAAAASUVORK5CYII="
                        data-src="<?php echo esc_url(wp_get_attachment_image_url($member['image']['id'], 'myhome_300_300')); ?>"
                        alt="<?php echo esc_attr($member['name']); ?>"
                    >
                <?php else : ?>
                    <div class="myhome-team-roster__placeholder">
                        <span><?php echo esc_html(tdf_string('no_photo')); ?></span>
                    </div>
                <?php endif; ?>
            </div>

            <?php if (!empty($member['name'])) : ?>
                <h3 class="myhome-team-roster__name">
                    <?php echo esc_html($member['name']); ?>
                </h3>
            <?php endif; ?>

            <?php if (!empty($member['position'])) : ?>
                <div class="myhome-team-roster__position">
                    <?php echo esc_html($member['position']); ?>
                </div>
            <?php endif; ?>

            <?php if (!empty($member['phone'])) : ?>
                <div class="myhome-team-roster__phone">
                    <a href="tel:<?php echo esc_attr(str_replace(' ', '', $member['phone'])); ?>">
                        <?php echo esc_html($member['phone']); ?>
                    </a>
                </div>
            <?php endif; ?>

            <?php if (!empty($member['link']['url'])) : ?>
                </a>
            <?php endif; ?>
        </div>
    <?php endforeach; ?>
</div>