<?php 
/* 
* Block Name: Team
* 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.
    $team = get_field('team') ?: false;
?>
    <section class="section team-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="fluid-container team-wrapper">
            <div class="team-container d-flex" data-translate="0">
                <div class="team row d-flex">
                <?php if (is_array($team) && $all = count($team)): $width = (($all - 1) * 120); ?>
                    <style>
                        @media only screen and (min-width: 936px) {
                            .team-section .team-container .team .member .content {
                                width: calc(100vw - <?php echo $width; ?>px);
                            }
                            .team-section .team-container .team .member.active {
                                min-width: calc(100vw - <?php echo $width; ?>px);
                                width: calc(100vw - <?php echo $width; ?>px);
                            }
                            .team-section .team-container .team .member .description {
                                width: calc(100vw - <?php echo $width + 320; ?>px);
                                min-width: calc(100vw - <?php echo $width + 320; ?>px);
                            }
                        }
                    </style>
                    <?php foreach ($team as $key => $member): ?>
                    <div class="member col <?php if (!$key) { echo 'first active'; } ?> <?php if ($key == ($all - 1)) { echo 'last'; } ?>">
                        <div class="content d-flex">
                            <div class="image" style="background-image: url(<?php if ($imgId = $member['image']) { $urlArr = wp_get_attachment_image_src($imgId, 'full'); echo $urlArr[0]; } ?>)"></div>
                            <div class="description d-flex align-items-center">
                                <span class="description-text">
                                    <div class="social-links">
                                    <?php if (is_array($member['social_media_links']) && count($member['social_media_links'])): ?>
                                        <?php foreach ($member['social_media_links'] as $link): ?>
                                            <?php if (isset($link['link'], $link['link']['url'])): ?>
                                            <a href="<?php echo $link['link']['url']; ?>" target="<?php echo $link['link']['target']; ?>" title="<?php echo $link['link']['title']; ?>">
                                                <?php if (isset($link['icon'])): ?>
                                                    <i class="link <?php echo $link['icon']; ?>"></i>
                                                <?php endif; ?>
                                            </a>
                                            <?php endif; ?>
                                        <?php endforeach ?>
                                    <?php endif; ?>
                                    </div>
                                    <?php if (isset($member['name']) && $member['name']): ?>
                                        <h2 class="name"><?php echo $member['name']; ?></h2>
                                    <?php endif; ?>
                                    <?php if (isset($member['position']) && $member['position']): ?>
                                        <p class="text">
                                            <small class="position"><?php echo $member['position']; ?></small>
                                        </p>
                                    <?php endif; ?>
                                    <?php if (isset($member['text']) && $member['text']): ?>
                                        <div class="text"><?php echo $member['text']; ?></div>
                                    <?php endif; ?>
                                    <div class="arrow"></div>
                                </span>
                            </div>
                        </div>
                    </div>
                    <?php endforeach ?>
                <?php endif ?>
                </div>
            </div>
        </div>
    </section>
<?php endif; ?>

