'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Button, Input, Label, Card, CardContent, CardHeader, CardTitle, cn } from '@horux/shared-ui'; import { useAuthStore } from '@/stores/auth-store'; import { apiClient } from '@/lib/api/client'; import { CheckCircle2, Server, Cloud, ArrowLeft, Clock, Building, Sparkles } from 'lucide-react'; type VerticalProfile = 'CONTABLE' | 'JURIDICO' | 'ARQUITECTURA'; type PlanType = 'trial' | 'mi_empresa' | 'mi_empresa_plus' | 'business_control' | 'business_cloud'; export default function RegisterDespachoPage() { const router = useRouter(); const { setUser, setTokens } = useAuthStore(); const [step, setStep] = useState(1); const [verticalProfile, setVerticalProfile] = useState(null); const [selectedPlan, setSelectedPlan] = useState(null); // Default 'annual' — sesgo intencional al cash-flow del negocio (10 meses // = 17% descuento para el cliente, año completo cobrado upfront para nosotros). const [billingFrequency, setBillingFrequency] = useState<'monthly' | 'annual'>('annual'); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [form, setForm] = useState({ despachoNombre: '', ownerNombre: '', ownerEmail: '', ownerPassword: '', acceptedTerms: false, }); const handleChange = (field: string) => (e: React.ChangeEvent) => { setForm((prev) => ({ ...prev, [field]: e.target.value })); setError(''); }; const handleSubmit = async () => { if (!form.acceptedTerms) { setError('Debes aceptar los términos y condiciones'); return; } if (!verticalProfile || !selectedPlan) { setError('Completa todos los pasos'); return; } setLoading(true); setError(''); try { const { data } = await apiClient.post('/despachos/signup', { despacho: { nombre: form.despachoNombre, verticalProfile, plan: selectedPlan, // Solo mi_empresa(+) acepta monthly; el backend ignora frequency // para los demás planes. Mandamos siempre el state para coherencia. frequency: billingFrequency, }, owner: { nombre: form.ownerNombre, email: form.ownerEmail, password: form.ownerPassword, }, }); setTokens(data.accessToken, data.refreshToken); setUser(data.user); // If paid plan with payment URL, redirect to MercadoPago if (data.paymentUrl) { window.location.href = data.paymentUrl; } else { router.push('/onboarding'); } } catch (err: any) { setError(err.response?.data?.message || 'Error al registrar el despacho'); setStep(1); } finally { setLoading(false); } }; // =================== STEP 1: Registration Form =================== if (step === 1) { const canProceed = form.despachoNombre && form.ownerNombre && form.ownerEmail && form.ownerPassword.length >= 10 && form.acceptedTerms; return (
1 2 3
Crea tu cuenta

Plataforma para despachos profesionales

setForm((p) => ({ ...p, acceptedTerms: e.target.checked }))} className="mt-1" />
{error &&

{error}

}

¿Ya tienes cuenta? Inicia sesión

); } // =================== STEP 2: Vertical Selection =================== if (step === 2) { return (
2 3

¿Qué tipo de despacho eres?

Selecciona tu área profesional

⚖️

Jurídico

Próximamente

🏗️

Arquitectura

Próximamente

); } // =================== STEP 3: Subscription Selection =================== return (
3

Elige tu plan

Empieza con el trial gratuito de 30 días o contrata un plan directo.

{/* Toggle facturación mensual / anual (afecta solo Mi Empresa y Mi Empresa+) */}
{/* Trial Gratuito */} setSelectedPlan('trial')} >
Trial Gratuito

Prueba sin compromiso

$0

30 días

Sin tarjeta

Hasta 3 RFCs
1 usuario
Todas las funcionalidades
BD en la nube
{/* Mi Empresa */} setSelectedPlan('mi_empresa')} >
Mi Empresa

Para 1 contribuyente

{billingFrequency === 'annual' ? ( <>
$5,800

por año

Equivale a 10 meses

) : ( <>
$580

mensual

o $5,800/año (10 meses)

)}
1 RFC
3 usuarios
50 timbres/mes
BD en la nube
{/* Mi Empresa + */} setSelectedPlan('mi_empresa_plus')} >
Mi Empresa +

Con IA + API

{billingFrequency === 'annual' ? ( <>
$9,000

por año

Equivale a 10 meses

) : ( <>
$900

mensual

o $9,000/año (10 meses)

)}
Todo Mi Empresa
Lolita IA Fiscal
API de integración
SAT incremental
{/* Business Control */} setSelectedPlan('business_control')} >
Más popular
Business Control

Despachos contables

$25,850

por año (IVA inc.)

+ $45/mes por RFC extra

100 RFCs incluidos
Usuarios ilimitados
BD en tu servidor
Servidor backup
API de integración
SAT incremental
{/* Enterprise (business_cloud) */} setSelectedPlan('business_cloud')} >
Enterprise

Despachos de alto volumen

$43,000

por año (IVA inc.)

+ $45/mes por RFC extra

100 RFCs incluidos
3M CFDIs por contribuyente
Usuarios ilimitados
BD en tu servidor
Servidor backup
SAT incremental + API
{error &&

{error}

}
); }