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

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

if ( empty( $experience ) ) {
	return;
}
?>
<div id="gn-experience" class="gn-section gn-section-experience">
	<div class="gn-head">
		<h3 class="gn-title"><?php esc_html_e( 'Experience', 'gigneo' ); ?></h3>
	</div>
	<div class="gn-body">
		<div class="gn-experiences">
			<ul class="gn-info-list">
				<?php
				foreach ( $experience as $key => $experience_item ) {
					$exp_title      = ! empty( $experience_item['title'] ) ? $experience_item['title'] : '';
					$exp_company    = ! empty( $experience_item['company'] ) ? $experience_item['company'] : '';
					$exp_start_date = ! empty( $experience_item['start_date'] ) ? date_i18n( $date_format, strtotime( $experience_item['start_date'] ), true ) : '';
					$exp_end_date   = ! empty( $experience_item['end_date'] ) ? date_i18n( $date_format, strtotime( $experience_item['end_date'] ), true ) : esc_html__( 'Present', 'gigneo' );

					if ( empty( $exp_title ) || empty( $exp_company ) ) {
						continue;
					}
					?>
					<li class="gn-info-list-item">
						<span class="gn-icon">
							<i class="hi hi-briefcase" aria-hidden="true"></i>
						</span>
						<div class="gn-info">
							<h4 class="gn-title"><?php echo esc_html( $exp_company ); ?></h4>
							<ul class="gn-meta">
								<li class="gn-company">
									<i class="hi hi-briefcase" aria-hidden="true"></i>
									<?php echo esc_html( $exp_title ); ?>
								</li>
								<?php if ( ! empty( $exp_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( $exp_start_date ),
										esc_html( $exp_end_date )
									);
									?>
								</li>
								<?php } ?>
							</ul>
						</div>
					</li>
				<?php } ?>
			</ul>
		</div>
	</div>
</div>
