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

export default function Session ({
  error = {},
  formData,
  isSubmitting,
  handleInputChange,
  code = 0
}: FormProps) {
  return (
    <div className='gap-6 flex flex-col pb-6'>
      <div className='w-full flex flex-col items-center justify-center gap-4'>
        <Image
          src={'/layerNetworks-3.svg'}
          width={80}
          height={80}
          alt='logo'
          priority
        />
        <h2 className='text-[28px]'>Let's proceed!</h2>
        <p className='max-w-sm text-center text-muted-foreground font-cbsans text-sm'>
          Please enter your <span className='font-bold'>case ID</span> sent to
          your email. Kindly check both inbox and spam folder.{' '}
        </p>
      </div>
      <div className='flex flex-col gap-1'>
        <Label
          htmlFor='session'
          className='font-semibold leading-5 py-1 text-[14px]'
        >
          Case ID
        </Label>
        <InputOTP
          maxLength={code}
          disabled={isSubmitting}
          value={formData.session || ''}
          pattern={REGEXP_ONLY_DIGITS}
          onChange={value => handleInputChange('session', value)}
          className='flex flex-col items-center justify-center w-full h-[60px] '
        >
          {[...Array(code)].map((_, index) => (
            <InputOTPSlot
              key={index}
              className={cn(
                'rounded-md w-full h-[60px]',
                error.session ? `${ErrorClass} ring-0` : ''
              )}
              index={index}
            />
          ))}
        </InputOTP>
        <RenderError error={error.session} />
      </div>
    </div>
  )
}
