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

$proposal_id = $args['p_id'] ?? '';

$job_id   = $args['job_id'] ?? gigneo_post_meta( $proposal_id, '_gigneo_pm_job_id' );
$job_info = gigneo_post_meta( $proposal_id, '_gigneo_pm_job_info' );

$job_title        = get_the_title( $job_id );
$job_title        = ! empty( $job_info['job_title'] ) ? $job_info['job_title'] : $job_title;
$price            = gigneo_post_meta( $job_id, '_gigneo_pm_price' );
$price            = ! empty( $job_info['job_budget'] ) ? $job_info['job_budget'] : $price;
$duration         = gigneo_post_meta( $job_id, '_gigneo_pm_duration' );
$duration         = ! empty( $job_info['job_delivery_time'] ) ? $job_info['job_delivery_time'] : $duration;
$duration_type    = gigneo_post_meta( $job_id, '_gigneo_pm_duration_type' );
$duration_type    = ! empty( $job_info['job_delivery_time_type'] ) ? $job_info['job_delivery_time_type'] : $duration_type;
$work_mode        = gigneo_post_meta( $job_id, '_gigneo_pm_type' );
$work_mode        = ! empty( $job_info['job_type'] ) ? $job_info['job_type'] : $work_mode;
$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;
$is_featured      = gigneo_post_meta( $job_id, '_gigneo_pm_featured' );

$posted_time      = get_post_time( 'Y-m-d H:i:s', true, $job_id );
$time_diff        = gigneo_datetime( $posted_time, $date_time_format );
$job_status       = get_post_status( $job_id );
$job_status       = 'publish' === $job_status ? 'active' : $job_status;
$job_status_label = gigneo_status_label( $job_status );
$job_status_class = gigneo_status_class( $job_status );
$job_permalink    = get_permalink( $job_id );

if ( empty( $job_id ) ) {
	return;
}

?>
<div class="gn-dashboard-section gn-job-info-section">
	<div class="gn-head">
		<div class="gn-title-wrapper">
			<h2 class="gn-title"><?php echo esc_html( $job_title ); ?></h2>
			<?php
			if ( $is_featured ) {
				?>
				<span class="gn-status-tag-fill gn-warning">
					<?php echo esc_html__( 'Featured', 'gigneo' ); ?>
				</span>
				<?php
			}
			?>
			<?php if ( ! empty( $job_status_class ) ) { ?>
				<span class="gn-status-tag <?php echo esc_attr( $job_status_class ); ?>"><?php echo esc_html( $job_status_label ); ?></span>
			<?php } ?>
		</div>
		<div class="gn-actions">
			<?php if ( in_array( $job_status, array( 'publish', 'completed', 'in-progress' ), true ) ) { ?>
				<a href="<?php echo esc_url( $job_permalink ); ?>" target="_blank" class="gn-btn gn-btn-outline-grey gn-btn-sm">
					<i class="hi hi-eye" aria-hidden="true"></i>
					<?php echo esc_html__( 'View job posting', 'gigneo' ); ?>
				</a>
			<?php } ?>
		</div>
	</div>
	<div class="gn-body">
		<ul class="gn-meta">
			<?php if ( ! empty( $work_mode ) ) { ?>
				<li class="gn-mode">
					<i class="hi hi-map-pin" aria-hidden="true"></i>
					<?php echo esc_html( ucfirst( $work_mode ) ); ?>
				</li>
			<?php } ?>
			<?php if ( ! empty( $duration ) ) { ?>
				<li class="gn-dueration">
					<i class="hi hi-clock" aria-hidden="true"></i>
					<?php echo esc_html( gigneo_delivery_time( $duration, $duration_type ) ); ?>
				</li>
			<?php } ?>
			<?php if ( ! empty( $price ) ) { ?>
				<li class="gn-budget">
					<i class="hi hi-banknotes" aria-hidden="true"></i>
					<?php echo esc_html( gigneo_price_format( $price, true ) ); ?>
				</li>
			<?php } ?>
			<?php if ( ! empty( $deadline ) ) { ?>
				<li class="gn-deadline">
					<i class="hi hi-calendar" aria-hidden="true"></i>
					<?php echo esc_html__( 'Deadline:', 'gigneo' ); ?> <?php echo esc_html( gigneo_datetime( $deadline, $date_format ) ); ?>
				</li>
			<?php } ?>
			<?php if ( ! empty( $posted_time ) ) { ?>
				<li class="gn-posted">
					<?php
					printf(
					// translators: %s is replaced with the time difference, e.g. "2 hours", "3 days"
						esc_html__( 'Posted: %s', 'gigneo' ),
						esc_html( $time_diff )
					);
					?>
				</li>
			<?php } ?>
		</ul>
	</div>
</div>