import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { TextInput } from '@inkjs/ui';
import { useBridgeWizardStore } from '../bridgeWizardStore.js';
import { useState } from 'react';
import { isAddress } from 'viem';
import { zodAddress } from '../../../../util/schemas.js';
export const EnterRecipient = () => {
    const { submitEnterRecipient } = useBridgeWizardStore();
    const [errorMessage, setErrorMessage] = useState('');
    const [resetKey, setResetKey] = useState(0);
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(Text, { children: "Enter the recipient address:" }) }), _jsx(TextInput, { onSubmit: address => {
                    if (!isAddress(address)) {
                        setErrorMessage('Invalid address: must start with 0x');
                        setResetKey(prev => prev + 1);
                        return;
                    }
                    const result = zodAddress.safeParse(address);
                    if (!result.success) {
                        setErrorMessage(result.error.message);
                        setResetKey(prev => prev + 1);
                        return;
                    }
                    submitEnterRecipient({ recipient: result.data });
                } }, resetKey), errorMessage && (_jsx(Box, { children: _jsx(Text, { color: "red", children: errorMessage ? `❌ ${errorMessage}` : ' ' }) }))] }));
};
