<?php
/**
 * Message Box - Template
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 * @param array $args {
 *   @type string $title                    Message box title.
 *   @type string $text                     Message box text.
 *   @type string $theme                    Message box theme. One of: 'positive', 'negative', 'passive', 'neutral'. Default: 'passive'.
 * }
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

$defaults = [
  'title' => '',
  'theme' => 'passive'
];

$options = array_merge( $defaults, $args );

$message_box_icons = [
  'positive'  => 'checkmark',
  'negative'  => 'cross',
  'neutral'   => 'alert',
  'passive'   => 'pin'
];

$is_status_tag_theme = in_array( $options['theme'], [ 'positive', 'negative' ] );

$message_box_icon = array_key_exists( $options['theme'], $message_box_icons ) ? $message_box_icons[$options['theme']] : '';
$message_box_icon_wrapper_classes = $is_status_tag_theme ? 'oroku-status-tag__icon' : 'oroku-message-box__icon oroku-message-box__icon--theme--' . $options['theme'];

?>
<div class="oroku-message-box oroku-message-box--theme--<?php echo esc_attr( $options['theme'] ); ?><?php if ( $options['title'] === '' ) : ?> oroku-message-box--style--small<?php endif; ?>">
<?php if ( $options['title'] !== '' ) : ?>
  <div class="oroku-message-box__header">
  <?php if ( $message_box_icon !== '' ) : ?>
    <?php if ( $is_status_tag_theme ) : ?>
      <div class="oroku-message-box__icon oroku-status-tag oroku-status-tag--size--small oroku-status-tag--style--border oroku-status-tag--theme--<?php echo esc_attr( $options['theme'] ); ?>">
    <?php endif; ?>
    <?php

      /**
       * SVG
       */
      orokublocks()->admin->requireTemplate(
        'svg',
        [
          'additional_wrapper_classes'  => $message_box_icon_wrapper_classes,
          'icon'                        => $message_box_icon
        ]
      );

    ?>
    <?php if ( $is_status_tag_theme ) : ?>
      </div>
    <?php endif; ?>
  <?php endif; ?>
    <h2 class="oroku-message-box__title oroku-h6"><?php echo esc_html( $options['title'] ); ?></h2>
  </div>
<?php endif; ?>
  <p class="oroku-message-box__text oroku-paragraph">
  <?php
  
    echo wp_kses(
      $options['text'],
      [
        'strong'  => [],
        'a'       => [
          'href'    => [],
          'target'  => []
        ]
      ]
    );
  
  ?>
  </p>
</div>