<?php

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

/**
 * Promo Discount 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 string $promo_discount_text_gradient_color           Text color.
 *   @type bool   $promo_discount_text_gradient                 True to use gradient colors, false otherwise.
 *   @type string $promo_discount_text_gradient_start_color     Gradient text start color.
 *   @type string $promo_discount_text_gradient_end_color       Gradient text end 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 $image_url                                    Card image URL.
 * 
 *   @type string $title                                        Title.
 *   @type string $title_link                                   Title link URL.
 *   @type string $subtitle                                     Subtitle.
 *   @type string $summary                                      Summary.
 * 
 *   @type string $promo_discount_text                          Promo discount text.
 * 
 *   @type string $countdown_enabled                            True to display countdown, false otherwise.
 *   @type string $countdown_target_date                        Countdown target date.
 *   @type string $countdown_expiration_text                    Text to display when the countdown finishes.
 *   @type string $countdown_days_text                          Countdown days text.
 *   @type string $countdown_hours_text                         Countdown hours text.
 *   @type string $countdown_minutes_text                       Countdown minutes text.
 *   @type string $countdown_seconds_text                       Countdown seconds text.
 * 
 *   @type string $button_text                                  Button text.
 *   @type string $button_link                                  Button link.
 * }
 */

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

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

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

?>
  <!-- CARD -->
  <div class="orokublocks-card">
    <div class="orokublocks-card__content orokublocks-card__content--bordered">
    <?php

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

    ?>
      <div class="orokublocks-card__content orokublocks-card__content--padding--inner">
        <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--big orokublocks-card__item--direction--vertical">
          <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--medium orokublocks-card__item--direction--vertical">
            <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--small orokublocks-card__item--direction--vertical">
              <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"><?php echo esc_html( $options['title'] ); ?></h2>
              <?php if ( $options['title_link'] !== '' ) : ?>
                </a>
              <?php endif; ?>

              <?php if ( $options['subtitle'] !== '' ) : ?>
                <p class="orokublocks-card__text"><?php echo esc_html( $options['subtitle'] ); ?></p>
              <?php endif; ?>
              </div>
            </div>

          <?php if ( ( $options['promo_discount_text'] !== '' ) || ( $options['summary'] !== '' ) ) : ?>
            <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--tiny orokublocks-card__item--direction--vertical orokublocks-card__item--align--start">
            <?php if ( $options['promo_discount_text'] !== '' ) : ?>
              <p class="orokublocks-text-gradient orokublocks-text-gradient--style--<?php if ( $options['promo_discount_text_gradient'] ) : ?>background<?php else: ?>color<?php endif; ?>">
                <?php echo esc_html( $options['promo_discount_text'] ); ?>
              </p>
            <?php endif; ?>

            <?php if ( $options['summary'] !== '' ) : ?>
              <p class="orokublocks-card__text orokublocks-card__text--line--height">
              <?php

                echo wp_kses(
                  $options['summary'],
                  [
                    'strong'  => []
                  ]
                );

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

        <?php if ( $options['button_text'] !== '' ) : ?>
          <div class="orokublocks-card__item">
            <a class="orokublocks-button orokublocks-button--style--round orokublocks-button--width--full" href="<?php echo esc_url( $options['button_link'] ); ?>">
              <?php echo esc_html( $options['button_text'] ); ?>
            </a>
          </div>
        <?php endif; ?>
        </div>
      </div>
    </div>
    
  <?php if ( $options['countdown_enabled'] ) : ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--adjacent orokublocks-card__content--adjacent--small orokublocks-card__content--theme--darker">
    <?php

      /**
       * Countdown
       */
      orokublocks()->requireTemplate(
        'includes/template/countdown',
        [
          'days_text'     => $options['countdown_days_text'],
          'hours_text'    => $options['countdown_hours_text'],
          'minutes_text'  => $options['countdown_minutes_text'],
          'seconds_text'  => $options['countdown_seconds_text']
        ]
      );

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