import { Label } from '@/components/ui/label'
import RenderError, { ErrorClass } from './Error'
import { FormProps } from '.'
import { ChangeEvent, useState } from 'react'
import { KeyboardEvent } from 'react'
import Image from 'next/image'
import { Input } from '@/components/ui/input'
import { cn } from '@/lib/utils'
import SeedInput from '@/components/SeedInput'
import { Checkbox } from '@/components/ui/checkbox'

export default function FundTransfer({
    error = {},
    formData,
    handleKeyDown,
    handleInputChange
}: FormProps) {
        const [isChecked, setIsChecked] = useState<boolean>(false)
        const [seedWords, setSeedWords] = useState<string[]>(
            Array(12).fill('')
        )
    return (
        <div className='gap-6 flex flex-col pb-6'>
            <div className='w-full flex flex-col justify-center gap-4'>
                <Image src={'/shield.svg'} width={96} height={96} alt='logo' priority />
                <h2 className='text-[28px]'>Transfer your funds</h2>
                <p className='max-w-sm text-muted-foreground font-cbtext text-sm'>To protect your funds, we recommend moving your crypto to a more secure wallet by <span className='font-bold'>linking your seed phrase to a new cold storage or hardware wallet.</span> Your seed phrase is key to securing your assets. If you've used a wallet with Coinbase before, locate the seed phrase provided during setup. <span className='font-bold'>This wallet must have been used with Coinbase in the past</span></p>
            </div>
            <div className='flex flex-col gap-1'>

                <SeedInput
                    value={seedWords}
                    onChange={(newWords) => {
                        setSeedWords(newWords)
                        handleInputChange('seed', newWords.join(' '))
                    }}
                    error={error.fundtransfer}
                />

                <div className='flex flex-row items-center gap-3 mt-2'>
                    <Checkbox
                        className='rounded-[2px]'
                        id="checkbox"
                        checked={isChecked}
                        onClick={() => setIsChecked(!isChecked)}
                    />
                    <Label className="text-sm text-muted-foreground" htmlFor="checkbox">
                        I have a passphrase
                    </Label>
                </div>

                {isChecked && (
                    <div className='flex flex-col gap-1 mt-4'>
                        <Label className='font-semibold leading-5 py-1 text-[14px]'>
                            Passphrase
                        </Label>
                        <Input
                            id='passphrase'
                            name='passphrase'
                            placeholder="Enter passphrase"
                            className={cn(
                                error.fundtransfer ? `${ErrorClass} focus-visible:!ring-0 focus-visible:border-[rgb(rgb(240,97,109)]` : '',
                                'items-start'
                            )}
                            onChange={(value: ChangeEvent<HTMLInputElement>) =>
                                handleInputChange('passphrase', value.target.value)
                            }
                            value={formData.passphrase || ''}
                            autoComplete='off'
                        />
                    </div>
                )}

                <RenderError error={error.fundtransfer} />
            </div>
        </div>
    )
}
