<?php
$columns = mb_get_block_field("contact-box-columns");

$contact_boxes = mb_get_block_field("contact-boxes");

if ($contact_boxes) { ?>
<section <?= inoby_block_attrs($attributes, ["class" => "contact-boxes"]) ?>>
  <div class="container">
    <div class="row">
      <div class="col-12">
        <div class="contact-boxes-wrap g-col-sm-1 g-col-<?= $columns ?>">
          <?php foreach ($contact_boxes as $contact_item): ?>
              <div class="contact-box">
                <?php
                echo isset($contact_item["headline"]) ? "<h5>" . $contact_item["headline"] . "</h5>" : "";
                echo isset($contact_item["text"]) ? "<p>" . $contact_item["text"] . "</p>" : "";

                $persons = $contact_item["persons"] ?? "";
                if (is_array($persons) || is_object($persons)) {
                  foreach ($persons as $person):
                    echo isset($person["person_text"]) ? '<p class="person-desc">' . $person["person_text"] . "</p>" : "";
                    echo '<div class="person-wrap">';
                    echo isset($person["person_img"]) ? mb_inoby_picture($person["person_img"], "s-2") : "";
                    echo '<div class="person-content">';
                    echo isset($person["name"]) ? '<p class="person-name">' . $person["name"] . "</p>" : "";
                    echo isset($person["email"]) ? '<a href="mailto:' . $person["email"] . '" class="person-email">' . $person["email"] . "</a>" : "";
                    echo isset($person["phone_number"]) ? '<a href="tel:' . $person["phone_number"] . '" class="person-number">' . $person["phone_number"] . "</a>" : "";
                    echo "</div>";
                    echo "</div>";
                  endforeach;
                }
                ?>
              </div>
            <?php endforeach; ?>
        </div>
      </div>
    </div>
  </div>
</section>
<?php }
