<?php
/**
 * Network defaults view.
 *
 * @var array<string, mixed> $mail_doctor_defaults
 * @var array<string, bool>  $mail_doctor_locks
 *
 * @package MailDoctor
 */

use MailDoctor\Helpers\Settings;

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

$mail_doctor_encryption           = $mail_doctor_defaults['smtp_encryption'] ?? 'tls';
$mail_doctor_scope                = $mail_doctor_defaults['override_scope'] ?? 'all';
$mail_doctor_backoff              = isset( $mail_doctor_defaults['backoff_schedule'] ) && is_array( $mail_doctor_defaults['backoff_schedule'] )
	? implode( ', ', array_map( 'intval', $mail_doctor_defaults['backoff_schedule'] ) )
	: '';
$mail_doctor_list_mailto          = $mail_doctor_defaults['list_unsubscribe_mailto'] ?? '';
$mail_doctor_list_url             = $mail_doctor_defaults['list_unsubscribe_url'] ?? '';
$mail_doctor_alerts_enabled       = ! empty( $mail_doctor_defaults['alerts_enabled'] );
$mail_doctor_alert_threshold      = $mail_doctor_defaults['alert_threshold_percent'] ?? 20;
$mail_doctor_alert_window         = $mail_doctor_defaults['alert_window_minutes'] ?? 30;
$mail_doctor_alert_burst_failures = $mail_doctor_defaults['alert_burst_failures'] ?? 5;
$mail_doctor_alert_burst_minutes  = $mail_doctor_defaults['alert_burst_minutes'] ?? 5;
$mail_doctor_alert_email          = $mail_doctor_defaults['alert_email'] ?? '';
$mail_doctor_alert_slack          = $mail_doctor_defaults['alert_slack_webhook'] ?? '';
$mail_doctor_alert_webhook        = $mail_doctor_defaults['alert_generic_webhook'] ?? '';
$mail_doctor_alert_cooldown       = $mail_doctor_defaults['alert_cooldown_minutes'] ?? 60;
$mail_doctor_structured_enabled   = ! empty( $mail_doctor_defaults['structured_logging_enabled'] );
$mail_doctor_structured_endpoint  = $mail_doctor_defaults['structured_logging_endpoint'] ?? '';
$mail_doctor_structured_token     = $mail_doctor_defaults['structured_logging_token'] ?? '';

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$mail_doctor_updated = isset( $_GET['updated'] ) && (bool) absint( wp_unslash( $_GET['updated'] ) );
?>
<?php $mail_doctor_main_id = 'mail-doctor-network'; ?>
<div class="wrap mail-doctor">
	<a class="mail-doctor__skip-link" href="#<?php echo esc_attr( $mail_doctor_main_id ); ?>"><?php esc_html_e( 'Skip to Mail Doctor content', 'mail-doctor' ); ?></a>
	<h1><?php esc_html_e( 'Mail Doctor Network Defaults', 'mail-doctor' ); ?></h1>

	<?php if ( $mail_doctor_updated ) : ?>
		<div class="notice notice-success"><p><?php esc_html_e( 'Network defaults saved.', 'mail-doctor' ); ?></p></div>
	<?php endif; ?>

	<p><?php esc_html_e( 'Configure default SMTP settings for all sites in the network. Optionally enforce specific values so subsites cannot override them.', 'mail-doctor' ); ?></p>

	<main id="<?php echo esc_attr( $mail_doctor_main_id ); ?>" class="mail-doctor__main" tabindex="-1">
	<form method="post" action="<?php echo esc_url( network_admin_url( 'edit.php?action=mail_doctor_network' ) ); ?>">
		<?php wp_nonce_field( 'mail_doctor_network' ); ?>

		<h2><?php esc_html_e( 'SMTP Credentials', 'mail-doctor' ); ?></h2>
		<table class="form-table">
			<tr>
				<th scope="row"><label for="omd-network-smtp-host"><?php esc_html_e( 'SMTP Host', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="text" id="omd-network-smtp-host" name="network_settings[smtp_host]" value="<?php echo esc_attr( $mail_doctor_defaults['smtp_host'] ?? '' ); ?>" class="regular-text" />
					<label><input type="checkbox" name="network_locks[smtp_host]" value="1" <?php checked( ! empty( $mail_doctor_locks['smtp_host'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-smtp-port"><?php esc_html_e( 'SMTP Port', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="number" id="omd-network-smtp-port" name="network_settings[smtp_port]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['smtp_port'] ?? '' ) ); ?>" min="1" />
					<label><input type="checkbox" name="network_locks[smtp_port]" value="1" <?php checked( ! empty( $mail_doctor_locks['smtp_port'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Encryption', 'mail-doctor' ); ?></th>
				<td>
					<select name="network_settings[smtp_encryption]">
						<?php foreach ( array( 'none', 'tls', 'ssl' ) as $mail_doctor_option ) : ?>
							<option value="<?php echo esc_attr( $mail_doctor_option ); ?>" <?php selected( $mail_doctor_encryption, $mail_doctor_option ); ?>><?php echo esc_html( strtoupper( $mail_doctor_option ) ); ?></option>
						<?php endforeach; ?>
					</select>
					<label><input type="checkbox" name="network_locks[smtp_encryption]" value="1" <?php checked( ! empty( $mail_doctor_locks['smtp_encryption'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-username"><?php esc_html_e( 'Username', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="text" id="omd-network-username" name="network_settings[smtp_username]" value="<?php echo esc_attr( $mail_doctor_defaults['smtp_username'] ?? '' ); ?>" class="regular-text" />
					<label><input type="checkbox" name="network_locks[smtp_username]" value="1" <?php checked( ! empty( $mail_doctor_locks['smtp_username'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-password"><?php esc_html_e( 'Password / API Key', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="password" id="omd-network-password" name="network_settings[smtp_password]" value="" class="regular-text" autocomplete="new-password" />
					<p class="description"><?php esc_html_e( 'Leave blank to keep the existing network password.', 'mail-doctor' ); ?></p>
					<label><input type="checkbox" name="network_locks[smtp_password]" value="1" <?php checked( ! empty( $mail_doctor_locks['smtp_password'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
		</table>

		<h2><?php esc_html_e( 'Email Identity & Behaviour', 'mail-doctor' ); ?></h2>
		<table class="form-table">
			<tr>
				<th scope="row"><label for="omd-network-from-email"><?php esc_html_e( 'From Email', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="email" id="omd-network-from-email" name="network_settings[from_email]" value="<?php echo esc_attr( $mail_doctor_defaults['from_email'] ?? '' ); ?>" class="regular-text" />
					<label><input type="checkbox" name="network_locks[from_email]" value="1" <?php checked( ! empty( $mail_doctor_locks['from_email'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-from-name"><?php esc_html_e( 'From Name', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="text" id="omd-network-from-name" name="network_settings[from_name]" value="<?php echo esc_attr( $mail_doctor_defaults['from_name'] ?? '' ); ?>" class="regular-text" />
					<label><input type="checkbox" name="network_locks[from_name]" value="1" <?php checked( ! empty( $mail_doctor_locks['from_name'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php esc_html_e( 'Override Scope', 'mail-doctor' ); ?></th>
				<td>
					<fieldset>
						<label>
							<input type="radio" name="network_settings[override_scope]" value="woocommerce" <?php checked( $mail_doctor_scope, 'woocommerce' ); ?> />
							<?php esc_html_e( 'WooCommerce emails only', 'mail-doctor' ); ?>
						</label><br />
						<label>
							<input type="radio" name="network_settings[override_scope]" value="all" <?php checked( $mail_doctor_scope, 'all' ); ?> />
							<?php esc_html_e( 'All wp_mail calls', 'mail-doctor' ); ?>
						</label>
					</fieldset>
					<label><input type="checkbox" name="network_locks[override_scope]" value="1" <?php checked( ! empty( $mail_doctor_locks['override_scope'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-max-attempts"><?php esc_html_e( 'Max Retry Attempts', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="number" id="omd-network-max-attempts" name="network_settings[max_attempts]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['max_attempts'] ?? '' ) ); ?>" min="1" />
					<label><input type="checkbox" name="network_locks[max_attempts]" value="1" <?php checked( ! empty( $mail_doctor_locks['max_attempts'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-backoff"><?php esc_html_e( 'Backoff Schedule (seconds)', 'mail-doctor' ); ?></label></th>
				<td>
					<input type="text" id="omd-network-backoff" name="network_settings[backoff_schedule]" value="<?php echo esc_attr( $mail_doctor_backoff ); ?>" class="regular-text" placeholder="300, 900, 3600" />
					<p class="description"><?php esc_html_e( 'Comma-separated retry delays (in seconds).', 'mail-doctor' ); ?></p>
					<label><input type="checkbox" name="network_locks[backoff_schedule]" value="1" <?php checked( ! empty( $mail_doctor_locks['backoff_schedule'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
	<tr>
		<th scope="row"><label for="omd-network-retention"><?php esc_html_e( 'Log Retention (days)', 'mail-doctor' ); ?></label></th>
		<td>
			<input type="number" id="omd-network-retention" name="network_settings[log_retention]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['log_retention'] ?? '' ) ); ?>" min="7" />
			<label><input type="checkbox" name="network_locks[log_retention]" value="1" <?php checked( ! empty( $mail_doctor_locks['log_retention'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
	<tr>
		<th scope="row"><?php esc_html_e( 'Privacy Mode', 'mail-doctor' ); ?></th>
		<td>
			<label>
				<input type="checkbox" name="network_settings[privacy_mode]" value="1" <?php checked( ! empty( $mail_doctor_defaults['privacy_mode'] ) ); ?> />
				<?php esc_html_e( 'Redact headers, bodies, and attachments by default.', 'mail-doctor' ); ?>
			</label>
			<br /><label><input type="checkbox" name="network_locks[privacy_mode]" value="1" <?php checked( ! empty( $mail_doctor_locks['privacy_mode'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
	<tr>
		<th scope="row"><?php esc_html_e( 'Hash Recipients', 'mail-doctor' ); ?></th>
		<td>
			<label>
				<input type="checkbox" name="network_settings[hash_recipients]" value="1" <?php checked( ! empty( $mail_doctor_defaults['hash_recipients'] ) ); ?> />
				<?php esc_html_e( 'Store recipient addresses as hashes by default.', 'mail-doctor' ); ?>
			</label>
			<br /><label><input type="checkbox" name="network_locks[hash_recipients]" value="1" <?php checked( ! empty( $mail_doctor_locks['hash_recipients'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
	<tr>
		<th scope="row"><label for="omd-network-retention-sent"><?php esc_html_e( 'Sent Retention (days)', 'mail-doctor' ); ?></label></th>
		<td>
			<input type="number" id="omd-network-retention-sent" name="network_settings[retention_sent_days]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['retention_sent_days'] ?? '' ) ); ?>" min="1" />
			<label><input type="checkbox" name="network_locks[retention_sent_days]" value="1" <?php checked( ! empty( $mail_doctor_locks['retention_sent_days'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
	<tr>
		<th scope="row"><label for="omd-network-retention-failed"><?php esc_html_e( 'Failed Retention (days)', 'mail-doctor' ); ?></label></th>
		<td>
			<input type="number" id="omd-network-retention-failed" name="network_settings[retention_failed_days]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['retention_failed_days'] ?? '' ) ); ?>" min="1" />
			<label><input type="checkbox" name="network_locks[retention_failed_days]" value="1" <?php checked( ! empty( $mail_doctor_locks['retention_failed_days'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
	<tr>
		<th scope="row"><label for="omd-network-retention-payload"><?php esc_html_e( 'Payload Retention (days)', 'mail-doctor' ); ?></label></th>
		<td>
			<input type="number" id="omd-network-retention-payload" name="network_settings[retention_payload_days]" value="<?php echo esc_attr( (string) ( $mail_doctor_defaults['retention_payload_days'] ?? '' ) ); ?>" min="1" />
			<label><input type="checkbox" name="network_locks[retention_payload_days]" value="1" <?php checked( ! empty( $mail_doctor_locks['retention_payload_days'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
		</td>
	</tr>
			<tr>
				<th scope="row"><label for="omd-network-cleanup"><?php esc_html_e( 'Full data removal on uninstall', 'mail-doctor' ); ?></label></th>
				<td>
					<label>
						<input type="checkbox" id="omd-network-cleanup" name="network_settings[cleanup_on_uninstall]" value="1" <?php checked( ! empty( $mail_doctor_defaults['cleanup_on_uninstall'] ) ); ?> />
						<?php esc_html_e( 'When a site deletes Mail Doctor, drop all plugin data (logs, archives, profiles, suppressions, secrets, settings, and API keys).', 'mail-doctor' ); ?>
					</label><br />
					<label><input type="checkbox" name="network_locks[cleanup_on_uninstall]" value="1" <?php checked( ! empty( $mail_doctor_locks['cleanup_on_uninstall'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
			<tr>
				<th scope="row"><label for="omd-network-compatibility"><?php esc_html_e( 'Compatibility Mode', 'mail-doctor' ); ?></label></th>
				<td>
					<label>
						<input type="checkbox" id="omd-network-compatibility" name="network_settings[compatibility_mode]" value="1" <?php checked( ! empty( $mail_doctor_defaults['compatibility_mode'] ) ); ?> />
						<?php esc_html_e( 'Limit overrides to WooCommerce emails by default.', 'mail-doctor' ); ?>
					</label><br />
					<label><input type="checkbox" name="network_locks[compatibility_mode]" value="1" <?php checked( ! empty( $mail_doctor_locks['compatibility_mode'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
				</td>
			</tr>
		</table>

		<?php submit_button( __( 'Save Network Defaults', 'mail-doctor' ) ); ?>
	</form>

	<h2><?php esc_html_e( 'List-Unsubscribe Defaults', 'mail-doctor' ); ?></h2>
	<table class="form-table">
		<tr>
			<th scope="row"><?php esc_html_e( 'Enable by default', 'mail-doctor' ); ?></th>
			<td>
				<label>
					<input type="checkbox" name="network_settings[list_unsubscribe]" value="1" <?php checked( ! empty( $mail_doctor_defaults['list_unsubscribe'] ) ); ?> />
					<?php esc_html_e( 'Turn on List-Unsubscribe header for new sites.', 'mail-doctor' ); ?>
				</label><br />
				<label><input type="checkbox" name="network_locks[list_unsubscribe]" value="1" <?php checked( ! empty( $mail_doctor_locks['list_unsubscribe'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-list-mailto"><?php esc_html_e( 'Mailto address', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="email" id="omd-network-list-mailto" name="network_settings[list_unsubscribe_mailto]" value="<?php echo esc_attr( $mail_doctor_list_mailto ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[list_unsubscribe_mailto]" value="1" <?php checked( ! empty( $mail_doctor_locks['list_unsubscribe_mailto'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-list-url"><?php esc_html_e( 'Unsubscribe URL', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="url" id="omd-network-list-url" name="network_settings[list_unsubscribe_url]" value="<?php echo esc_attr( $mail_doctor_list_url ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[list_unsubscribe_url]" value="1" <?php checked( ! empty( $mail_doctor_locks['list_unsubscribe_url'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
	</table>

	<h2><?php esc_html_e( 'Alerts & Notifications', 'mail-doctor' ); ?></h2>
	<table class="form-table">
		<tr>
			<th scope="row"><?php esc_html_e( 'Enable alerts by default', 'mail-doctor' ); ?></th>
			<td>
				<label>
					<input type="checkbox" name="network_settings[alerts_enabled]" value="1" <?php checked( $mail_doctor_alerts_enabled ); ?> />
					<?php esc_html_e( 'Turn on failure monitoring for new sites.', 'mail-doctor' ); ?>
				</label><br />
				<label><input type="checkbox" name="network_locks[alerts_enabled]" value="1" <?php checked( ! empty( $mail_doctor_locks['alerts_enabled'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-threshold"><?php esc_html_e( 'Failure threshold (%)', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="number" id="omd-network-alert-threshold" name="network_settings[alert_threshold_percent]" value="<?php echo esc_attr( (string) $mail_doctor_alert_threshold ); ?>" min="1" max="100" />
				<label><input type="checkbox" name="network_locks[alert_threshold_percent]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_threshold_percent'] ) ); ?> /> <?php esc_html_e( 'Lock value', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-window"><?php esc_html_e( 'Evaluation window (minutes)', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="number" id="omd-network-alert-window" name="network_settings[alert_window_minutes]" value="<?php echo esc_attr( (string) $mail_doctor_alert_window ); ?>" min="5" />
				<label><input type="checkbox" name="network_locks[alert_window_minutes]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_window_minutes'] ) ); ?> /> <?php esc_html_e( 'Lock value', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-burst"><?php esc_html_e( 'Burst failures', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="number" id="omd-network-alert-burst" name="network_settings[alert_burst_failures]" value="<?php echo esc_attr( (string) $mail_doctor_alert_burst_failures ); ?>" min="1" />
				<label>&nbsp;<?php esc_html_e( 'within', 'mail-doctor' ); ?>&nbsp;</label>
				<input type="number" id="omd-network-alert-burst-minutes" name="network_settings[alert_burst_minutes]" value="<?php echo esc_attr( (string) $mail_doctor_alert_burst_minutes ); ?>" min="1" />
				<?php esc_html_e( 'minutes', 'mail-doctor' ); ?>
				<label><input type="checkbox" name="network_locks[alert_burst_failures]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_burst_failures'] ) ); ?> /> <?php esc_html_e( 'Lock', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-email"><?php esc_html_e( 'Alert email', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="email" id="omd-network-alert-email" name="network_settings[alert_email]" value="<?php echo esc_attr( $mail_doctor_alert_email ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[alert_email]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_email'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-slack"><?php esc_html_e( 'Slack webhook', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="url" id="omd-network-alert-slack" name="network_settings[alert_slack_webhook]" value="<?php echo esc_attr( $mail_doctor_alert_slack ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[alert_slack_webhook]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_slack_webhook'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-webhook"><?php esc_html_e( 'Generic webhook', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="url" id="omd-network-alert-webhook" name="network_settings[alert_generic_webhook]" value="<?php echo esc_attr( $mail_doctor_alert_webhook ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[alert_generic_webhook]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_generic_webhook'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-alert-cooldown"><?php esc_html_e( 'Cooldown (minutes)', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="number" id="omd-network-alert-cooldown" name="network_settings[alert_cooldown_minutes]" value="<?php echo esc_attr( (string) $mail_doctor_alert_cooldown ); ?>" min="5" />
				<label><input type="checkbox" name="network_locks[alert_cooldown_minutes]" value="1" <?php checked( ! empty( $mail_doctor_locks['alert_cooldown_minutes'] ) ); ?> /> <?php esc_html_e( 'Lock value', 'mail-doctor' ); ?></label>
			</td>
		</tr>
	</table>

	<h2><?php esc_html_e( 'Structured Logging', 'mail-doctor' ); ?></h2>
	<table class="form-table">
		<tr>
			<th scope="row"><?php esc_html_e( 'Enable structured logging', 'mail-doctor' ); ?></th>
			<td>
				<label>
					<input type="checkbox" name="network_settings[structured_logging_enabled]" value="1" <?php checked( $mail_doctor_structured_enabled ); ?> />
					<?php esc_html_e( 'Default to exporting anonymised events for sites in the network.', 'mail-doctor' ); ?>
				</label><br />
				<label><input type="checkbox" name="network_locks[structured_logging_enabled]" value="1" <?php checked( ! empty( $mail_doctor_locks['structured_logging_enabled'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-logging-endpoint"><?php esc_html_e( 'Endpoint URL', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="url" id="omd-network-logging-endpoint" name="network_settings[structured_logging_endpoint]" value="<?php echo esc_attr( $mail_doctor_structured_endpoint ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[structured_logging_endpoint]" value="1" <?php checked( ! empty( $mail_doctor_locks['structured_logging_endpoint'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="omd-network-logging-token"><?php esc_html_e( 'Auth token', 'mail-doctor' ); ?></label></th>
			<td>
				<input type="text" id="omd-network-logging-token" name="network_settings[structured_logging_token]" value="<?php echo esc_attr( $mail_doctor_structured_token ); ?>" class="regular-text" />
				<label><input type="checkbox" name="network_locks[structured_logging_token]" value="1" <?php checked( ! empty( $mail_doctor_locks['structured_logging_token'] ) ); ?> /> <?php esc_html_e( 'Enforce on all sites', 'mail-doctor' ); ?></label>
			</td>
		</tr>
	</table>
	</main>
</div>
