'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select } from '@/components/ui/select'; import { valuationFormSchema, type ValuationFormData, VALUATION_PROPERTY_TYPES, CITIES, } from '@/lib/validations/valuation'; import type { ValuationRequest } from '@/lib/valuation-api'; interface ValuationFormProps { onSubmit: (data: ValuationRequest) => void; isLoading?: boolean; } function toNum(val: string | undefined): number | undefined { if (!val || val === '') return undefined; const n = Number(val); return isNaN(n) ? undefined : n; } export function ValuationForm({ onSubmit, isLoading }: ValuationFormProps) { const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(valuationFormSchema), defaultValues: { city: 'Ho Chi Minh', hasLegalPaper: true, }, }); const handleFormSubmit = (data: ValuationFormData) => { onSubmit({ propertyType: data.propertyType, area: Number(data.area), district: data.district, city: data.city, bedrooms: toNum(data.bedrooms), bathrooms: toNum(data.bathrooms), floors: toNum(data.floors), frontage: toNum(data.frontage), roadWidth: toNum(data.roadWidth), yearBuilt: toNum(data.yearBuilt), hasLegalPaper: data.hasLegalPaper, }); }; return ( Dinh gia bat dong san Nhap thong tin bat dong san de nhan uoc tinh gia tu AI
{/* Row 1: Property type + City */}
{errors.propertyType && (

{errors.propertyType.message}

)}
{errors.city && (

{errors.city.message}

)}
{/* Row 2: District + Area */}
{errors.district && (

{errors.district.message}

)}
{errors.area && (

{errors.area.message}

)}
{/* Row 3: Bedrooms + Bathrooms + Floors */}
{/* Row 4: Frontage + Road Width + Year Built */}
{/* Legal paper checkbox */}
); }