<?php

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

/**
 * Testimonial Recommendation V2 - Template
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 * @param array $args {
 *   @type string $theme                                    Card color scheme, one of: 'light', 'dark'.
 * 
 *   @type string $light_primary_color                      Light theme primary color. Used when $theme is set to 'light'.
 *   @type string $light_background_color                   Light theme background color. Used when $theme is set to 'light'.
 *   @type string $light_background_alt_color               Light theme alternate background color. Used when $theme is set to 'light'.
 *   @type string $light_line_color                         Light theme line color. Used when $theme is set to 'light'.
 *   @type string $light_text_color                         Light theme text color. Used when $theme is set to 'light'.
 * 
 *   @type string $dark_primary_color                       Dark theme primary color. Used when $theme is set to 'dark'.
 *   @type string $dark_background_color                    Dark theme background color. Used when $theme is set to 'dark'.
 *   @type string $dark_background_alt_color                Dark theme alternate background color. Used when $theme is set to 'dark'.
 *   @type string $dark_line_color                          Dark theme line color. Used when $theme is set to 'dark'.
 *   @type string $dark_text_color                          Dark theme text color. Used when $theme is set to 'dark'.
 * 
 *   @type string $user_avatar_border_color                 User avatar border color.
 *   @type bool   $user_avatar_gradient                     True to use gradient, false otherwise.
 *   @type string $user_avatar_gradient_start_color         User avatar gradient start color.
 *   @type string $user_avatar_gradient_end_color           User avatar gradient end color.
 * 
 *   @type string $verified_user_color                      Verified user color.
 * 
 *   @type string $rating_color                             Rating icon color.
 *   @type string $rating_underline_color                   Rating underlying icon color.
 * 
 *   @type bool   $use_plugin_font                          True to use plugin font, false otherwise.
 *   @type int    $font_scale                               Font size scale value.
 *   @type int    $card_border_radius                       Card border radius.
 *   @type int    $card_image_border_radius                 Card image border radius.
 *   @type int    $width                                    Card width, a value of 0 to lets the card auto adjust size.
 * 
 *   @type string $embed_url                                Card embed URL.
 * 
 *   @type string $title                                    Title.
 *   @type string $title_link                               Title link URL.
 *   @type string $summary                                  Summary.
 * 
 *   @type string $avatar_url                               User avatar URL.
 *   @type string $user_text                                User text.
 *   @type string $user_name                                User name.
 *   @type bool   $verified_user                            True if user is verified, false otherwise.
 * 
 *   @type string $timestamp                                Timestamp.
 * 
 *   @type string $recommendation_title                     Recommendation title.
 *   @type string $recommendation_text                      Recommendation text.
 *   @type string $recommendation_image_url                 Recommendation image URL.
 * 
 *   @type int    $score_value                              Score value.
 *   @type int    $score_max_value                          Score max value.
 * 
 *   @type string $footer_left_title                        Footer left title.
 *   @type bool   $share_facebook_enabled                   True to display facebook share link, false otherwise.
 *   @type bool   $share_x_enabled                          True to display x share link, false otherwise.
 * }
 */

$defaults = orokublocks()->widgets['item_review']['instance']->getDefaultOptions();

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

$embed_enabled = $options['embed_url'] !== '';

$recommendation_available = ( $options['recommendation_image_url'] !== '' ) || ( $options['recommendation_title'] !== '' ) || ( $options['recommendation_text'] !== '' );
$user_available = ( $options['avatar_url'] !== '' ) || ( $options['user_text'] !== '' ) || ( $options['user_name'] !== '' );

$share_enabled = $options['share_facebook_enabled'] || $options['share_x_enabled'];
$footer_available = ( $options['footer_left_title'] !== '' ) || $share_enabled;

/**
 * Card Opening Tag
 */
orokublocks()->requireTemplate(
  'widgets/testimonialrecommendation/template/card-opening-tag',
  [
    'version' => 'v2',
    'options' => $options
  ]
);

