<?php
// app/Controllers/EngagementController.php

class EngagementController extends Controller {
    public function favorites() {
        $engagement = $this->model('Engagement');
        $favorites = $engagement->getFavorites();

        $this->view('front/favorites', [
            'title' => 'Favorilerim',
            'active' => '',
            'favorites' => $favorites
        ]);
    }

    public function toggleFavorite($id) {
        $engagement = $this->model('Engagement');
        $engagement->toggleFavorite($id);

        $redirect = $_SERVER['HTTP_REFERER'] ?? (BASE_URL . '/favorites');
        header('Location: ' . $redirect);
        exit;
    }

    public function clearFavorites() {
        $engagement = $this->model('Engagement');
        $engagement->clearFavorites();

        header('Location: ' . BASE_URL . '/favorites');
        exit;
    }

    public function compare() {
        $engagement = $this->model('Engagement');
        $compares = $engagement->getCompares();

        $this->view('front/compare', [
            'title' => 'Karşılaştırma',
            'active' => '',
            'compares' => $compares
        ]);
    }

    public function toggleCompare($id) {
        $engagement = $this->model('Engagement');
        $engagement->toggleCompare($id);

        $redirect = $_SERVER['HTTP_REFERER'] ?? (BASE_URL . '/compare');
        header('Location: ' . $redirect);
        exit;
    }

    public function clearCompare() {
        $engagement = $this->model('Engagement');
        $engagement->clearCompares();

        header('Location: ' . BASE_URL . '/compare');
        exit;
    }
}
