<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Mail\ContactoMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Http;

class mailController extends Controller
{
    public function store(Request $request){

        $message = request()->validate([
            'nombre' => 'required',
            'estado' => 'required',
            'email' => 'required|email',
            'telefono' => 'required|min:10',
            'mensaje' => 'required',
            //'cf-turnstile-response' => 'required'

        ]);
        /*$response = Http::asForm()->post(
                'https://challenges.cloudflare.com/turnstile/v0/siteverify',
                [
                    'secret' => env('TURNSTILE_SECRET_KEY'),
                    'response' => $request->input('cf-turnstile-response'),
                    'remoteip' => $request->ip()
                ]
            );

            $resultado = $response->json();

            if (!$resultado['success']) {
                return back()
                    ->withErrors(['captcha' => 'Error de verificación'])
                    ->withInput();
        }*/

        Mail::to('paola.vazquezr98@gmail.com')->send(new ContactoMail($message));
        return back()->with('success', 'Mensaje enviado correctamente');
    }
}
