<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$education   = $args['education'] ?? array();
$date_format = $args['date_format'] ?? '';

if ( empty( $education ) ) {
	return;
}

?>
<div id="gn-education" class="gn-section gn-education-section">
	<div class="gn-head">
		<h3 class="gn-title"><?php esc_html_e( 'Education', 'gigneo' ); ?></h3>
	</div>
	<div class="gn-body">
		<div class="gn-educations">
			<ul class="gn-info-list">
				<?php
				foreach ( $education as $key => $education_item ) {
					$edu_school         = ! empty( $education_item['school'] ) ? $education_item['school'] : '';
					$edu_degree         = ! empty( $education_item['degree'] ) ? $education_item['degree'] : '';
					$edu_specialization = ! empty( $education_item['specialization'] ) ? $education_item['specialization'] : '';
					$edu_start_date     = ! empty( $education_item['start_date'] ) ? date_i18n( $date_format, strtotime( $education_item['start_date'] ), true ) : '';
					$edu_end_date       = ! empty( $education_item['end_date'] ) ? date_i18n( $date_format, strtotime( $education_item['end_date'] ), true ) : esc_html__( 'Continue', 'gigneo' );

					if ( empty( $edu_school ) || empty( $edu_degree ) || empty( $edu_specialization ) ) {
						continue;
					}
					?>
					<li class="gn-info-list-item">
						<span class="gn-icon">
							<i class="hi hi-academic-cap" aria-hidden="true"></i>
						</span>
						<div class="gn-info">
							<h4 class="gn-title gn-school"><?php echo esc_html( $edu_school ); ?></h4>
							<ul class="gn-meta">
								<li class="gn-degree">
									<i class="hi hi-briefcase" aria-hidden="true"></i>
									<?php
									printf(
											// translators: 1: Degree, 2: Specialization
										esc_html__( '%1$s in %2$s', 'gigneo' ),
										esc_html( $edu_degree ),
										esc_html( $edu_specialization )
									);
									?>
								</li>
								<?php if ( ! empty( $edu_start_date ) ) { ?>
									<li class="gn-date">
										<i class="hi hi-calendar" aria-hidden="true"></i>
										<?php
										printf(
										// translators: 1: Start date, 2: End date
											esc_html__( '%1$s - %2$s', 'gigneo' ),
											esc_html( $edu_start_date ),
											esc_html( $edu_end_date )
										);
										?>
									</li>
								<?php } ?>
							</ul>
						</div>
					</li>
				<?php } ?>
			</ul>
		</div>
	</div>
</div>
