<?php
/**
 * Resume Early Confirmation Panel
 *
 * Inline panel that expands when a subscriber clicks the "Resume Early"
 * action on a snoozed Scheduled Order. Replaces the browser confirm()
 * dialog with an in-page UI that explains the consequence of resuming
 * before the auto-resume date.
 *
 * This template can be overridden by copying it to yourtheme/autoship-cloud/templates/scheduled-orders/resume-early-confirm-template.php
 *
 * @package Autoship
 * @subpackage Templates
 *
 * @var int            $order_number      The scheduled order ID.
 * @var object|array   $autoship_order    The scheduled order.
 */

defined( 'ABSPATH' ) || exit;

$schedule_label    = autoship_translate_text( 'Scheduled Order' );
$snooze_until_text = autoship_get_snooze_until_text( $autoship_order );
?>

<div class="autoship-resume-early-panel"
	id="autoship-resume-early-panel-<?php echo esc_attr( $order_number ); ?>"
	data-order-id="<?php echo esc_attr( $order_number ); ?>">

	<div class="autoship-resume-early-panel-inner">

		<h4 class="autoship-resume-early-title">
			<?php
			echo esc_html(
				sprintf(
					/* translators: %s is the Scheduled Order label */
					__( 'Resume this %s now?', 'autoship' ),
					strtolower( $schedule_label )
				)
			);
			?>
		</h4>

		<p class="autoship-resume-early-body">
			<?php
			if ( ! empty( $snooze_until_text ) ) {
				$is_array         = is_array( $autoship_order );
				$snooze_until_utc = $is_array ? ( $autoship_order['snoozeUntilUtc'] ?? '' ) : ( $autoship_order->snoozeUntilUtc ?? '' ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
				$timestamp        = strtotime( $snooze_until_utc );
				$formatted_date   = false !== $timestamp ? date_i18n( get_option( 'date_format' ), $timestamp ) : '';

				echo wp_kses(
					sprintf(
						/* translators: %s is the formatted resume date */
						__( 'Your order is currently snoozed until <strong>%s</strong>. Resuming early will reactivate it immediately — your next occurrence will be recalculated from today.', 'autoship' ),
						esc_html( $formatted_date )
					),
					array( 'strong' => array() )
				);
			} else {
				echo esc_html( __( 'Resuming early will reactivate this order immediately — your next occurrence will be recalculated from today.', 'autoship' ) );
			}
			?>
		</p>

		<div class="autoship-resume-early-actions">
			<button type="button"
					class="autoship-resume-early-confirm button"
					data-order-id="<?php echo esc_attr( $order_number ); ?>">
				<?php echo esc_html( __( 'Yes, Resume Now', 'autoship' ) ); ?>
			</button>
			<button type="button"
					class="autoship-resume-early-cancel button"
					data-order-id="<?php echo esc_attr( $order_number ); ?>">
				<?php echo esc_html( __( 'Keep Snoozed', 'autoship' ) ); ?>
			</button>
		</div>

		<div class="autoship-resume-early-message" id="autoship-resume-early-message-<?php echo esc_attr( $order_number ); ?>" style="display:none;"></div>

	</div>

</div>
