<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

$gcaptcha_data = SftcyWordformBase::wordform_settings_page_grecaptcha_config();
?>
<div class="wrap sc-wordform-setting-page-gcaptcha-tab-table-wrapper">
	<div class="sc-wordform-general-toolbar sc-wordform-upload-toolbar">
		<div class="sc-wordform-general-toolbar-copy">
			<label><?php esc_html_e( 'Google reCaptcha Settings', 'wordform-pro' ); ?></label>
			<p><?php esc_html_e( 'Use the correct key type and version so Google reCaptcha can render and verify successfully on your forms.', 'wordform-pro' ); ?></p>
		</div>
	</div>

	<div class="google-recaptcha-create-hints-div-wrapper">
		<i class="fa-solid fa-circle-info"></i>
		<?php echo wp_kses_post( __( 'If you do not have Google reCaptcha keys yet then you can <a href="https://www.google.com/recaptcha/admin/create" target="_blank" rel="noopener noreferrer">create free Google reCaptcha keys</a>. You can also <a href="https://cloud.google.com/recaptcha-enterprise/docs/keys" target="_blank" rel="noopener noreferrer">check different key types</a>. Please use the correct reCaptcha type and version with your keys so it works properly in your forms.', 'wordform-pro' ) ); ?>
	</div>

	<form id="scWordformSettingsgCaptchaTabForm" method="post">
		<table class="sc-wordform-general-settings-table wordform-grecaptcha-settings-tbl">
			<tbody>
				<tr class="sc-wordform-general-section-row">
					<td colspan="2">
						<div class="sc-wordform-general-section-head">
							<h4><?php esc_html_e( 'reCaptcha Type And Version', 'wordform-pro' ); ?></h4>
							<p><?php esc_html_e( 'Choose the Google reCaptcha key family and challenge mode that matches the keys you generated.', 'wordform-pro' ); ?></p>
						</div>
					</td>
				</tr>

				<tr class="sc-wordform-general-setting-row">
					<td class="sc-wordform-settings-general-tab-label-td sc-wordform-settings-gcaptcha-tab-label-td">
						<h4><?php esc_html_e( 'Google reCaptcha Type', 'wordform-pro' ); ?></h4>
					</td>
					<td>
						<select id="scWordformSelectreCaptchaKeysType" name="wordform-gcaptcha-type">
							<option value="classic" <?php selected( $gcaptcha_data['gcaptcha-type'], 'classic' ); ?>><?php esc_html_e( 'Classic', 'wordform-pro' ); ?></option>
							<option value="enterprise" <?php selected( $gcaptcha_data['gcaptcha-type'], 'enterprise' ); ?>><?php esc_html_e( 'Enterprise', 'wordform-pro' ); ?></option>
						</select>
						<small><?php esc_html_e( 'Choose Classic or Enterprise based on the keys you generated in Google.', 'wordform-pro' ); ?></small>
					</td>
				</tr>

				<tr class="sc-wordform-general-setting-row">
					<td class="sc-wordform-settings-general-tab-label-td sc-wordform-settings-gcaptcha-tab-label-td">
						<h4><?php esc_html_e( 'Google reCaptcha Version', 'wordform-pro' ); ?></h4>
					</td>
					<td>
						<div class="sc-wordform-general-radio-inline">
							<label>
								<input type="radio" value="v2" name="wordform-gcaptcha-version" class="wordform-gcaptcha-version" <?php checked( 'v2', $gcaptcha_data['gcaptcha-version'], true ); ?> />
								<?php esc_html_e( 'Challenge (V2)', 'wordform-pro' ); ?>
							</label>
							<label>
								<input type="radio" value="v3" name="wordform-gcaptcha-version" class="wordform-gcaptcha-version" <?php checked( 'v3', $gcaptcha_data['gcaptcha-version'], true ); ?> />
								<?php esc_html_e( 'Score Based (V3)', 'wordform-pro' ); ?>
							</label>
						</div>
						<small><?php esc_html_e( 'V2 shows a visible challenge widget. V3 scores requests in the background.', 'wordform-pro' ); ?></small>
					</td>
				</tr>

				<tr class="sc-wordform-general-section-row">
					<td colspan="2">
						<div class="sc-wordform-general-section-head">
							<h4><?php esc_html_e( 'API Keys And Theme', 'wordform-pro' ); ?></h4>
							<p><?php esc_html_e( 'Add the site and secret keys from Google, then choose the widget theme for visible challenges.', 'wordform-pro' ); ?></p>
						</div>
					</td>
				</tr>

				<tr class="sc-wordform-general-setting-row">
					<td class="sc-wordform-settings-general-tab-label-td sc-wordform-settings-gcaptcha-tab-label-td">
						<h4><i class="fa-solid fa-key"></i><?php esc_html_e( 'Site Key', 'wordform-pro' ); ?></h4>
					</td>
					<td>
						<input type="text" value="<?php echo esc_attr( $gcaptcha_data['gcaptcha-site-key'] ); ?>" name="wordform-gcaptcha-site-key" class="wordform-gcaptcha-site-key" placeholder="Site Key" />
					</td>
				</tr>

				<tr class="sc-wordform-general-setting-row">
					<td class="sc-wordform-settings-general-tab-label-td sc-wordform-settings-gcaptcha-tab-label-td">
						<h4><i class="fa-solid fa-key"></i><?php esc_html_e( 'Secret Key', 'wordform-pro' ); ?></h4>
					</td>
					<td>
						<input type="text" value="<?php echo esc_attr( $gcaptcha_data['gcaptcha-secret-key'] ); ?>" name="wordform-gcaptcha-secret-key" class="wordform-gcaptcha-secret-key" placeholder="Secret Key" />
					</td>
				</tr>

				<tr class="sc-wordform-general-setting-row">
					<td class="sc-wordform-settings-general-tab-label-td sc-wordform-settings-gcaptcha-tab-label-td">
						<h4><?php esc_html_e( 'Google reCaptcha Theme', 'wordform-pro' ); ?></h4>
					</td>
					<td>
						<div class="sc-wordform-general-radio-inline">
							<label>
								<input type="radio" value="light" name="wordform-gcaptcha-theme" class="wordform-gcaptcha-theme" <?php checked( 'light', $gcaptcha_data['gcaptcha-theme'], true ); ?> />
								<?php esc_html_e( 'Light', 'wordform-pro' ); ?>
							</label>
							<label>
								<input type="radio" value="dark" name="wordform-gcaptcha-theme" class="wordform-gcaptcha-theme" <?php checked( 'dark', $gcaptcha_data['gcaptcha-theme'], true ); ?> />
								<?php esc_html_e( 'Dark', 'wordform-pro' ); ?>
							</label>
						</div>
					</td>
				</tr>
			</tbody>
		</table>

		<div class="sc-wordform-general-actions">
			<button type="submit" class="button button-primary button-large"><?php esc_html_e( 'Save', 'wordform-pro' ); ?></button>
			<span class="sc-wordform-gcaptcha-message-settings-info"></span>
		</div>
	</form>
</div>
