<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Contact;

class ContactController extends Controller
{
    public function index()
    {
        $filter = request('filter', 'all');
        $query = Contact::latest();

        if ($filter === 'unread') {
            $query->where('is_read', false);
        } elseif ($filter === 'read') {
            $query->where('is_read', true);
        }

        $contacts = $query->paginate(15);

        return view('admin.contacts.index', compact('contacts', 'filter'));
    }

    public function show(Contact $contact)
    {
        $contact->update(['is_read' => true]);

        return view('admin.contacts.show', compact('contact'));
    }

    public function destroy(Contact $contact)
    {
        $contact->delete();

        return redirect()->route('admin.contacts.index')->with('success', 'Message supprimé !');
    }
}
