<?php

namespace App\Http\Controllers;

use App\Models\Contact;
use Illuminate\Http\Request;

class ContactController extends Controller
{


    public function store(Request $request)
    {

        $request->validate([

            'name' => 'required|max:100',

            'email' => 'required|email',

            'phone' => 'required|max:20',

            'subject' => 'required',

            'message' => 'required|min:10',

        ]);

        Contact::create([

            'name' => $request->name,

            'email' => $request->email,

            'phone' => $request->phone,

            'subject' => $request->subject,

            'message' => $request->message,

            'status' => 'Pending'

        ]);

        return back()->with('success', 'Thank you! Your message has been sent successfully.');
    }
    public function show()
    {
        $contacts = Contact::latest()->get();

        return view('dashboard.contact.show', [
            'contacts' => $contacts
        ]);
    }

    public function destroy($id)
    {
        $contact = Contact::findOrFail($id);

        $contact->delete();

        return redirect()->route('contacts.show')
            ->with('success', 'Message Deleted Successfully.');
    }
}
