<?php

namespace App\Http\Controllers;

use App\Models\ContactMessage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class ContactController extends Controller
{
    public function contact_en()
    {
        return view('frontend.contact-en');
    }

    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'fname'   => 'required|string|max:255',
            'lname'   => 'required|string|max:255',
            'email'   => 'required|email|max:255',
            'phone'   => 'required|string|max:15',
            'message' => 'nullable|string',
        ]);

        if ($validator->fails()) {
            return redirect()
                ->back()
                ->withErrors($validator)
                ->withInput();
        }

        ContactMessage::create($validator->validated());

        return redirect()
            ->back()
            ->with('success', 'Thank you! Your message has been submitted successfully.');
    }
}