<?php
/**
 * Template part for displaying the news footer contact information
 *
 * @package MarComm-AUX
 * @since 1.0.0
 */
declare(strict_types=1);

use WP_AUX\Entities\PageTemplateEntity;
use WP_AUX\Services\HtmlService;

$auxTemplate = PageTemplateEntity::getRequested();
$contactInfo = $auxTemplate->getSetting('contact');

if (
  empty($contactInfo['person']) &&
  empty($contactInfo['organization']) &&
  empty($contactInfo['email']) &&
  empty($contactInfo['phone']) &&
  empty($contactInfo['additional_content'])
) {
  return;
}
?>
<div class="media-contact">
  <span class="media-contact__heading">Media Contact</span>
  <div class="media-contact__info">
    <?php
    echo HtmlService::paragraph($contactInfo['person'], 'name');
    echo HtmlService::paragraph(@$contactInfo['organization']->name, 'title');

    if (!empty($contactInfo['email'])) {
      ?>
      <p class="email">
        <svg alt="email"><use href="#aux_envelope"></use></svg>
        <?php
        echo sprintf('<a href="mailto:%s">%s</a>', $contactInfo['email'], $contactInfo['email']);
        ?>
      </p>
      <?php
    }

    if (!empty($contactInfo['phone'])) {
      ?>
      <p class="phone">
        <svg alt="phone"><use href="#aux_phone"></use></svg>
        <?php echo $contactInfo['phone']; ?>
      </p>
      <?php
    }

    echo HtmlService::formattedValue($contactInfo['additional_content'], '<div>%s</div>');
    ?>
  </div>
</div>
