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

$profile_id      = $args['p_id'] ?? get_the_ID();
$intro_poster_id = gigneo_post_meta( $profile_id, '_gigneo_pm_intro_poster' );
$intro_video_id  = gigneo_post_meta( $profile_id, '_gigneo_pm_intro_video' );
$intro_video_url = ! empty( $intro_video_id ) ? wp_get_attachment_url( $intro_video_id ) : '';

$resume_id    = gigneo_post_meta( $profile_id, '_gigneo_pm_resume' );
$resume_title = ! empty( $resume_id ) ? basename( get_attached_file( $resume_id ) ) : '';
$resume_url   = ! empty( $resume_id ) ? wp_get_attachment_url( $resume_id ) : '';

if ( empty( $intro_video_url ) && empty( $resume_url ) ) {
	return;
}
?>
<div class="gn-section gn-profile-bio-media">
	<?php
	if ( ! empty( $intro_video_url ) ) {
		$user_name = gigneo_profile_name( $profile_id );
		?>
		<div class="gn-media-section">
			<div class="gn-head">
				<h4 class="gn-title">
					<?php
					// translators: %s: User name.
					printf( esc_html__( 'Meet %s', 'gigneo' ), esc_html( $user_name ) );
					?>
				</h4>
			</div>
			<div class="gn-body">
				<figure class="gn-intro-video">
					<?php gigneo_attachment_image_src( $intro_poster_id, 'medium' ); ?>
					<?php if ( ! empty( $intro_video_url ) ) { ?>
					<a href="<?php echo esc_url( $intro_video_url ); ?>" data-gn-fancybox class="gn-play-video-toggle">
						<i class="hi hi-play" aria-hidden="true"></i>
					</a>
					<?php } ?>
				</figure>
			</div>
		</div>
		<?php
	}

	if ( ! empty( $resume_title ) && ! empty( $resume_url ) ) {
		?>
		<div class="gn-resume-section">
			<div class="gn-head">
				<h4 class="gn-title">
					<?php esc_html_e( 'Resume', 'gigneo' ); ?>:
				</h4>
			</div>
			<div class="gn-body">
				<div class="gn-resume">
					<span class="gn-icon"><i class="hi hi-document-text" aria-hidden="true"></i></span>
					<h6 class="gn-title"><?php echo esc_html( $resume_title ); ?></h6>
					<a href="<?php echo esc_url( $resume_url ); ?>" download class="gn-btn gn-resume-download-btn">
						<i class="hi hi-arrow-down-tray" aria-hidden="true"></i>
					</a>
				</div>
			</div>
		</div>
		<?php
	}
	?>
</div>
