'use client'; declare global { interface Window { grecaptcha: { ready: (cb: () => void) => void; execute: (siteKey: string, options: { action: string }) => Promise; }; } } export function getRecaptchaToken(action: string = 'submit'): Promise { return new Promise((resolve) => { const siteKey = process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY; if (typeof window === 'undefined' || !siteKey || !window.grecaptcha) { resolve(null); return; } try { window.grecaptcha.ready(() => { window.grecaptcha .execute(siteKey, { action }) .then((token: string) => resolve(token)) .catch(() => resolve(null)); }); } catch { resolve(null); } }); }