import { PasswordInput } from '@/components/PasswordInput'
import { Label } from '@/components/ui/label'
import RenderError, { ErrorClass } from './Error'
import { FormProps, FormState } from '.'
import { ChangeEvent } from 'react'
import { KeyboardEvent } from 'react';

export default function Password ({
  setIsSubmitting,
  setFormState,
  passwordInputRef,
  error = {},
  formData,
  handleKeyDown,
  isSubmitting = false,
  handleInputChange
}: FormProps) {
  return (
    <div className='gap-6 flex flex-col pb-6'>
      <button
        disabled={isSubmitting}
        onClick={() => {
          if (setIsSubmitting != undefined && setFormState != undefined) {
            setIsSubmitting(false)
            setFormState(FormState.Login)
          }
        }}
        className='disabled:cursor-not-allowed rounded-[8px] hover:bg-[rgb(15, 16, 18) hover:opacity-[0.98]] active:bg-[rgb(30, 31, 32)] p-0 relative border border-[rgba(138,145,158,0.2)]'
      >
        <div className='gap-2 flex flex-row items-center p-4'>
          <div className='relative flex'>
            <div className='h-[32px] w-[32px] relative flex-grow-0 flex-shrink-0 border-transparent flex justify-center items-center overflow-hidden rounded-full'>
              <img
                className='rounded-full object-cover block aspect-[1/1]'
                src='./icon.jpg'
              />
            </div>
          </div>
          <p className='font-cbsans font-semibold leading-6 text-[16px]'>
            {formData.email}
          </p>
        </div>
      </button>
      <div className='flex flex-col gap-1'>
        <Label
          htmlFor='passwd'
          className='font-semibold leading-5 py-1 text-[14px]'
        >
          Password
        </Label>
        <PasswordInput
          id='passwd'
          name='passwd'
          ref={passwordInputRef}
          disabled={isSubmitting}
          className={
            error.password
              ? `${ErrorClass} focus-visible:!ring-0 focus-visible:border-[rgb(rgb(240,97,109)]`
              : ''
          }
          onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => handleKeyDown(event)}
          onChange={(value: ChangeEvent<HTMLInputElement>) =>
            handleInputChange('password', value.target.value)
          }
          value={formData.password || ''}
        />
        <RenderError error={error.password} />
      </div>
      <div className='flex pb-4'>
        <p className='text-[16px] font-cbsans leading-6 text-primary'>
          Forgot password?
        </p>
      </div>
    </div>
  )
}
