<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$job_id               = get_the_ID();
$profile_id           = gigneo_active_profile_id();
$price                = gigneo_post_meta( $job_id, '_gigneo_pm_price' );
$duration             = gigneo_post_meta( $job_id, '_gigneo_pm_duration' );
$duration_type        = gigneo_post_meta( $job_id, '_gigneo_pm_duration_type' );
$work_mode            = gigneo_post_meta( $job_id, '_gigneo_pm_type' );
$work_mode            = ! empty( $work_mode ) ? ucfirst( $work_mode ) : '';
$experience_level     = gigneo_post_meta( $job_id, '_gigneo_pm_experience_level' );
$deadline             = gigneo_post_meta( $job_id, '_gigneo_pm_application_deadline_gmt' );
$date_format          = get_option( 'date_format' );
$time_format          = get_option( 'time_format' );
$date_time_format     = $date_format . ' ' . $time_format;
$posted_time          = get_post_time( 'Y-m-d H:i:s', true, $job_id );
$application_deadline = gigneo_datetime( $deadline, $date_format, $profile_id );
$time_posted          = gigneo_datetime( $posted_time, $date_time_format );
$job_type             = gigneo_post_meta( $job_id, '_gigneo_pm_job_type' );
$job_type             = ! empty( $job_type ) ? ucfirst( $job_type ) : '';
$is_featured          = gigneo_post_meta( $job_id, '_gigneo_pm_featured' );

