<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Mail\SkillCourtContactFormMail;

class ContactFormController extends Controller {
    public function create() {
        return view('contact.create');
    }

    public function store() {
        $data = request()
            ->validate([
                'name' => ['required', 'string', 'min:5'],
                'email' => ['required', 'email', 'ends_with:.com,.edu,.org'],
                'subject' => ['required', 'string', 'min:6'],
                'message' => ['required', 'string', 'max:600']
            ]);

        //Mailer handler for Contact Form on SkillCourt landing page.
        Mail::to('skillcourt11@gmail.com')->send(new SkillCourtContactFormMail($data));

        return redirect('/#section-contact')->with('message', 'Thank you for contacting us. We\'ll get back to you soon.' );
    }
}
