"use server"

export async function sendEmail(formData: FormData) {
  try {
    const name = formData.get("name") as string
    const email = formData.get("email") as string
    const message = formData.get("message") as string

    // Validate form data
    if (!name || !email || !message) {
      return {
        success: false,
        message: "Please fill out all fields.",
      }
    }

    // Here you would typically use an email service like SendGrid, Mailgun, etc.
    // For now, we'll simulate a successful email send

    // Example of how you would use a service like Nodemailer or SendGrid:
    /*
    const response = await fetch('https://api.sendgrid.com/v3/mail/send', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.SENDGRID_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        personalizations: [{ to: [{ email: 'contact@ameliapetrie.com' }] }],
        from: { email: email },
        subject: `Contact Form: Message from ${name}`,
        content: [{ type: 'text/plain', value: message }]
      })
    })
    */

    // For demo purposes, we'll just return success
    return {
      success: true,
      message: "Your message has been sent! I'll get back to you soon.",
    }
  } catch (error) {
    console.error("Error sending email:", error)
    return {
      success: false,
      message: "Failed to send message. Please try again later.",
    }
  }
}

