'use client'; import React, { useCallback } from 'react'; import { useRegisterForm } from '../lib/useRegisterForm'; import { formatPhone, normalizeDigits } from '@/shared/lib/formatPhone'; import PhonePrefix from '@/shared/ui/phonePrefix'; import { useTranslations } from 'next-intl'; import { useLoginModal, useRegisterModal } from '@/shared/zustand/auth'; function Field({ id, label, type = 'text', placeholder, value, name, onChange, error, }: { id: string; label: string; type?: string; placeholder?: string; value: string; name: string; onChange: (e: React.ChangeEvent) => void; error?: string; }) { return (
{error && ( {error} )}
); } export function RegisterFormUI() { const [phone, setPhone] = React.useState(''); const t = useTranslations('Auth.Register'); const t_login = useTranslations('Auth.Login'); const tCommon = useTranslations('Common'); const { registerData, errors, loading, success, handleChange, handleOferta, handleSubmit, setItem, } = useRegisterForm(); const toggleLoginModal = useLoginModal((state) => state.toggleLoginModal); const toggleRegisterModal = useRegisterModal( (state) => state.toggleRegisterModal, ); const [isFocused, setIsFocused] = React.useState(false); const handlePhoneChange = useCallback( (e: React.ChangeEvent) => { setPhone(normalizeDigits(e.target.value)); if (normalizeDigits(e.target.value).length === 9) setItem('phone', `998${phone}`); }, [setPhone], ); if (errors) { console.log('Validation errors:', errors); } // ── Success state ────────────────────────────────────── if (success) { return (

{t('successTitle')}

{t('successMessage')}

); } // ── Form ─────────────────────────────────────────────── return (
{/* Header */}

{t('headerLabel')}

{t('title')}

{t('description')}

{/* Name + Surname row */}
{/* Phone */}
setIsFocused(true)} onBlur={() => setIsFocused(false)} className={` w-full rounded-sm border bg-stone-50 py-2.5 pl-30 pr-3.5 text-[0.95rem] font-medium text-stone-900 outline-none placeholder:text-stone-300 transition-all duration-150 ${ isFocused ? 'border-stone-400 ring-2 ring-stone-300/30' : 'border-stone-200 hover:border-stone-300' } `} />
{/* Digit counter / complete hint */}
{phone.length > 0 && t('digitsEntered', { count: phone.length })} {phone.length === 9 && ( {tCommon('complete')} )}
{/* Terms checkbox */}
{errors.oferta && (

{errors.oferta}

)}
{/* Submit */}
{/* Divider */}
{tCommon('or')}
{/* Register hint */}

{t('loginPrompt')}

{ toggleLoginModal(); toggleRegisterModal(); }} className="text-stone-800 hover:cursor-pointer underline underline-offset-2 hover:text-stone-600 transition-colors" > {t_login('title')}

); }