'use client'; import 'altcha'; import { useEffect, useRef } from 'react'; import { Box, useTheme } from '@mui/material'; import { CONFIG } from '../../config'; import { UseAltchaProps } from './useAltcha'; const getChallengeUrl = () => `${CONFIG.API_URL}/altcha`; const HIDDEN_STATES: AltchaState[] = ['unverified', 'verifying', 'verified']; interface Props extends UseAltchaProps {} const Altcha = ({ state, onStateChange }: Props) => { const theme = useTheme(); const widgetRef = useRef(null); useEffect(() => { const { current: altcha } = widgetRef; if (!altcha) return () => {}; const handler = (e: AltchaStateChangeEvent) => { const { detail } = e; if (!detail) return; onStateChange(detail); }; altcha.addEventListener('statechange', handler as any); return () => { altcha.removeEventListener('statechange', handler as any); }; }, [onStateChange]); const visible = !HIDDEN_STATES.includes(state); return ( ); }; export default Altcha;