<?php

namespace App\Http\Controllers\Member;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use App\Mail\ContactFormMail;
use Illuminate\Http\Request;



class ContactController extends Controller
{
  

    public function sendContact(Request $request)
    {
        $validated = $request->validate([
			'name' => 'required',
			'email' => 'required|email',
			'message' => 'required',
			'subject' => 'nullable',
		]);
		

        $adminSetting = DB::table('settings')
            ->where('key', 'contact_email') 
            ->orWhere('key', 'admin_email')
            ->first();
		$adminEmail = $adminSetting ? $adminSetting->value : config('mail.from.address');

        if ($adminEmail) {
           @Mail::to($adminEmail)->send(new ContactFormMail($validated));
        }

        return redirect()->back()->with('success', 'Your Message has been submitted successfully! Our team will review it shortly.');
    }
}
