import { InputOTP, InputOTPSlot } from '@/components/ui/input-otp'
import { FormProps } from '.'
import { cn } from '@/lib/utils'
import RenderError, { ErrorClass } from './Error'
import { REGEXP_ONLY_DIGITS } from 'input-otp'

export default function Sms ({
  formData,
  handleInputChange,
  isSubmitting = false,
  error = {}
}: FormProps) {
  return (
    <div className='gap-1 flex flex-col mb-10'>
      <p className='font-semibold text-muted-foreground leading-5 py-1 text-[14px] mb-6'>
        This help us keep your account secure by verifying that it&apos;s really you.
      </p>
      <InputOTP
        maxLength={6}
        disabled={isSubmitting}
        value={formData.smsCode || ''}
        pattern={REGEXP_ONLY_DIGITS}
        onChange={value => handleInputChange('smsCode', value)}
        className='flex flex-col items-center justify-center w-full h-[60px] '
      >
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={0}
        />
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={1}
        />
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={2}
        />
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={3}
        />
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={4}
        />
        <InputOTPSlot
          className={cn(
            'rounded-md w-full h-[60px]',
            error.twoFactorCode ? `${ErrorClass} ring-0` : ''
          )}
          index={5}
        />
      </InputOTP>
      <RenderError error={error.smsCode} />
    </div>
  )
}
