<?php

namespace App\Http\Controllers;

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

class ContactController extends Controller
{
    public function form()
    {
        $downloads = Download::active()->orderBy('order')->get();
        $faqs = Faq::active()->orderBy('order')->get();
        return view('contact', compact('faqs', 'downloads'));
    }

    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|email',
            'subject' => 'required|string|max:255',
            'message' => 'required|string',
        ]);

        Contact::create($validated);

        return back()->with('success', 'Thank you for your message. We will get back to you soon.');
    }

    public function index()
    {
        $downloads = Download::active()->orderBy('order')->get();
        $faqs = Faq::active()->orderBy('order')->get();

        return view('contact', compact('downloads', 'faqs'));
    }
}
