<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Prevent direct access to the script.
}

$profile_id        = $args['profile_id'] ?? gigneo_active_profile_id();
$date_format       = $args['date_format'] ?? get_option( 'date_format' );
$max_date          = $args['max_date'] ?? gigneo_datetime( gmdate( 'Y-m-d' ), 'Y-m-d' );
$images_extensions = $args['images_extensions'] ?? gigneo_option( '_gigneo_ts_image_extensions', array( 'jpg', 'jpeg', 'png', 'gif' ) );
$image_max_size    = $args['image_max_size'] ?? gigneo_option( '_gigneo_ts_image_max_size', '1' );

$thumbnail_id     = get_post_thumbnail_id( $profile_id );
$video_extensions = gigneo_option( '_gigneo_ts_video_extensions', array( 'mp4', 'avi', 'mov' ) );
$video_max_size   = gigneo_option( '_gigneo_ts_video_max_size', '1' );
$intro_poster_id  = gigneo_post_meta( $profile_id, '_gigneo_pm_intro_poster' );
$intro_poster_url = ! empty( $intro_poster_id ) ? wp_get_attachment_url( $intro_poster_id ) : '';
$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 ) : '';
?>
<div id="gn-profile-intro" class="gn-setting-section gn-setting-section-list">
	<div class="gn-head">
		<h3 class="gn-title"><?php echo esc_html__( 'Intro video', 'gigneo' ); ?></h3>
		<button class="gn-link gn-link-primary" data-gn-modal-toggle="gn-edit-profile-intro">
			<i class="hi hi-pencil-edit" aria-hidden="true"></i>
		</button>
	</div>
	<?php if ( ! empty( $intro_video_url ) ) { ?>
		<div class="gn-body">
			<figure class="gn-intro-video">
				<?php gigneo_attachment_image_src( $intro_poster_id, 'large' ); ?>
				<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>
			</figure>
		</div>
	<?php } ?>
	<!--Add/Edit Modal-->
	<div id="gn-edit-profile-intro" class="gn-modal-wrapper gn-profile-setting-modal">
		<div class="gn-modal-dialog">
			<div class="gn-modal-content">
				<div class="gn-modal-info">
					<div class="gn-modal-header">
						<h4 class="gn-title"><?php echo esc_html__( 'Introduction video', 'gigneo' ); ?></h4>
						<p class="gn-description"><?php echo esc_html__( 'Manage or update your intro video.', 'gigneo' ); ?></p>
						<button type="button" data-gn-modal-close="gn-edit-profile-intro" class="gn-modal-close">
							<i class="hi hi-x-mark" aria-hidden="true"></i>
						</button>
					</div>
					<form id="gn-save-profile-setting-form" class="gn-theme-form gn-save-profile-setting">
						<div class="gn-modal-body gn-custom-scrollbar">
							<fieldset class="gn-form-fields">
								<div class="gn-form-field gn-media-upload">
									<label for="gn-intro-poster-file"><?php echo esc_html__( 'Upload poster', 'gigneo' ); ?></label>
									<div id="gn-intro-poster-upload" class="gn-media-uploader gn-media-type-image">
										<input id="gn-intro-poster-file" type="hidden" name="intro_poster" autocomplete="off" value="<?php echo esc_attr( $intro_poster_id ); ?>" />
										<span class="gn-media-info">
										<img src="<?php echo ! empty( $intro_poster_url ) ? esc_url( $intro_poster_url ) : ''; ?>" alt="<?php echo esc_attr__( 'Intro poster', 'gigneo' ); ?>">
										<button class="gn-media-uploader-remove" type="button"><i class="hi hi-x-mark" aria-hidden="true"></i></button>
									</span>
										<span class="gn-upload-info">
										<button class="gn-media-upload-toggle" type="button"><?php echo esc_html__( 'Select image', 'gigneo' ); ?></button>
										<p class="gn-upload-description">
										<?php
										printf(
											// translators: %1$s: Valid extensions %2$s Maximum file size.
											esc_html__( '%1$s (Max. %2$s MB)', 'gigneo' ),
											esc_html( strtoupper( implode( ',', $images_extensions ) ) ),
											esc_html( $image_max_size )
										);
										?>
										</p>
									</span>
									</div>
								</div>
								<div class="gn-form-field gn-media-upload">
									<label for="gn-intro-video-file"><?php echo esc_html__( 'Upload video', 'gigneo' ); ?></label>
									<div id="gn-intro-video-upload" class="gn-media-uploader gn-media-type-video">
										<input id="gn-intro-video-file" type="hidden" name="intro_video" autocomplete="off" value="<?php echo esc_attr( $intro_video_id ); ?>" />
										<span class="gn-media-info" data-src="<?php echo ! empty( $intro_video_id ) ? esc_url( wp_get_attachment_url( $intro_video_id ) ) : ''; ?>">
											<img src="<?php echo esc_url( GIGNEO_DIR_URL . 'assets/img/icon/document.png' ); ?>" alt="<?php echo esc_attr__( 'Intro video', 'gigneo' ); ?>">
											<button class="gn-media-uploader-remove" type="button"><i class="hi hi-x-mark" aria-hidden="true"></i></button>
										</span>
										<span class="gn-upload-info">
											<button class="gn-media-upload-toggle" type="button"><?php echo esc_html__( 'Select video', 'gigneo' ); ?></button>
											<p class="gn-upload-description">
											<?php
											printf(
												// translators: %1$s: Valid extensions %2$s Maximum file size.
												esc_html__( '%1$s (Max. %2$s MB)', 'gigneo' ),
												esc_html( strtoupper( implode( ',', $video_extensions ) ) ),
												esc_html( $video_max_size )
											);
											?>
											</p>
										</span>
									</div>
								</div>
							</fieldset>
						</div>
						<div class="gn-modal-footer">
							<input type="hidden" name="type" value="intro">
							<button type="button" class="gn-btn gn-btn-outline-grey" data-gn-modal-close="gn-edit-profile-intro"><?php echo esc_html__( 'Close', 'gigneo' ); ?></button>
							<button type="submit" class="gn-btn gn-btn-primary"><?php echo esc_html__( 'Save', 'gigneo' ); ?></button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>