$job_save_items = ! empty( $profile_id ) ? gigneo_post_meta( $profile_id, '_gigneo_pm_saved_job' ) : array();
$active_class   = ( ! empty( $job_save_items ) && in_array( $job_id, $job_save_items, true ) ) ? 'gn-saved' : '';
?>
<div class="gn-single gn-job-single gn-job-single-layout-1">
	<div class="gn-main">
		<div class="gn-head">
			<div class="gn-heading-area">
				<h2 class="gn-title"><?php echo esc_html( get_the_title( $job_id ) ); ?>
					<?php
					if ( $is_featured ) {
						?>
						<span class="gn-status-tag-fill gn-warning">
							<?php echo esc_html__( 'Featured', 'gigneo' ); ?>
						</span>
						<?php
					}
					?>
				</h2>
				<div class="gn-actions">
					<button class="gn-save-btn gn-btn gn-btn-outline-grey <?php echo esc_attr( $active_class ); ?> gn-btn-sm"
						data-gn-id="<?php echo intval( $job_id ); ?>"
						data-gn-type="job"
						aria-label="<?php esc_attr_e( 'Save', 'gigneo' ); ?>">
						<?php gigneo_saved_icon( true ); ?>
					</button>
					<?php if ( in_array( 'report_abuse', gigneo_active_modules(), true ) ) { ?>
							<button class="gn-report-btn gn-btn gn-btn-outline-grey"
									data-gn-id="<?php echo intval( $job_id ); ?>"
									data-gn-type="job"
									data-gn-modal-toggle="gn-job-report-abuse-modal"
									aria-label="<?php esc_attr_e( 'Report abuse', 'gigneo' ); ?>">
								<i class="hi hi-flag" aria-hidden="true"></i>
							</button>
						<?php } ?>
				</div>
			</div>
			<div class="gn-posted-date">
				<span class="gn-date">
					<?php
					printf(
					// translators: %s is replaced with the time difference, e.g. "2 hours", "3 days", etc.
						esc_html__( 'Posted: %s', 'gigneo' ),
						esc_html( $time_posted )
					);

					?>
				</span>
			</div>
			<div class="gn-info-cards">
				<?php if ( ! empty( $job_type ) || ! empty( $work_mode ) ) { ?>
				<div class="gn-info-card">
					<div class="gn-head">
						<span class="gn-icon">
							<i class="hi hi-map-pin" aria-hidden="true"></i>
						</span>
						<h6 class="gn-label"><?php echo esc_html__( 'Type', 'gigneo' ); ?></h6>
					</div>
					<h3 class="gn-value">
						<?php
							echo esc_html( $job_type );
						if ( ! empty( $job_type ) && ! empty( $work_mode ) ) {
							echo esc_html( ' - ' );
						}
								echo esc_html( $work_mode );
						?>
					</h3>
				</div>
				<?php } ?>
				<?php if ( ! empty( $price ) ) { ?>
				<div class="gn-info-card">
					<div class="gn-head">
						<span class="gn-icon">
							<i class="hi hi-banknotes" aria-hidden="true"></i>
						</span>
						<h6 class="gn-label"><?php echo esc_html__( 'Budget', 'gigneo' ); ?></h6>
					</div>
					<h3 class="gn-value"><?php echo esc_html( gigneo_price_format( $price, true ) ); ?></h3>
				</div>
				<?php } ?>
				<?php if ( ! empty( $duration ) && ! empty( $duration_type ) ) { ?>
				<div class="gn-info-card">
					<div class="gn-head">
						<span class="gn-icon">
							<i class="hi hi-clock" aria-hidden="true"></i>
						</span>
						<h6 class="gn-label"><?php echo esc_html__( 'Timeline', 'gigneo' ); ?></h6>
					</div>
					<h3 class="gn-value"><?php echo esc_html( gigneo_delivery_time( $duration, $duration_type ) ); ?></h3>
				</div>
				<?php } ?>
				<?php if ( ! empty( $experience_level ) ) { ?>
				<div class="gn-info-card">
					<div class="gn-head">
						<span class="gn-icon">
							<i class="hi hi-briefcase" aria-hidden="true"></i>
						</span>
						<h6 class="gn-label"><?php echo esc_html__( 'Experience level', 'gigneo' ); ?></h6>
					</div>
					<h3 class="gn-value"><?php echo esc_html( ucfirst( $experience_level ) ); ?></h3>
				</div>
				<?php } ?>
			</div>
		</div>
		<div class="gn-body">
			<?php
			//Description
			gigneo_load_template( 'single/job/parts/description', true, array( 'p_id' => $job_id ) );

			// Skills
			gigneo_load_template( 'single/job/parts/skills', true, array( 'p_id' => $job_id ) );

			//certification
			gigneo_load_template( 'single/job/parts/certifications', true, array( 'p_id' => $job_id ) );

			//Location
			gigneo_load_template( 'single/job/parts/location', true, array( 'p_id' => $job_id ) );

			//Attachments
			gigneo_load_template( 'single/job/parts/attachments', true, array( 'p_id' => $job_id ) );
			?>
		</div>
	</div>
	<div class="gn-aside">
		<?php

		//Vacation
		do_action( 'gigneo_single_job_layout_1_vacation_notice', $job_id );

		if ( ! empty( $application_deadline ) ) {
			?>
			<div class="gn-notices-wrapper">
				<div class="gn-notice gn-notice-info">
					<div class="gn-notice-content">
						<div class="gn-notice-icon">
							<i class="hi hi-exclamation-circle" aria-hidden="true"></i>
						</div>
						<div class="gn-notice-info">
							<p class="gn-description">
								<?php
								printf(
									// translators: %s is replaced with the application deadline date.
									esc_html__( 'Application deadline:  %s.', 'gigneo' ),
									esc_html( $application_deadline )
								)
								?>
							</p>
						</div>
					</div>
				</div>
			</div>
		<?php } ?>
		<form id="gn-job-single-proposal-form" class="gn-job-single-proposal-form" method="get" action="/">
			<?php
			//proposal
			gigneo_load_template( 'single/job/parts/proposal', true, array( 'p_id' => $job_id ) );
			?>
		</form>
		<div class="gn-job-single-employer">
			<?php
			//employer
			gigneo_load_template( 'single/job/parts/employer', true, array( 'p_id' => $job_id ) );
			?>
		</div>
	</div>
</div>
<?php
apply_filters( 'gigneo_job_report_abuse', $job_id );
?>