?>
  <!-- CARD -->
  <div class="orokublocks-card">
  <?php if ( $embed_enabled ) : ?>
    <div class="orokublocks-card__content orokublocks-card__content--padding--none orokublocks-card__content--bordered orokublocks-card__content--border--bottom--none orokublocks-card__content--border--bottom--flat">
      <!-- CARD MEDIA -->
      <div class="card__media">
        <iframe
          class="card__media-embed"
          src="<?php echo esc_url( $options['embed_url'] ); ?>"
          frameborder="0"
          allowfullscreen
        >
        </iframe>
      </div>
      <!-- /CARD MEDIA -->
    </div>
  <?php endif; ?>

    <div class="orokublocks-card__content orokublocks-card__content--bordered<?php if ( ( $options['summary'] !== '' ) || $recommendation_available || $footer_available ) : ?> orokublocks-card__content--border--bottom--flat<?php endif; ?><?php if ( $embed_enabled ) : ?> orokublocks-card__content--border--top--none orokublocks-card__content--border--top--flat<?php endif; ?>">
      <div class="orokublocks-card__content orokublocks-card__content--padding--inner">
        <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--small orokublocks-card__item--direction--vertical orokublocks-card__item--align--center">
          <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--minier orokublocks-card__item--direction--vertical orokublocks-card__item--align--center orokublocks-card__item--centered">
          <?php if ( $options['timestamp'] !== '' ) : ?>
            <div class="orokublocks-card__item">
              <p class="orokublocks-card__text orokublocks-card__text--size--small"><?php echo esc_html( $options['timestamp'] ); ?></p>
            </div>
          <?php endif; ?>

            <div class="orokublocks-card__item">
            <?php if ( $options['title_link'] !== '' ) : ?>
              <a class="orokublocks-card__link" href="<?php echo esc_url( $options['title_link'] ); ?>">
            <?php endif; ?>
              <h2 class="orokublocks-card__title orokublocks-card__title--line--height--small"><?php echo esc_html( $options['title'] ); ?></h2>
            <?php if ( $options['title_link'] !== '' ) : ?>
              </a>
            <?php endif; ?>
            </div>
          </div>
        <?php

          /**
           * Rating Tag Box
           */
          orokublocks()->requireTemplate(
            'includes/template/rating-tag-box',
            [
              'score_value'     => $options['score_value'],
              'score_max_value' => $options['score_max_value']
            ]
          );

          if ( $user_available ) {
            /**
             * User Avatar Block
             */
            orokublocks()->requireTemplate(
              'includes/template/user-avatar-block',
              [
                'avatar_url'            => $options['avatar_url'],
                'user_avatar_gradient'  => $options['user_avatar_gradient'],
                'verified_user'         => $options['verified_user'],
                'user_text'             => $options['user_text'],
                'user_name'             => $options['user_name']
              ]
            );
          }

        ?>
        </div>
      </div>
    </div>

  <?php if ( $options['summary'] !== '' ) : ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--adjacent orokublocks-card__content--adjacent--regular<?php if ( $recommendation_available || $footer_available ) : ?> orokublocks-card__content--border--bottom--flat<?php endif; ?> orokublocks-card__content--theme--darker">
      <div class="orokublocks-card__item orokublocks-card__item--centered">
        <p class="orokublocks-card__text orokublocks-card__text--line--height"><?php echo esc_html( $options['summary'] ); ?></p>
      </div>
    </div>
  <?php endif; ?>

  <?php if ( $recommendation_available ) : ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--adjacent orokublocks-card__content--adjacent--small<?php if ( $footer_available ) : ?> orokublocks-card__content--border--bottom--flat<?php endif; ?>">
      <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap orokublocks-card__item--align--center orokublocks-card__item--justify--space--between">
        <div class="orokublocks-card__item">
          <p class="orokublocks-card__text orokublocks-card__text--size--small"><?php echo esc_html( $options['recommendation_title'] ); ?></p>
        </div>

        <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--tiny orokublocks-card__item--align--center">
          <p class="orokublocks-card__text orokublocks-card__text--size--small orokublocks-card__text--style--bold"><?php echo esc_html( $options['recommendation_text'] ); ?></p>

        <?php if ( $options['recommendation_image_url'] !== '' ) : ?>
          <div class="orokublocks-thumbnail">
            <img class="orokublocks-thumbnail__image orokublocks-thumbnail__image--size--small" src="<?php echo esc_url( $options['recommendation_image_url'] ); ?>" alt="">
          </div>
        <?php endif; ?>
        </div>
      </div>
    </div>
  <?php endif; ?>
  <?php

    /**
     * Card Footer
     */
    orokublocks()->requireTemplate(
      'includes/template/card-footer',
      [
        'title' => $options['footer_left_title'],
        'share' => [
          'share_facebook_enabled'  => $options['share_facebook_enabled'],
          'share_x_enabled'         => $options['share_x_enabled'],
          'share_text'              => $options['title'],
          'share_url'               => $options['title_link']
        ],
        'theme' => 'light'
      ]
    );

  ?>
  </div>
  <!-- /CARD -->
</div>