'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { motion, AnimatePresence } from 'framer-motion' import { Sparkles, ShieldCheck, Mail, ArrowRight, Loader2, Check, Lock, Building, User, MapPin, Receipt, Palette, Send } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { createClient } from '@/lib/supabase/client' import { completeSetup, testSmtpConfig } from '@/lib/actions/setup' import { ColorThemePicker } from '@/components/admin/ColorThemePicker' export function SetupWizard() { const router = useRouter() const [step, setStep] = useState(1) const [loading, setLoading] = useState(false) const [errorMsg, setErrorMsg] = useState('') const [testSmtpLoading, setTestSmtpLoading] = useState(false) const [testSmtpResult, setTestSmtpResult] = useState<{ success: boolean; message: string } | null>(null) // Step 2: Admin Account const [adminForm, setAdminForm] = useState({ email: '', password: '', confirmPassword: '', firstName: '', lastName: '', }) // Step 3: Firmendaten & Rechnungsadresse const [brandingForm, setBrandingForm] = useState({ companyName: '', street: '', zip: '', city: '', billingStreet: '', billingZip: '', billingCity: '', sameBillingAddress: true, colorScheme: 'modern_blue', primaryColor: '#2563eb', accentColor: '#38bdf8', }) // Step 5: SMTP Config const [smtpForm, setSmtpForm] = useState({ host: '', port: '587', secure: false, user: '', pass: '', }) // Validations const isAdminFormValid = adminForm.email.includes('@') && adminForm.password.length >= 6 && adminForm.password === adminForm.confirmPassword && adminForm.firstName.trim().length > 0 && adminForm.lastName.trim().length > 0 const isCompanyFormValid = brandingForm.companyName.trim().length > 0 && brandingForm.street.trim().length > 0 && brandingForm.zip.trim().length > 0 && brandingForm.city.trim().length > 0 && (brandingForm.sameBillingAddress || (brandingForm.billingStreet.trim().length > 0 && brandingForm.billingZip.trim().length > 0 && brandingForm.billingCity.trim().length > 0)) const handleTestSmtp = async () => { setTestSmtpLoading(true) setTestSmtpResult(null) const res = await testSmtpConfig( { host: smtpForm.host, port: Number(smtpForm.port), secure: smtpForm.secure, user: smtpForm.user, pass: smtpForm.pass, }, adminForm.email ) setTestSmtpResult(res) setTestSmtpLoading(false) } const handleFinishSetup = async () => { if (!isAdminFormValid || !isCompanyFormValid) return setLoading(true) setErrorMsg('') try { const res = await completeSetup( { email: adminForm.email, password: adminForm.password, companyName: brandingForm.companyName, firstName: adminForm.firstName, lastName: adminForm.lastName, }, { street: brandingForm.street, zip: brandingForm.zip, city: brandingForm.city, billingStreet: brandingForm.billingStreet, billingZip: brandingForm.billingZip, billingCity: brandingForm.billingCity, sameBillingAddress: brandingForm.sameBillingAddress, colorScheme: brandingForm.colorScheme, primaryColor: brandingForm.primaryColor, accentColor: brandingForm.accentColor, }, { host: smtpForm.host, port: Number(smtpForm.port), secure: smtpForm.secure, user: smtpForm.user, pass: smtpForm.pass, } ) if (!res.success) { setErrorMsg(res.error || 'Fehler beim Setup.') setLoading(false) return } // Setup erfolgreich – Weiterleitung zur Login-Seite router.push('/auth/login?setup=success') router.refresh() } catch (e: any) { setErrorMsg(e.message || 'Ein unerwarteter Fehler ist aufgetreten.') setLoading(false) } } return (
{/* Background Glow */}
{/* Step Indicator Header */}
B2B Shop made by hephex
{[1, 2, 3, 4, 5].map((s) => (
))}
{/* STEP 1: Willkommen */} {step === 1 && (

B2B Shop made by hephex

Richten Sie Ihren persönlichen Lizenz- und Anfrage-Shop ein. Wir konfigurieren Administrator-Zugang, Firmendaten, Rechnungsadresse und Ihr persönliches Farbschema.

Komplett self-hosted & sicher
9 vordefinierte Farbpaletten + Custom Farbwähler
Lizenzserver-Anbindung
Stammdatenverwaltung
Automatische Adress- & Rechnungsverwaltung
)} {/* STEP 2: Admin-Konto */} {step === 2 && (

Admin-Konto anlegen

Erstellen Sie das erste Administrator-Konto für vollen Systemzugriff.

setAdminForm({ ...adminForm, firstName: e.target.value })} placeholder="Vorname" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, lastName: e.target.value })} placeholder="Nachname" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, email: e.target.value })} placeholder="admin@firma.de" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, password: e.target.value })} placeholder="••••••" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setAdminForm({ ...adminForm, confirmPassword: e.target.value })} placeholder="••••••" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
)} {/* STEP 3: Firmendaten & Rechnungsadresse */} {step === 3 && (

Firmendaten & Adressen

Tragen Sie Ihren Firmennamen, die Anschrift und die Rechnungsadresse ein.

setBrandingForm({ ...brandingForm, companyName: e.target.value })} placeholder="z. B. CASPOS Software GmbH" className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
{/* Anschrift */}
Firmenanschrift
setBrandingForm({ ...brandingForm, street: e.target.value })} placeholder="Musterstraße 12" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600 text-xs" />
setBrandingForm({ ...brandingForm, zip: e.target.value })} placeholder="12345" className="bg-white/5 border-white/10 text-white text-xs" />
setBrandingForm({ ...brandingForm, city: e.target.value })} placeholder="Musterstadt" className="bg-white/5 border-white/10 text-white text-xs" />
{/* Rechnungsadresse */}
Rechnungsadresse
{!brandingForm.sameBillingAddress && (
setBrandingForm({ ...brandingForm, billingStreet: e.target.value }) } placeholder="Rechnungsstraße 45" className="bg-white/5 border-white/10 text-white text-xs" />
setBrandingForm({ ...brandingForm, billingZip: e.target.value }) } placeholder="54321" className="bg-white/5 border-white/10 text-white text-xs" />
setBrandingForm({ ...brandingForm, billingCity: e.target.value }) } placeholder="Rechnungsstadt" className="bg-white/5 border-white/10 text-white text-xs" />
)}
)} {/* STEP 4: Farbschema & Live-Vorschau */} {step === 4 && (

Farbschema & Webshop Styling

Wählen Sie aus 9 vorgegebenen Farbpaletten oder erstellen Sie eine eigene Farbkombination mit Live-Vorschau.

setBrandingForm({ ...brandingForm, colorScheme: scheme, primaryColor: primary, accentColor: accent, }) } />
)} {/* STEP 5: SMTP Mailserver */} {step === 5 && (

SMTP-Mailserver

Optional

Tragen Sie Ihre Mailserver-Daten ein oder überspringen Sie diesen Schritt. Sie können die Einstellungen jederzeit im Admin-Bereich anpassen.

{errorMsg && (
{errorMsg}
)}
setSmtpForm({ ...smtpForm, host: e.target.value })} placeholder="smtp.domain.de" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, port: e.target.value })} placeholder="587" className="bg-white/5 border-white/10 text-white" />
setSmtpForm({ ...smtpForm, user: e.target.value })} placeholder="mail@domain.de" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, pass: e.target.value })} placeholder="••••••••••••" className="bg-white/5 border-white/10 text-white placeholder:text-slate-600" />
setSmtpForm({ ...smtpForm, secure: e.target.checked })} className="w-4 h-4 rounded border-slate-700 bg-white/5 text-blue-500 focus:ring-0 focus:ring-offset-0" />
{testSmtpResult && (
{testSmtpResult.message}
)}
)}
) }