<?php

/**
 * The Template for displaying course stats in archive courses page
 *
 *
 * HOWEVER, on occasion Masteriyo will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @package Masteriyo\Templates
 * @version 1.11.0
 */

defined( 'ABSPATH' ) || exit; // Exit if accessed directly.

/**
 * Fires before rendering stats section in archive course page.
 *
 * @since 1.11.0
 */
do_action( 'masteriyo_before_archive_course_stats' );
$sections = masteriyo_get_course_structure( $course->get_id() );
if ( empty( $sections ) ) {
	return;
}

?>
<div class="masteriyo-course--content__stats">
	<?php if ( masteriyo_should_show_component( 'showCourseDuration', 'course_archive.components_visibility.course_duration' ) && $course->get_duration() > 0 ) : ?>
	<div class="masteriyo-course-stats-duration">
		<?php masteriyo_get_svg( 'time', true ); ?> <span><?php echo esc_html( masteriyo_minutes_to_time_length_string( $course->get_duration() ) ); ?></span>
	</div>
	<?php endif; ?>
	<?php if ( masteriyo_should_show_component( 'showStudentsCount', 'course_archive.components_visibility.students_count' ) && masteriyo_count_enrolled_users( $course->get_id() ) + $course->get_fake_enrolled_count() > 0 ) : ?>
	<div class="masteriyo-course-stats-students">
		<?php masteriyo_get_svg( 'group', true ); ?> <span><?php echo esc_html( masteriyo_count_enrolled_users( $course->get_id() ) + $course->get_fake_enrolled_count() ); ?></span>
	</div>
	<?php endif; ?>
	<?php if ( masteriyo_should_show_component( 'showLessonsCount', 'course_archive.components_visibility.lessons_count' ) && masteriyo_get_lessons_count( $course ) + $quiz_count + $google_meet_count > 0 ) : ?>
	<div class="masteriyo-course-stats-curriculum">
		<?php masteriyo_get_svg( 'book', true ); ?> <span><?php echo esc_html( masteriyo_get_lessons_count( $course ) + $quiz_count + $google_meet_count ); ?></span>
	</div>
	<?php endif; ?>
	<!-- Available seats for students-->
	<?php if ( masteriyo_get_setting( 'course_archive.components_visibility.seats_for_students' ) && $course->get_enrollment_limit() > 0 ) : ?>
		<div class="masteriyo-available-seats-for-students">
			<?php masteriyo_get_svg( 'available-seats-for-students', true ); ?> <span><?php echo esc_html( $course->get_enrollment_limit() > 0 ? $course->get_enrollment_limit() - masteriyo_count_enrolled_users( $course->get_id() ) : 0 ); ?></span>
		</div>
	<?php endif; ?>
</div>

<?php

/**
 * Fires after rendering stats section in archive course page.
 *
 * @since 1.11.0
 */
do_action( 'masteriyo_after_archive_course_stats' );
