'use client' import { useState } from 'react' import { CharacterSelect, type CharOption } from '@/components/CharacterSelect' /** Campo con ojo para mostrar/ocultar (contraseña / token). */ function SecretInput({ id, value, onChange, placeholder, maxLength, toggleClass, }: { id: string value: string onChange: (v: string) => void placeholder: string maxLength: number toggleClass: string }) { const [show, setShow] = useState(false) return ( <> onChange(e.target.value)} placeholder={placeholder} required />{' '} setShow((s) => !s)} /> ) } export function TransferForm({ characters, price }: { characters: CharOption[]; price: number }) { const [character, setCharacter] = useState('') const [destination, setDestination] = useState('') const [password, setPassword] = useState('') const [token, setToken] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState(null) async function handleSubmit(e: React.FormEvent) { e.preventDefault() if (busy || !character || !destination.trim() || !password || !token.trim()) return if (!window.confirm(`¿Estás seguro de transferir el personaje "${character}" a la cuenta ${destination.trim()} por ${price} € (SumUp)?`)) return setBusy(true) setError(null) try { const res = await fetch('/api/character/transfer/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'same-origin', body: JSON.stringify({ character, destination_account: destination.trim(), password, security_token: token.trim(), provider: 'sumup', }), }) const data: { success?: boolean; url?: string; message?: string } = await res.json() if (data.success && data.url) window.location.href = data.url else { setError(data.message || 'No se pudo iniciar la transferencia. Inténtalo de nuevo.') setBusy(false) } } catch { setError('Algo ha salido mal. Inténtalo más tarde.') setBusy(false) } } if (characters.length === 0) return

No tienes personajes disponibles.

return (

setDestination(e.target.value)} required />



{error && {error}}
) }