<?php
/**
 * Step: switch on order notifications.
 *
 * @package TextTango
 *
 * @var array<string, mixed> $args           View data.
 * @var array<string, mixed> $texttango_step This step's state.
 */

declare( strict_types=1 );

defined( 'ABSPATH' ) || exit;

$texttango_blocked = ! empty( $texttango_step['blocked'] );
?>

<?php if ( $texttango_blocked ) : ?>
	<p class="tt-stage-lead tt-mb-0">
		<?php esc_html_e( 'Sign-in codes, the public API and WP-CLI all work without WooCommerce.', 'texttango' ); ?>
	</p>
<?php else : ?>
	<p class="tt-stage-lead">
		<?php esc_html_e( 'Nearly every store wants these two: a message when payment lands, and one when the order is on its way. The rest, and the wording, are on the Notifications tab.', 'texttango' ); ?>
	</p>

	<div class="tt-notice tt-notice-warn tt-mb-5">
		<?php esc_html_e( 'Switching these on starts texting real customers as orders move, and each message costs credit.', 'texttango' ); ?>
	</div>

	<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
		<input type="hidden" name="action" value="<?php echo esc_attr( (string) $args['action'] ); ?>" />
		<input type="hidden" name="step" value="events" />
		<?php wp_nonce_field( (string) $args['action'] ); ?>

		<?php foreach ( (array) $args['recommend'] as $texttango_key ) : ?>
			<?php
			$texttango_event = (array) ( $args['events'][ $texttango_key ] ?? array() );
			$texttango_on    = ! empty( $args['event_on'][ $texttango_key ]['enabled'] );

			if ( empty( $texttango_event ) ) {
				continue;
			}
			?>
			<label class="tt-stage-choice">
				<input type="checkbox" name="events[]" class="tt-mt-0.5"
					value="<?php echo esc_attr( (string) $texttango_key ); ?>"
					<?php checked( true ); ?>
					<?php disabled( $texttango_on ); ?> />
				<span>
					<strong><?php echo esc_html( (string) ( $texttango_event['label'] ?? $texttango_key ) ); ?></strong>
					<?php if ( $texttango_on ) : ?>
						<span class="tt-text-emerald-700"><?php esc_html_e( '— already on', 'texttango' ); ?></span>
					<?php endif; ?>
					<span class="tt-hint tt-block tt-font-mono">
						<?php echo esc_html( (string) ( $texttango_event['template'] ?? '' ) ); ?>
					</span>
				</span>
			</label>
		<?php endforeach; ?>

		<div class="tt-stage-actions">
			<button type="submit" class="tt-btn tt-btn-primary">
				<?php esc_html_e( 'Switch these on', 'texttango' ); ?>
			</button>
		</div>
	</form>
<?php endif; ?>
