<?php

if ( ! get_theme_mod( 'charity_elite_enable_about_section', false ) ) {
	return;
}

$charity_elite_content_id   = array();
$charity_elite_content_type = get_theme_mod( 'charity_elite_about_content_type', 'page' );

if ( 'post' === $charity_elite_content_type ) {
	$charity_elite_content_id[] = get_theme_mod( 'charity_elite_about_content_post' );
} else {
	$charity_elite_content_id[] = get_theme_mod( 'charity_elite_about_content_page' );
}
$charity_elite_args = array(
	'post_type'           => $charity_elite_content_type,
	'posts_per_page'      => absint( 1 ),
	'ignore_sticky_posts' => true,
);

if ( ! empty( array_filter( $charity_elite_content_id ) ) ) {
	$charity_elite_args['post__in'] = array_filter( $charity_elite_content_id );
	$charity_elite_args['orderby']  = 'post__in';
} else {
	$charity_elite_args['orderby'] = 'date';
}
	
$charity_elite_args = apply_filters( 'charity_elite_about_section_content', $charity_elite_args );

charity_elite_render_about_section( $charity_elite_args );

/**
 * Render About Us Section
 */

function charity_elite_render_about_section( $charity_elite_args ) {
	$charity_elite_query = new WP_Query( $charity_elite_args );
	if ( $charity_elite_query->have_posts() ) :
		$charity_elite_section_text = get_theme_mod( 'charity_elite_about_section_text', '' );
		$charity_elite_button_label = get_theme_mod( 'charity_elite_about_button_label', __( 'Read More', 'charity-elite' ) );
		$charity_elite_video_label  = get_theme_mod( 'charity_elite_about_video_label', __( 'Play Video', 'charity-elite' ) );
		$charity_elite_video_link   = get_theme_mod( 'charity_elite_about_video_link', '' );
		while ( $charity_elite_query->have_posts() ) :
			$charity_elite_query->the_post();
			?>
			<section id="charity_elite_about_section" class="ascendoor-frontpage-section about-section about-image-right about-style-1">
				<?php
				if ( is_customize_preview() ) :
					charity_elite_section_link( 'charity_elite_about_section' );
				endif;
				?>
				<div class="ascendoor-wrapper">
					<div class="about-section-wrapper">
						<div class="section-image">
							<?php the_post_thumbnail(); ?>
						</div>
						<div class="section-text section-header-subtitle">
							<h3 class="section-title"><?php the_title(); ?></h3>
							<?php if ( ! empty( $charity_elite_section_text ) ) : ?>
								<p class="section-subtitle"><?php echo esc_html( $charity_elite_section_text ); ?></p>
							<?php endif; ?>
							<p class="description"><?php echo wp_kses_post( wp_trim_words( get_the_content(), 50 ) ); ?></p>
							<div class="section-button">
								<a href="<?php the_permalink(); ?>" class="ascendoor-button"><?php echo esc_html( $charity_elite_button_label ); ?></a>
								<?php if ( ! empty( $charity_elite_video_link ) ) : ?>
									<span class="video-btn">
										<a class="ascendoor-video-popup ascendoor-play-btn" href="<?php echo esc_url( $charity_elite_video_link ); ?>">
											<i class="fas fa-play"></i>
											<span class="video-btn-txt"><?php echo esc_html( $charity_elite_video_label ); ?></span>
										</a>
									</span>
								<?php endif; ?>
							</div>
						</div>
					</div>
				</div>
			</section>
			<?php
		endwhile;
		wp_reset_postdata();
	endif;
}
