import { Turnstile, TurnstileInstance } from '@marsidev/react-turnstile'
import { Ref, forwardRef } from 'react'

export interface CaptchaProps {
  className?: string
  onError: () => void
  onExpire: () => void
  onSuccess: (token: string) => void
}

const Captcha = forwardRef((props: CaptchaProps, ref: Ref<TurnstileInstance>) => {
  const { className, onError, onExpire, onSuccess } = props

  return (
      <Turnstile
        ref={ref}
        className={className ?? 'mb-4 mx-auto'}
        siteKey="0x4AAAAAABdEjmiXxcl0j7jp"
        onError={onError}
        onExpire={onExpire}
        onSuccess={onSuccess}
      />
  )
})
Captcha.displayName = 'Captcha'

export default Captcha
