<?php

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;
use App\Core\Session;

class SearchController extends Controller
{
    public function search(Request $request): Response
    {
        $q = trim($request->get('q', ''));
        $results = [];
        if (strlen($q) >= 2) {
            $postModel = new \App\Models\Post();
            $results = $postModel->search($q);
        }
        $title = 'Search: ' . htmlspecialchars($q);
        return $this->render('search', compact('q', 'results', 'title'));
    }
}
