<?php

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

$content_id    = $section_content = array();
$content_count = 1;

$content_type = get_theme_mod( 'construktly_about_content_type', 'page' );
if ( in_array( $content_type, array( 'post', 'page' ) ) ) {

	$content_id[] = get_theme_mod( 'construktly_about_content_' . $content_type );

	$args = array(
		'post_type'           => $content_type,
		'post__in'            => $content_id,
		'orderby'             => 'post__in',
		'posts_per_page'      => absint( $content_count ),
		'ignore_sticky_posts' => true,
	);
	$args = apply_filters( 'construktly_about_section_content', $args );

	construktly_render_about_section( $args );
}

/**
 * Render About Section
 */
function construktly_render_about_section( $args ) {
	$query = new WP_Query( $args );
	if ( $query->have_posts() ) :
		$section_subtitle = get_theme_mod( 'construktly_about_subtitle', __( 'About Us', 'construktly' ) );
		$button_label     = get_theme_mod( 'construktly_about_button_label', __( 'Read More', 'construktly' ) );
		while ( $query->have_posts() ) :
			$query->the_post();
			?>
			<section id="construktly_about_section" class="construktly-frontpage-section construktly-text-image-section construktly-secondary1-background construktly-image-left construktly-about-style-1">
				<?php
				if ( is_customize_preview() ) :
					construktly_section_link( 'construktly_about_section' );
				endif;
				?>
				<div class="construktly-text-image-section-image">
					<?php the_post_thumbnail(); ?>
				</div>
				<div class="ascendoor-wrapper">
					<div class="construktly-text-image-section-wrapper">
						<div class="construktly-text-image-section-text section-header-subtitle small-title">
							<h3 class="section-title"><?php echo esc_html( $section_subtitle ); ?></h3>
							<p class="section-subtitle"><?php the_title(); ?></p>
							<p class="description">
								<?php echo wp_kses_post( wp_trim_words( get_the_content(), get_theme_mod( 'construktly_about_excerpt_count', 50 ) ) ); ?>
							</p>
							<?php if ( ! empty( $button_label ) ) { ?>
								<div class="construktly-button construktly-button-alternate">
									<a href="<?php the_permalink(); ?>"><?php echo esc_html( $button_label ); ?></a>
								</div>
							<?php } ?>
						</div>
					</div>
				</div>
			</section>
			<?php
		endwhile;
		wp_reset_postdata();
	endif;
}
