<?php
$defaults = function_exists('fjord_clone_get_about_team_defaults') ? fjord_clone_get_about_team_defaults() : [];
$attrs = (array) $attributes;

$members = [];
if (!empty($attrs['members']) && is_array($attrs['members'])) {
  $members = $attrs['members'];
}
if (!$members && isset($defaults['members'])) {
  $members = $defaults['members'];
}

if (!$members) {
  return;
}
?>
<div class="fjord-about-team">
  <?php foreach ($members as $member) : ?>
    <?php
    $name = isset($member['name']) ? (string) $member['name'] : '';
    $role = isset($member['role']) ? (string) $member['role'] : '';
    $image = isset($member['imageUrl']) ? (string) $member['imageUrl'] : '';
    $alt = isset($member['imageAlt']) ? (string) $member['imageAlt'] : '';
    if ($alt === '') {
      $alt = $name;
    }
    $socials = isset($member['socials']) && is_array($member['socials']) ? $member['socials'] : [];
    ?>
    <article class="fjord-about-team__card">
      <?php if ($name !== '') : ?>
        <span class="fjord-about-team__name"><?php echo esc_html($name); ?></span>
      <?php endif; ?>
      <?php if ($image !== '') : ?>
        <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($alt); ?>">
      <?php endif; ?>
      <div class="fjord-about-team__overlay">
        <?php if ($role !== '') : ?>
          <span class="fjord-about-team__role"><?php echo esc_html($role); ?></span>
        <?php endif; ?>
        <?php if (!empty($socials)) : ?>
          <div class="fjord-about-team__social">
            <?php foreach ($socials as $social) : ?>
              <?php
              $network = isset($social['network']) ? (string) $social['network'] : '';
              $url = isset($social['url']) ? (string) $social['url'] : '';
              if ($network === '' || $url === '') {
                continue;
              }
              $icon = function_exists('fjord_clone_get_social_icon_svg') ? fjord_clone_get_social_icon_svg($network) : '';
              if ($icon === '') {
                continue;
              }
              $label = function_exists('fjord_clone_get_social_label') ? fjord_clone_get_social_label($network) : ucfirst($network);
              ?>
              <a href="<?php echo esc_url($url); ?>" aria-label="<?php echo esc_attr($label); ?>">
                <?php echo $icon; ?>
              </a>
            <?php endforeach; ?>
          </div>
        <?php endif; ?>
      </div>
    </article>
  <?php endforeach; ?>
</div>
