buildHeader($componentId); $html .= $this->buildVisibilityGroup($componentId); $html .= $this->buildCredentialsGroup($componentId); $html .= $this->buildBehaviorGroup($componentId); $html .= $this->buildHelpSection(); return $html; } private function buildHeader(string $componentId): string { $html = '
renderer->getFieldValue($componentId, 'visibility', 'is_enabled', false); $html .= $this->buildToggle( 'recaptchaIsEnabled', 'Habilitar reCAPTCHA v3', $isEnabled, 'Activa la proteccion reCAPTCHA en Newsletter y Formulario de Contacto' ); $html .= '
'; $html .= ''; return $html; } private function buildCredentialsGroup(string $componentId): string { $html = '
'; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' Credenciales'; $html .= '
'; $html .= '
'; // Site Key $html .= '
'; $siteKey = $this->renderer->getFieldValue($componentId, 'credentials', 'site_key', ''); $html .= $this->buildTextInput( 'recaptchaSiteKey', 'Site Key (Clave del sitio)', $siteKey, 'Clave publica visible en frontend' ); $html .= '
'; // Secret Key $html .= '
'; $secretKey = $this->renderer->getFieldValue($componentId, 'credentials', 'secret_key', ''); $html .= $this->buildPasswordInput( 'recaptchaSecretKey', 'Secret Key (Clave secreta)', $secretKey, 'Clave privada - NUNCA se expone en frontend' ); $html .= '
'; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' Obtiene tus claves en Google reCAPTCHA Admin. '; $html .= ' Asegurate de seleccionar reCAPTCHA v3.'; $html .= '
'; $html .= '
'; $html .= '
'; return $html; } private function buildBehaviorGroup(string $componentId): string { $html = '
'; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' Comportamiento'; $html .= '
'; $html .= '
'; // Score Threshold $html .= '
'; $threshold = $this->renderer->getFieldValue($componentId, 'behavior', 'score_threshold', '0.5'); $html .= $this->buildSelect( 'recaptchaScoreThreshold', 'Umbral de Score', $threshold, [ '0.3' => '0.3 - Permisivo (menos bloqueos)', '0.5' => '0.5 - Balanceado (recomendado)', '0.7' => '0.7 - Estricto', '0.9' => '0.9 - Muy estricto (mas bloqueos)' ], 'Score minimo para considerar humano (0=bot, 1=humano)' ); $html .= '
'; // Fail Open $html .= '
'; $failOpen = $this->renderer->getFieldValue($componentId, 'behavior', 'fail_open', true); $html .= $this->buildToggle( 'recaptchaFailOpen', 'Permitir si API falla', $failOpen, 'Si Google no responde, permite el envio (recomendado)' ); $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; // Action Newsletter $html .= '
'; $actionNewsletter = $this->renderer->getFieldValue($componentId, 'behavior', 'action_newsletter', 'newsletter_submit'); $html .= $this->buildTextInput( 'recaptchaActionNewsletter', 'Accion Newsletter', $actionNewsletter, 'Identificador para formulario newsletter' ); $html .= '
'; // Action Contact $html .= '
'; $actionContact = $this->renderer->getFieldValue($componentId, 'behavior', 'action_contact', 'contact_submit'); $html .= $this->buildTextInput( 'recaptchaActionContact', 'Accion Contacto', $actionContact, 'Identificador para formulario contacto' ); $html .= '
'; // Log Blocked $html .= '
'; $logBlocked = $this->renderer->getFieldValue($componentId, 'behavior', 'log_blocked', true); $html .= $this->buildToggle( 'recaptchaLogBlocked', 'Registrar bloqueados', $logBlocked, 'Guarda log de intentos bloqueados' ); $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; return $html; } private function buildHelpSection(): string { $html = '
'; $html .= '
'; $html .= '
'; $html .= ' '; $html .= ' Como funciona reCAPTCHA v3'; $html .= '
'; $html .= ' '; $html .= '
'; $html .= '
'; return $html; } private function buildToggle(string $id, string $label, mixed $value, string $helpText = ''): string { $checked = ($value === true || $value === '1' || $value === 1) ? ' checked' : ''; $html = '
'; $html .= '
'; $html .= ' '; $html .= ' '; $html .= '
'; if (!empty($helpText)) { $html .= '
' . esc_html($helpText) . '
'; } $html .= '
'; return $html; } private function buildTextInput(string $id, string $label, mixed $value, string $helpText = ''): string { $value = is_string($value) ? $value : ''; $html = '
'; $html .= ' '; $html .= ' '; if (!empty($helpText)) { $html .= '
' . esc_html($helpText) . '
'; } $html .= '
'; return $html; } private function buildPasswordInput(string $id, string $label, mixed $value, string $helpText = ''): string { $value = is_string($value) ? $value : ''; $html = '
'; $html .= ' '; $html .= '
'; $html .= ' '; $html .= ' '; $html .= '
'; if (!empty($helpText)) { $html .= '
' . esc_html($helpText) . '
'; } $html .= '
'; return $html; } private function buildSelect(string $id, string $label, mixed $value, array $options, string $helpText = ''): string { $value = is_string($value) ? $value : ''; $html = '
'; $html .= ' '; $html .= ' '; if (!empty($helpText)) { $html .= '
' . esc_html($helpText) . '
'; } $html .= '
'; return $html; } }