<?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:', 'wp-powersuite' ); ?></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:', 'wp-powersuite' ); ?></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:', 'wp-powersuite' ); ?></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)', 'wp-powersuite' ); ?></small>
</p>
<p>
	<label><strong><?php esc_html_e( 'Redirect URL (optional):', 'wp-powersuite' ); ?></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:', 'wp-powersuite' ); ?></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:', 'wp-powersuite' ); ?></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)', 'wp-powersuite' ); ?></option>
		<option value="simple" <?php selected( $captcha_provider, 'simple' ); ?>><?php esc_html_e( 'Simple CAPTCHA', 'wp-powersuite' ); ?></option>
		<option value="google" <?php selected( $captcha_provider, 'google' ); ?>><?php esc_html_e( 'Google reCAPTCHA', 'wp-powersuite' ); ?></option>
		<option value="turnstile" <?php selected( $captcha_provider, 'turnstile' ); ?>><?php esc_html_e( 'Cloudflare Turnstile', 'wp-powersuite' ); ?></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', 'wp-powersuite' ); ?>
	</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:', 'wp-powersuite' ); ?></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:', 'wp-powersuite' ); ?></strong></label><br>
		<textarea name="form_settings[autoreply_message]" class="widefat" rows="4"><?php echo esc_textarea( $settings['autoreply_message'] ?? '' ); ?></textarea>
	</p>
</div>
<script>jQuery(function($){$('#wpps-bf-enable-autoreply').on('change',function(){$('#wpps-bf-autoreply-settings').toggle(this.checked)});});</script>
