<?php
/**
 * Step: choose the sender ID.
 *
 * @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'] ) && empty( $texttango_step['done'] );
?>
<?php if ( $texttango_blocked ) : ?>
	<div class="tt-notice tt-notice-warn">
		<?php esc_html_e( 'Connect your account first — there is nothing to choose from until a token works.', 'texttango' ); ?>
	</div>
<?php else : ?>
	<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="sender" />
		<?php wp_nonce_field( (string) $args['action'] ); ?>

		<label class="tt-label" for="texttango-wizard-sender"><?php esc_html_e( 'Sender ID', 'texttango' ); ?></label>
		<div class="tt-flex tt-gap-2">
			<input
				class="tt-input"
				id="texttango-wizard-sender"
				name="sender_id"
				type="text"
				maxlength="11"
				list="texttango-sender-ids"
				value="<?php echo esc_attr( (string) $args['sender'] ); ?>" />
			<datalist id="texttango-sender-ids"></datalist>
			<button type="button" class="tt-btn tt-btn-secondary tt-shrink-0" data-texttango-action="load-senders">
				<?php esc_html_e( 'Load', 'texttango' ); ?>
			</button>
		</div>
		<p class="tt-hint">
			<?php esc_html_e( 'Up to 11 characters. Load pulls the approved sender IDs from your account — an unapproved one is rejected at send time.', 'texttango' ); ?>
		</p>

		<div class="tt-stage-actions">
			<button type="submit" class="tt-btn tt-btn-primary">
				<?php esc_html_e( 'Save and continue', 'texttango' ); ?>
			</button>
			<span class="tt-text-sm" data-texttango-result aria-live="polite"></span>
		</div>
	</form>
<?php endif; ?>
