<?php

namespace Core\App\Controllers;

use Core\App\Models\ProductModel;
use Core\App\Models\ThemeSettings;
use Core\System\Response;



class ThemeProductController
{
    protected ProductModel $products;
    protected ThemeSettings $settings;

    public function __construct()
    {
        $this->products = new ProductModel();
        $this->settings = new ThemeSettings();
    }

    /**
     * Display product selector page
     */
    public function activeProduct()
    {
        $items = $this->products->getAll();
        $current = $this->settings->get('active_product_id', null);

        view_admin('theme/active_product', [
            'products'     => $items,
            'current'      => $current
        ]);
    }

    /**
     * Set selected product as active
     */
    public function setActiveProduct($id)
    {
        \Core\System\Csrf::check();
        $this->settings->set('active_product_id', (int)$id);

        return Response::redirect('/admin/theme/active-product');
    }
}
