<?php

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

/**
 * SportsPress Player Card V1 - 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 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    $width                                    Card width, a value of 0 to lets the card auto adjust size.
 * 
 *   @type string $player_image_style                       Player image style. One of: 'contained', 'overflow'.
 *   @type string $player_background_type                   Player background type. One of: 'color', 'gradient', 'image'.
 *   @type string $player_background_color                  Player background color.
 *   @type string $player_background_gradient_start_color   Player background gradient start color.
 *   @type string $player_background_gradient_end_color     Player background gradient end color.
 *   @type string $player_overlay_color                     Player overlay color.
 *   @type string $player_tag_color                         Player tag color.
 * 
 *   @type string $cover_image_url                          Card cover image URL.
 *   @type string $image_url                                Card image URL.
 *   @type string $featured_image_url                       Featured image URL.
 *   @type string $logo_image_url                           Logo image URL.
 * 
 *   @type string $title                                    Title.
 *   @type string $number                                   Number.
 * 
 *   @type string $tag_text                                 Tag text.
 * 
 *   @type array  $metrics                                  {
 *     @type string $title         Metric title.
 *     @type string $text          Metric text.
 *   }
 * }
 */

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

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

$cover_image_enabled = ( $options['player_background_type'] === 'image' ) && $options['cover_image_url'] !== '';

$player_image_overflow = $options['player_image_style'] === 'overflow';
$has_player_image = $options['image_url'] !== '';

$has_metrics = count( $options['metrics'] ) > 0;

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

?>
  <!-- CARD -->
  <div class="orokublocks-card">
  <?php if ( $options['featured_image_url'] !== '' ) : ?>
    <div class="orokublocks-profile__floaty orokublocks-profile__floaty--position--top--plus orokublocks-profile__floaty--position--right--out">
    <?php

      /**
       * Image Tag
       */
      orokublocks()->requireTemplate(
        'includes/template/image-tag',
        [
          'image_url' => $options['featured_image_url'],
          'size'      => 'tiny',
          'style'     => 'pill'
        ]
      );

    ?>
    </div>
  <?php endif; ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered<?php if ( $player_image_overflow ) : ?> orokublocks-card__content--padding--top--none<?php endif; ?>">
      <div class="orokublocks-profile-wrap<?php if ( $player_image_overflow ) : ?> orokublocks-profile--style--with--cover<?php endif; ?>">
        <div class="orokublocks-profile<?php if ( $options['player_background_type'] === 'color' ) : ?> orokublocks-profile--style--background--color<?php endif; ?><?php if ( $options['player_background_type'] === 'gradient' ) : ?> orokublocks-profile--style--background--gradient<?php endif; ?>">
        <?php if ( $cover_image_enabled ) : ?>
          <div class="orokublocks-profile__cover">
          <?php

            /**
             * Card Image
             */
            orokublocks()->requireTemplate(
              'includes/template/card-image',
              [
                'image_url' => $options['cover_image_url']
              ]
            );

          ?>
          </div>
        <?php endif; ?>

        <?php if ( $has_player_image ) : ?> 
          <div class="orokublocks-profile__image">
            <div class="orokublocks-profile__overlay"></div>
          <?php

            /**
             * Card Image
             */
            orokublocks()->requireTemplate(
              'includes/template/card-image',
              [
                'image_url' => $options['image_url']
              ]
            );

          ?>
          </div>
        <?php endif; ?>

          <div class="orokublocks-profile__details orokublocks-profile__details--align--items--center orokublocks-profile__details--justify--content--end">
          <?php if ( $options['number'] !== '' ) : ?>
            <div class="orokublocks-profile__floaty orokublocks-profile__floaty--position--top orokublocks-profile__floaty--position--left">
              <p class="orokublocks-card__title orokublocks-card__title--size--large orokublocks-text-shadow"><?php echo esc_html( $options['number'] ); ?></p>
            </div>
          <?php endif; ?>

          <?php if ( $options['logo_image_url'] !== '' ) : ?>
            <div class="orokublocks-profile__floaty orokublocks-profile__floaty--position--top--small orokublocks-profile__floaty--position--right">
              <img class="orokublocks-profile__logo" src="<?php echo esc_url( $options['logo_image_url'] ); ?>" alt="">
            </div>
          <?php endif; ?>
          
            <h2 class="orokublocks-card__title orokublocks-card__title--size--bigger orokublocks-text-shadow"><?php echo esc_html( $options['title'] ); ?></h2>
          <?php

            if ( $options['tag_text'] !== '' ) {
              /**
               * Tag
               */
              orokublocks()->requireTemplate(
                'includes/template/tag',
                [
                  'text'  => $options['tag_text'],
                  'color' => $options['player_tag_color'],
                  'size'  => 'medium'
                ]
              );
            }

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

  <?php if ( $has_metrics ) : ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--adjacent orokublocks-card__content--adjacent--small orokublocks-card__content--adjacent--padding--sides--small orokublocks-card__content--theme--darker">
    <?php

      /**
       * Metrics
       */
      orokublocks()->requireTemplate(
        'includes/template/metrics',
        [
          'metrics' => $options['metrics']
        ]
      );

    ?>
    </div>
  <?php endif; ?>
  </div>
  <!-- /CARD -->
</div>