<?php
/**
 * Basic Forms - Form Settings Meta Box
 *
 * @package BasicForms
 * @since 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<p>
	<label><strong><?php esc_html_e( 'Email Recipient:', 'wppowersuite-lite' ); ?></strong></label><br>
	<input type="email" name="form_settings[recipient]" value="<?php echo esc_attr( $settings['recipient'] ?? '' ); ?>" class="widefat">
</p>
<p>
	<label><strong><?php esc_html_e( 'Email Subject:', 'wppowersuite-lite' ); ?></strong></label><br>
	<input type="text" name="form_settings[subject]" value="<?php echo esc_attr( $settings['subject'] ?? '' ); ?>" class="widefat">
</p>
<p>
	<label><strong><?php esc_html_e( 'Success Message:', 'wppowersuite-lite' ); ?></strong></label><br>
	<textarea name="form_settings[success_message]" class="widefat" rows="3"><?php echo esc_textarea( $settings['success_message'] ?? '' ); ?></textarea>
	<small><?php esc_html_e( 'Shown after successful submission (if no redirect)', 'wppowersuite-lite' ); ?></small>
</p>
<p>
	<label><strong><?php esc_html_e( 'Redirect URL (optional):', 'wppowersuite-lite' ); ?></strong></label><br>
	<input type="url" name="form_settings[redirect_url]" value="<?php echo esc_attr( $settings['redirect_url'] ?? '' ); ?>" class="widefat" placeholder="https://example.com/thank-you">
</p>
<p>
	<label><strong><?php esc_html_e( 'Submit Button Text:', 'wppowersuite-lite' ); ?></strong></label><br>
	<input type="text" name="form_settings[submit_button_text]" value="<?php echo esc_attr( $settings['submit_button_text'] ?? '' ); ?>" class="widefat">
</p>
<?php
$captcha_provider = $settings['captcha_provider'] ?? null;
if ( $captcha_provider === null && ! empty( $settings['enable_spam_protection'] ) ) {
	$captcha_provider = 'simple';
}
$captcha_provider = $captcha_provider ?? '';
?>
<p>
	<label><strong><?php esc_html_e( 'Spam Protection:', 'wppowersuite-lite' ); ?></strong></label><br>
	<select name="form_settings[captcha_provider]" class="widefat">
		<option value="" <?php selected( $captcha_provider, '' ); ?>><?php esc_html_e( 'None (honeypot + timing only)', 'wppowersuite-lite' ); ?></option>
		<option value="simple" <?php selected( $captcha_provider, 'simple' ); ?>><?php esc_html_e( 'Simple CAPTCHA', 'wppowersuite-lite' ); ?></option>
		<option value="google" <?php selected( $captcha_provider, 'google' ); ?>><?php esc_html_e( 'Google reCAPTCHA', 'wppowersuite-lite' ); ?></option>
		<option value="turnstile" <?php selected( $captcha_provider, 'turnstile' ); ?>><?php esc_html_e( 'Cloudflare Turnstile', 'wppowersuite-lite' ); ?></option>
	</select>
</p>
<p>
	<label>
		<input type="checkbox" name="form_settings[enable_autoreply]" value="1" <?php checked( ! empty( $settings['enable_autoreply'] ) ); ?> id="wpps-bf-enable-autoreply">
		<?php esc_html_e( 'Send auto-reply email', 'wppowersuite-lite' ); ?>
	</label>
</p>
<div id="wpps-bf-autoreply-settings" style="<?php echo empty( $settings['enable_autoreply'] ) ? 'display:none' : ''; ?>">
	<p>
		<label><strong><?php esc_html_e( 'Auto-reply Subject:', 'wppowersuite-lite' ); ?></strong></label><br>
		<input type="text" name="form_settings[autoreply_subject]" value="<?php echo esc_attr( $settings['autoreply_subject'] ?? '' ); ?>" class="widefat">
	</p>
	<p>
		<label><strong><?php esc_html_e( 'Auto-reply Message:', 'wppowersuite-lite' ); ?></strong></label><br>
		<textarea name="form_settings[autoreply_message]" class="widefat" rows="4"><?php echo esc_textarea( $settings['autoreply_message'] ?? '' ); ?></textarea>
	</p>
</div>
<?php
\WP_PowerSuite\Core\InlineAssets::script(
	'wpps-bf-autoreply-toggle',
	'jQuery(function($){$(\'#wpps-bf-enable-autoreply\').on(\'change\',function(){$(\'#wpps-bf-autoreply-settings\').toggle(this.checked)});});'
);
?>
