<?php
/**
 * Step: let delivery receipts reach this site.
 *
 * Shown even when it cannot work here. Silently skipping it would withhold the
 * one thing a developer on a local domain most needs to know — that this is
 * fine, and works once the site is live.
 *
 * @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'] );
$texttango_done    = ! empty( $texttango_step['done'] );
?>
<p class="tt-stage-lead">
	<?php esc_html_e( 'TextTango posts a signed receipt here each time a message is delivered or fails. Without it the message log never moves past "sent".', 'texttango' ); ?>
</p>

<label class="tt-label" for="texttango-wizard-hook"><?php esc_html_e( 'This site receives receipts at', 'texttango' ); ?></label>
<input
	class="tt-input tt-font-mono tt-text-xs"
	id="texttango-wizard-hook"
	type="text"
	readonly
	onfocus="this.select()"
	value="<?php echo esc_attr( (string) $args['webhook'] ); ?>" />

<?php if ( $texttango_blocked ) : ?>
	<div class="tt-notice tt-notice-warn tt-mt-5">
		<strong><?php esc_html_e( 'Not possible on this site.', 'texttango' ); ?></strong>
		<?php echo esc_html( (string) $texttango_step['summary'] ); ?>
	</div>
<?php elseif ( $texttango_done ) : ?>
	<div class="tt-notice tt-notice-ok tt-mt-5">
		<?php echo esc_html( (string) $texttango_step['summary'] ); ?>
	</div>
<?php endif; ?>

<div class="tt-stage-actions">
	<button type="button" class="tt-btn tt-btn-primary" data-texttango-action="webhook-register"
		<?php disabled( $texttango_blocked ); ?>>
		<?php esc_html_e( 'Register this site', 'texttango' ); ?>
	</button>
	<button type="button" class="tt-btn tt-btn-secondary" data-texttango-action="webhook-test"
		<?php disabled( $texttango_blocked ); ?>>
		<?php esc_html_e( 'Send test event', 'texttango' ); ?>
	</button>
</div>

<p class="tt-text-sm tt-mt-3" data-texttango-webhook-result aria-live="polite"></p>

<p class="tt-hint">
	<?php esc_html_e( 'Registering needs a token with webhooks:write. Without that ability, set the callback URL by hand in the TextTango dashboard — everything else still works.', 'texttango' ); ?>
</p>
