<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Prodigy\Includes\Helpers\Prodigy_Formatting;

if ( $show_description ) : ?>
	<?php $has_show_more = ! isset( $is_quick_view ) && ! empty( $is_huge_description ); ?>
	<div class="prodigy-product__description prodigy-custom-template<?php echo $has_show_more ? ' prodigy-product__description--has-show-more' : ''; ?>">
		<div class="prodigy-product__description-container">
			<?php if ( isset( $is_huge_description ) && $is_huge_description ) : ?>
				<div class="prodigy-product__description-truncated">
					<?php echo wp_kses( Prodigy_Formatting::prodigy_truncate( $content, max( 1, (int) $content_truncate_chars ) ), Prodigy_Formatting::get_allowed_html() ); ?>
				</div>
				<div class="prodigy-product__description-full" style="display: none;">
					<?php echo wp_kses( $content, Prodigy_Formatting::get_allowed_html() ); ?>
				</div>
			<?php else : ?>
				<?php echo wp_kses( $content, Prodigy_Formatting::get_allowed_html() ); ?>
			<?php endif; ?>
		</div>
		<?php if ( isset( $is_quick_view ) ) : ?>
			<?php if ( isset( $is_huge_description ) && $is_huge_description ) : ?>
				<span class="show-description-js" style="text-decoration: underline">
					<a href="<?php echo esc_attr( $product->get_field( 'guid' ) ); ?>#tab-description"><?php esc_html_e( 'View on Product Page', 'prodigy-commerce' ); ?></a>
				</span>
			<?php endif; ?>
		<?php elseif ( isset( $is_huge_description ) && $is_huge_description ) : ?>
			<?php
			$anchor_class           = ( isset( $style_anchor_type ) && 'button' === $style_anchor_type )
				? 'prodigy-product__description-control prodigy-product__description-control--btn prodigy-product__description-toggle-js'
				: 'prodigy-product__description-control prodigy-product__description-control--link prodigy-product__description-toggle-js';
			$content_truncate_chars = isset( $content_truncate_chars ) ? (int) $content_truncate_chars : 150;
			?>
			<?php $expandable_id = 'prodigy-description-' . ( isset( $idwidget ) ? $idwidget : '0' ); ?>
			<div id="<?php echo esc_attr( $expandable_id ); ?>" class="prodigy-product__description-expandable prodigy-product__description-expandable--collapsed" aria-expanded="false">
				<div class="prodigy-product__description-container prodigy-product__description-container--truncated">
					<?php echo wp_kses( Prodigy_Formatting::prodigy_truncate( $content, $content_truncate_chars ), Prodigy_Formatting::get_allowed_html() ); ?>
				</div>
				<div class="prodigy-product__description-container prodigy-product__description-container--full" aria-hidden="true">
					<?php echo wp_kses( $content, Prodigy_Formatting::get_allowed_html() ); ?>
				</div>
			</div>
			<button type="button" class="<?php echo esc_attr( $anchor_class ); ?>" data-more="<?php echo esc_attr( __( 'Show more', 'prodigy-commerce' ) ); ?>" data-less="<?php echo esc_attr( __( 'Show less', 'prodigy-commerce' ) ); ?>" aria-controls="<?php echo esc_attr( $expandable_id ); ?>">
				<?php esc_html_e( 'Show more', 'prodigy-commerce' ); ?>
			</button>
		<?php else : ?>
			<?php if ( isset( $is_huge_description ) && $is_huge_description ) : ?>
				<span class="show-description-js" style="text-decoration: underline">
						<a href="<?php echo esc_attr( $product->get_field( 'guid' ) ); ?>#tab-description"><?php esc_html_e( 'Show more', 'prodigy-commerce' ); ?></a>
					</span>
			<?php endif; ?>
			<div class="prodigy-product__description-container">
				<?php echo wp_kses( $content, Prodigy_Formatting::get_allowed_html() ); ?>
			</div>
		<?php endif; ?>
	</div>
<?php endif; ?>
