<?php
/**
 * Test Email tab.
 *
 * @package EmailSmtp
 * @var string $page_url
 * @var array<string, array<string, mixed>> $connections
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$settings_url = add_query_arg( [ 'tab' => 'settings' ], $page_url );
?>

<div class="wpps-ed-panel">
	<h2 class="wpps-ed-panel-title"><?php esc_html_e( 'Send test email', 'wp-powersuite' ); ?></h2>
	<div class="wpps-ed-panel-body">
		<?php if ( $connections === [] ) : ?>
			<p class="description"><?php esc_html_e( 'Add a connection on the Settings tab before sending a test email.', 'wp-powersuite' ); ?></p>
			<p><a class="button button-primary" href="<?php echo esc_url( $settings_url ); ?>"><?php esc_html_e( 'Go to Settings', 'wp-powersuite' ); ?></a></p>
		<?php else : ?>
			<p class="description"><?php esc_html_e( 'Sends through the real WordPress mail path. The connection is chosen automatically from the From email on the message.', 'wp-powersuite' ); ?></p>
			<table class="form-table" role="presentation">
				<tr>
					<th scope="row"><label for="wpps_ed_test_email"><?php esc_html_e( 'Send to', 'wp-powersuite' ); ?></label></th>
					<td><input type="email" class="regular-text" id="wpps_ed_test_email" value="<?php echo esc_attr( wp_get_current_user()->user_email ); ?>" /></td>
				</tr>
				<tr>
					<th scope="row"><label for="wpps_ed_test_subject"><?php esc_html_e( 'Subject', 'wp-powersuite' ); ?></label></th>
					<td><input type="text" class="regular-text" id="wpps_ed_test_subject" value="<?php echo esc_attr( sprintf( __( 'Email delivery check – %s', 'wp-powersuite' ), get_bloginfo( 'name' ) ) ); ?>" /></td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Format', 'wp-powersuite' ); ?></th>
					<td>
						<label><input type="radio" name="wpps_ed_test_format" value="html" checked /> <?php esc_html_e( 'HTML', 'wp-powersuite' ); ?></label>
						&nbsp;
						<label><input type="radio" name="wpps_ed_test_format" value="plain" /> <?php esc_html_e( 'Plain text', 'wp-powersuite' ); ?></label>
					</td>
				</tr>
			</table>
			<p>
				<button type="button" class="button button-primary" id="wpps-ed-send-test" data-label="<?php esc_attr_e( 'Send Test Email', 'wp-powersuite' ); ?>"><?php esc_html_e( 'Send Test Email', 'wp-powersuite' ); ?></button>
			</p>
			<div id="wpps-ed-test-feedback" class="wpps-ed-feedback" role="status" aria-live="polite"></div>
		<?php endif; ?>
	</div>
</div>
