import { Eye, EyeOff, Shield, MousePointer, Fingerprint, Crown } from "lucide-react" import { useState } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Button } from "@/components/ui/button" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" import { Slider } from "@/components/ui/slider" import { Badge } from "@/components/ui/badge" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { RecaptchaState, CaptchaProvider, RecaptchaVersion, RecaptchaV2Mode, RecaptchaV3Display, TurnstileAppearance, HcaptchaMode, recaptchaVersions } from "../../config" interface GeneralTabProps { settings: RecaptchaState updateSettings: (key: K, value: RecaptchaState[K]) => void setProvider: (provider: CaptchaProvider) => void setVersion: (version: RecaptchaVersion) => void setV2Mode: (mode: RecaptchaV2Mode) => void setV3Display: (display: RecaptchaV3Display) => void isPro: boolean } // Get plugin URL for local assets const getPluginUrl = () => { return window.swiftCommerceData?.pluginUrl || '/wp-content/plugins/swift-commerce/' } // Provider definitions interface ProviderOption { id: CaptchaProvider name: string logo: string isPro: boolean } const getProviders = (): ProviderOption[] => [ { id: 'google-recaptcha', name: 'Google reCAPTCHA', logo: `${getPluginUrl()}assets/img/icons/google-recaptcha.png`, isPro: false, }, { id: 'cloudflare-turnstile', name: 'Cloudflare Turnstile', logo: `${getPluginUrl()}assets/img/icons/cloudflare-turnstile.png`, isPro: true, }, { id: 'hcaptcha', name: 'hCaptcha', logo: `${getPluginUrl()}assets/img/icons/hcaptcha.png`, isPro: true, }, ] export function GeneralTab({ settings, updateSettings, setProvider, setVersion, setV2Mode, setV3Display, isPro, }: GeneralTabProps) { const [showV2SecretKey, setShowV2SecretKey] = useState(false) const [showV3SecretKey, setShowV3SecretKey] = useState(false) const [showTurnstileSecretKey, setShowTurnstileSecretKey] = useState(false) const [showHcaptchaSecretKey, setShowHcaptchaSecretKey] = useState(false) const hasProvider = settings.provider !== '' // Free users only see Google reCAPTCHA; Pro users see all const providers = getProviders().filter(p => !p.isPro || isPro) return (
{/* Step 1: Choose CAPTCHA Provider */} CAPTCHA Provider Choose which CAPTCHA service to use for bot protection on your site.
{!isPro && (

More providers are available with Pro.

)}
{/* ── Google reCAPTCHA configuration ── */} {hasProvider && settings.provider === 'google-recaptcha' && ( <> {/* Step 2: Choose reCAPTCHA Version */} reCAPTCHA Version Each version uses different API keys. You'll need to{' '} register your site {' '} with the version you choose. setVersion(value as RecaptchaVersion)} className="grid grid-cols-1 sm:grid-cols-2 gap-3" > {/* v2 Option */}
{/* v3 Option */}
{/* Step 3: API Keys */} API Keys Enter your reCAPTCHA {settings.version.toUpperCase()} keys from the{' '} Google reCAPTCHA Admin Console {settings.version === 'v2' && ( <>
updateSettings('v2SiteKey', e.target.value)} />

This key is used to display the reCAPTCHA widget on your site.

updateSettings('v2SecretKey', e.target.value)} className="pr-10" />

This key is used for server-side verification of responses.

)} {settings.version === 'v3' && ( <>
updateSettings('v3SiteKey', e.target.value)} />

This key is used to load the reCAPTCHA script on your site.

updateSettings('v3SecretKey', e.target.value)} className="pr-10" />

This key is used for server-side score verification.

)}
{/* Step 4: Version-specific Configuration */} {settings.version === 'v2' && ( Challenge Type Select how the reCAPTCHA challenge appears to users. setV2Mode(value as RecaptchaV2Mode)} className="grid gap-3" > {recaptchaVersions.v2.modes.map((mode) => (
setV2Mode(mode.id as RecaptchaV2Mode)} >

{mode.description}

))}
)} {settings.version === 'v3' && ( <> {/* V3 Score Threshold */} Score Threshold Set the minimum score required to pass verification. Higher values are stricter.
{settings.v3Threshold.toFixed(1)}
updateSettings('v3Threshold', value)} min={0} max={1} step={0.1} className="w-full" />
0.0 — Likely Bot 0.5 — Recommended 1.0 — Likely Human
Tip: Start with 0.5 and adjust based on your needs. Lower the threshold if legitimate users are being blocked.
{/* V3 Badge Display */} Badge Display Choose how the reCAPTCHA badge is displayed on your site. setV3Display(value as RecaptchaV3Display)} className="grid gap-3" > {recaptchaVersions.v3.displayOptions.map((option) => (
setV3Display(option.id as RecaptchaV3Display)} >

{option.description}

))}
{settings.v3Display === 'hidden' && (
Note: When hiding the badge, you must include reCAPTCHA branding in your privacy policy.
)}
)} )} {/* ── Cloudflare Turnstile configuration (Pro only) ── */} {hasProvider && settings.provider === 'cloudflare-turnstile' && isPro && ( Turnstile API Keys Enter your Cloudflare Turnstile keys from the{' '} Cloudflare Dashboard
updateSettings('turnstileSiteKey', e.target.value)} />

This key is used to render the Turnstile widget on your site.

updateSettings('turnstileSecretKey', e.target.value)} className="pr-10" />

This key is used for server-side verification of responses.

)} {/* ── Turnstile Widget Mode (Pro only) ── */} {hasProvider && settings.provider === 'cloudflare-turnstile' && isPro && ( Widget Mode Choose when the Turnstile widget is visible to users. updateSettings('turnstileAppearance', value as TurnstileAppearance)} className="space-y-3" >

The widget is always shown on the page. Best for transparency.

The widget is only shown when actively solving a challenge.

Invisible to users — the widget only appears if interaction is needed.

)} {/* ── hCaptcha configuration (Pro only) ── */} {hasProvider && settings.provider === 'hcaptcha' && isPro && ( hCaptcha API Keys Enter your hCaptcha keys from the{' '} hCaptcha Dashboard
updateSettings('hcaptchaSiteKey', e.target.value)} />

This key is used to render the hCaptcha widget on your site.

updateSettings('hcaptchaSecretKey', e.target.value)} className="pr-10" />

This key is used for server-side verification of responses.

)} {/* ── hCaptcha Widget Mode (Pro only) ── */} {hasProvider && settings.provider === 'hcaptcha' && isPro && ( Widget Mode Choose how the hCaptcha widget is displayed to users. updateSettings('hcaptchaMode', value as HcaptchaMode)} className="space-y-3" >

Users interact with a visible checkbox widget. Best for transparency.

Runs in the background — only shows a challenge if suspicious activity is detected.

)}
) }