<?php
namespace Tshen\Controllers;
use Tshen\Database; use function Tshen\view; use function Tshen\redirect;

class ContactController {
    public function index() { return view('contact/index', ['title'=>'Contact']); }
    public function send() {
        if (!\Tshen\csrf_check()) { \Tshen\flash('error','Invalid request.'); return redirect('/contact'); }
        $name = $_POST['name'] ?? ''; $email = $_POST['email'] ?? ''; $message = $_POST['message'] ?? '';
        if ($name && $email && $message) {
            Database::run('INSERT INTO messages (name,email,message) VALUES (?,?,?)', [$name,$email,$message]);
        }
        \Tshen\flash('success','Message sent.');
        redirect('/contact');
    }
}