<?php

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

$content_id = $section_content = array();

$content_type = get_theme_mod( 'corporaze_mission_content_type', 'page' );

if ( 'post' === $content_type ) {
	$content_id[] = get_theme_mod( 'corporaze_mission_content_post' );
} else {
	$content_id[] = get_theme_mod( 'corporaze_mission_content_page' );
}
$args = array(
	'post_type'           => $content_type,
	'posts_per_page'      => absint( 1 ),
	'ignore_sticky_posts' => true,
);

if ( ! empty( array_filter( $content_id ) ) ) {
	$args['post__in'] = array_filter( $content_id );
	$args['orderby']  = 'post__in';
} else {
	$args['orderby'] = 'date';
}

$args = apply_filters( 'corporaze_mission_section_content', $args );

corporaze_render_mission_section( $args );

/**
 * Render About Section
 */
function corporaze_render_mission_section( $args ) {
	$query = new WP_Query( $args );
	if ( $query->have_posts() ) :
		$section_subtitle = get_theme_mod( 'corporaze_mission_subtitle', __( 'Our Mission', 'corporaze' ) );
		$button_label     = get_theme_mod( 'corporaze_mission_button_label', __( 'Explore More', 'corporaze' ) );

		while ( $query->have_posts() ) :
			$query->the_post();
			?>
			<section id="corporaze_mission_section" class="corporaze-frontpage-section corporaze-text-image-section mission-style-1 corporaze-image-right">
				<?php
				if ( is_customize_preview() ) :
					corporaze_section_link( 'corporaze_mission_section' );
				endif;
				?>
				<div class="ascendoor-wrapper">
					<div class="corporaze-text-image-section-wrapper">
						<div class="corporaze-text-image-section-image wow fadeInRight" data-wow-duration=".7s" data-wow-delay=".3s">
							<?php the_post_thumbnail(); ?>
						</div>
						<div class="corporaze-text-image-section-text section-header-subtitle small-title wow fadeInLeft" data-wow-duration=".7s" data-wow-delay=".3s">
							<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(), 50 ) ); ?>
							</p>
							<?php if ( ! empty( $button_label ) ) { ?>
								<div class="corporaze-button">
									<a href="<?php the_permalink(); ?>"><?php echo esc_html( $button_label ); ?></a>
								</div>
							<?php } ?>
						</div>
					</div>
				</div>
			</section>
			<?php
		endwhile;
		wp_reset_postdata();
	endif;
}
