<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

$order_id                 = $args['order_id'] ?? 0;
$profile_id               = $args['profile_id'] ?? 0;
$profile_type             = $args['profile_type'] ?? '';
$freelancer_profile_id    = $args['freelancer_profile_id'] ?? 0;
$employer_profile_id      = $args['employer_profile_id'] ?? 0;
$participant_profile_id   = $args['participant_profile_id'] ?? 0;
$participant_profile_type = $args['participant_profile_type'] ?? '';
$order_location           = $args['order_location'] ?? array();

$date_format     = get_option( 'date_format' );
$order_id_format = gigneo_format_id( $order_id, 'order', false );
$order_post      = get_post( $order_id );

$start_date_raw         = gigneo_post_meta( $order_id, '_gigneo_pm_started_at_gmt' );
$start_date             = ! empty( $start_date_raw ) ? gigneo_datetime( $start_date_raw, $date_format ) : esc_html__( 'None', 'gigneo' );
$extended_delivery_date = gigneo_post_meta( $order_id, '_gigneo_pm_extended_delivery_date_time_gmt' );
$initial_delivery_date  = gigneo_post_meta( $order_id, '_gigneo_pm_delivery_at_gmt' );
$delivery_date_raw      = ! empty( $extended_delivery_date ) ? $extended_delivery_date : $initial_delivery_date;
$delivery_date          = ! empty( $delivery_date_raw ) ? gigneo_datetime( $delivery_date_raw, $date_format ) : esc_html__( 'None', 'gigneo' );

$sub_total   = gigneo_post_meta( $order_id, '_gigneo_pm_subtotal' );
$total       = gigneo_post_meta( $order_id, '_gigneo_pm_total' );
$proposal_id = gigneo_post_meta( $order_id, '_gigneo_pm_proposal_id' );
$job_type    = gigneo_post_meta( $order_id, '_gigneo_pm_delivery_type' );
?>
<div class="gn-order-section gn-order-payment-overview">
	<div class="gn-head">
		<h3 class="gn-title"><?php echo esc_html__( 'Contract overview', 'gigneo' ); ?></h3>
		<?php if ( ! empty( $proposal_id ) ) { ?>
			<a class="gn-link gn-link-primary" href="<?php echo esc_url( gigneo_dashboard_url( 'proposal', 'detail', array( 'p_id' => $proposal_id ) ) ); ?>" target="_blank">
				<?php echo esc_html__( 'View proposal', 'gigneo' ); ?>
				<i class="hi hi-arrow-up-right" aria-hidden="true"></i>
			</a>
		<?php } ?>
	</div>
	<div class="gn-body">
		<div class="gn-stats-wrapper">
			<div class="gn-stat">
				<h4 class="gn-label"><?php echo 'freelancer' === $profile_type ? esc_html__( 'Order amount', 'gigneo' ) : esc_html__( 'Amount paid', 'gigneo' ); ?></h4>
				<span class="gn-value"><?php echo esc_html( gigneo_price_format( 'freelancer' === $profile_type ? $sub_total : $total, true ) ); ?></span>
			</div>
			<div class="gn-stat">
				<h4 class="gn-label"><?php echo esc_html__( 'Type', 'gigneo' ); ?></h4>
				<span class="gn-value"><?php echo esc_html( ucfirst( $job_type ) ); ?></span>
			</div>
			<div class="gn-stat">
				<h4 class="gn-label"><?php echo esc_html__( 'Start date', 'gigneo' ); ?></h4>
				<p class="gn-value"><?php echo esc_html( $start_date ); ?></p>
			</div>
			<div class="gn-stat">
				<h4 class="gn-label"><?php echo esc_html__( 'Due date', 'gigneo' ); ?></h4>
				<p class="gn-value"><?php echo esc_html( $delivery_date ); ?></p>
			</div>
		</div>
	</div>
</div>

<?php gigneo_load_template( 'dashboard/order/job/parts/detail/activity', false, $args ?? array() ); ?>