import { NextRequest, NextResponse } from 'next/server' import { z } from 'zod' // Validation schema matching sp_25 structure const contactSchema = z.object({ name: z.string().min(1, 'Name is required').trim(), email: z.string().email('Invalid email format').trim(), company: z.string().optional(), service_intrest: z.string().min(1, 'Service interest is required'), message: z.string().min(1, 'Message is required').trim(), }) export async function POST(request: NextRequest) { try { const body = await request.json() // Validate the request body const validatedData = contactSchema.parse(body) // Get client IP address const ip_address = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown' // TODO: Database integration // This would integrate with MongoDB/database in production // For now, just simulate successful submission // TODO: Email notification // This would send email notification in production // const emailData = { // to: 'contact@siliconpin.com', // subject: 'New Contact Form Submission', // body: ` // Name: ${validatedData.name} // Email: ${validatedData.email} // Company: ${validatedData.company || 'Not provided'} // Service Interest: ${validatedData.service_intrest} // Message: ${validatedData.message} // IP Address: ${ip_address} // ` // } // Log the submission (for development) console.log('Contact form submission:', { ...validatedData, ip_address, timestamp: new Date().toISOString() }) // Simulate processing delay await new Promise(resolve => setTimeout(resolve, 500)) return NextResponse.json({ success: true, message: 'Thank you for your message! We\'ll get back to you soon.' }, { status: 200 }) } catch (error) { console.error('Contact form error:', error) if (error instanceof z.ZodError) { return NextResponse.json({ success: false, message: 'Validation failed', errors: error.issues.reduce((acc, err) => { if (err.path.length > 0) { acc[err.path[0] as string] = err.message } return acc }, {} as Record) }, { status: 400 }) } return NextResponse.json({ success: false, message: 'Internal server error. Please try again later.' }, { status: 500 }) } }