<?php

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

/**
 * Item Review 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 $status_tag_enabled_icon_color            Status tag enabled icon color.
 *   @type string $status_tag_enabled_background_color      Status tag enabled background color.
 *   @type string $status_tag_disabled_icon_color           Status tag disabled icon color.
 *   @type string $status_tag_disabled_background_color     Status tag disabled background 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 $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 int    $score_value                              Score value.
 *   @type int    $score_max_value                          Score max value.
 *   @type string $score_separator                          Score separator.
 *   @type string $score_text                               Score text.
 * 
 *   @type string $pros_icon                                Pros custom SVG icon name.
 *   @type string $pros_status_tag_style                    Pros status tag style, one of: 'regular', 'background', 'background-round', 'outline'.
 *   @type string $pros_title                               Pros title.
 *   @type array  $pros                                     {
 *     @type string $text       Pro text.
 *   }
 *   @type string $cons_icon                                Cons custom SVG icon name.
 *   @type string $cons_status_tag_style                    Cons status tag style, one of: 'regular', 'background', 'background-round', 'outline'.
 *   @type string $cons_title                               Cons title.
 *   @type array  $cons                                     {
 *     @type string $text       Con text.
 *   }
 * 
 *   @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.
 * 
 *   @type string $button_text                              Button text.
 *   @type string $button_link                              Button link.
 * }
 */

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

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

$has_pros = count( $options['pros'] ) > 0;
$has_cons = count( $options['cons'] ) > 0;
$has_pros_or_cons = $has_pros || $has_cons;

$features = orokublocks()->widgets['item_review']['instance']->parseFeaturesData( $options );

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

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

    /**
     * Social Tag Box
     */
    orokublocks()->requireTemplate(
      'includes/template/social-tag-box',
      [
        'position'  => [ 'top', 'right' ],
        'share'     => [
          'share_facebook_enabled'  => $options['share_facebook_enabled'],
          'share_x_enabled'         => $options['share_x_enabled'],
          'share_text'              => $options['title'],
          'share_url'               => $options['title_link']
        ]
      ]
    );

  ?>
    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--border--bottom--flat">
      <div class="orokublocks-card__content orokublocks-card__content--padding--inner">
        <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--medium orokublocks-card__item--direction--vertical">
        <?php if ( $options['image_url'] !== '' ) : ?>
          <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--tiny">
            <div class="orokublocks-card__item">
            <?php

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

            ?>
            </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"><?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>
        <?php if ( $options['image_url'] !== '' ) : ?>
          </div>
        <?php endif; ?>

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

          /**
           * Card Features
           */
          orokublocks()->requireTemplate(
            'includes/template/card-features',
            [
              'features'  => $features
            ]
          );

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

    <div class="orokublocks-card__content orokublocks-card__content--bordered orokublocks-card__content--adjacent">
      <div class="orokublocks-card__item orokublocks-card__item--divided orokublocks-card__item--gap--small orokublocks-card__item--justify--space--between orokublocks-card__item--align--bottom">
        <div class="orokublocks-card__item">
        <?php if ( $options['score_text'] !== '' ) : ?>
          <p class="orokublocks-card__text orokublocks-card__text--size--small orokublocks-card__text--space--below"><?php echo esc_html( $options['score_text'] ); ?></p>
        <?php endif; ?>
        <?php if ( ( $options['score_value'] !== '' ) && ( $options['score_max_value'] !== '' ) ) : ?>
          <h2 class="orokublocks-card__title">
          <?php echo esc_html( $options['score_value'] ); ?>
          <?php echo esc_html( $options['score_separator'] ); ?>
          <?php echo esc_html( $options['score_max_value'] ); ?>
          </h2>
        <?php endif; ?>
        </div>

        <div class="orokublocks-card__item">
        <?php

          /**
           * Rating
           */
          orokublocks()->requireTemplate(
            'includes/template/rating',
            [
              'rating_value'      => $options['score_value'],
              'rating_max_value'  => $options['score_max_value']
            ]
          );

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

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