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

$profile_id = $args['profile_id'] ?? gigneo_active_profile_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 ) : '';

$document_max_size = gigneo_option( '_gigneo_ts_document_max_size', '1' );
?>
<div id="gn-profile-resume" class="gn-setting-section gn-profile-resume">
	<div class="gn-head">
		<h3 class="gn-title"><?php echo esc_html__( 'Resume', 'gigneo' ); ?></h3>
		<button class="gn-link gn-link-primary" data-gn-modal-toggle="gn-edit-profile-resume">
			<i class="hi hi-pencil-edit" aria-hidden="true"></i>
		</button>
	</div>
	<?php if ( ! empty( $resume_title ) && ! empty( $resume_url ) ) { ?>
		<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>
	<?php } ?>
	<!--Edit Resume Modal-->
	<div id="gn-edit-profile-resume" 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__( 'Resume', 'gigneo' ); ?></h4>
						<p class="gn-description"><?php echo esc_html__( 'Manage and update your resume.', 'gigneo' ); ?></p>
						<button type="button" data-gn-modal-close="gn-edit-profile-resume" 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-resume-file"><?php echo esc_html__( 'Upload resume', 'gigneo' ); ?></label>
									<div id="gn-resume-upload" class="gn-media-uploader gn-media-type-document">
										<input id="gn-resume-file" type="hidden" name="resume" autocomplete="off" value="<?php echo esc_attr( $resume_id ); ?>" />
										<span class="gn-media-info" data-src="<?php echo ! empty( $resume_id ) ? esc_url( wp_get_attachment_url( $resume_id ) ) : ''; ?>">
													<img src="<?php echo esc_url( GIGNEO_DIR_URL . 'assets/img/icon/document.png' ); ?>" alt="<?php echo esc_attr__( 'Document', '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 file', 'gigneo' ); ?></button>
											<span class="gn-upload-description">
												<?php
												printf(
												// translators: %1$s is document max size in MB.
													esc_html__( 'PDF (Max. %1$s MB)', 'gigneo' ),
													esc_html( $document_max_size )
												);
												?>
											</span>
										</span>
									</div>
								</div>
							</fieldset>
						</div>
						<div class="gn-modal-footer">
							<input type="hidden" name="type" value="resume">
							<button type="button" class="gn-btn gn-btn-outline-grey" data-gn-modal-close="gn-edit-profile-resume"><?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>
