<?php

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

$order_id = $args['p_id'] ?? '';
if ( ! $order_id ) {
	return;
}

$plan_data      = get_post_meta( $order_id, '_gigneo_pm_price_plan', true );
$total_revision = ! empty( $plan_data['revisions'] ) ? $plan_data['revisions'] : 'unlimited';
$revision_used  = gigneo_post_meta( $order_id, '_gigneo_pm_revision_used' );
$revision_used  = ! empty( $revision_used ) ? intval( $revision_used ) : 0;
$revision_left  = is_numeric( $total_revision ) ? intval( $total_revision ) - $revision_used : 0;

if ( ! is_numeric( $total_revision ) && 'unlimited' === $total_revision ) {
	return;
}
?>
<div class="gn-order-section gn-order-revisions">
	<div class="gn-head">
		<h3 class="gn-title"><?php esc_html_e( 'Revisions used', 'gigneo' ); ?></h3>
		<div class="gn-count-wrapper">
			<span class="gn-count-left"><?php echo esc_html( $revision_used ); ?></span>
			<span class="gn-count-separator">/</span>
			<span class="gn-count-total"><?php echo esc_html( $revision_left ); ?></span>
		</div>
	</div>
	<div class="gn-body">
		<div class="gn-progress-steps">
			<?php
			$total_revision_int = intval( $total_revision );

			for ( $i = 1; $i <= $total_revision_int; $i++ ) {
				$step_status = 'pending';

				if ( $i <= $revision_used ) {
					$step_status = 'active';
				}
				?>
				<span class="gn-progress-step gn-<?php echo esc_attr( $step_status ); ?>"></span>
			<?php } ?>
		</div>
	</div>
</div>
