<?php

declare(strict_types=1);

namespace FatBottom\Controllers;

use FatBottom\Core\Auth;
use FatBottom\Core\Config;
use FatBottom\Core\Http;
use FatBottom\Services\CartService;

abstract class BaseController
{
    public function __construct(
        protected readonly Config $config,
        protected readonly Auth $auth,
        protected readonly CartService $cart
    ) {
    }

    protected function shared(array $data = []): array
    {
        $user = $this->auth->user();
        $cart = $this->cart->details($user ? (int) $user['id'] : null);

        return array_merge([
            'config' => $this->config,
            'auth' => $this->auth,
            'currentUser' => $user,
            'currentCart' => $cart,
            'flashMessages' => Http::consumeFlash(),
            'old' => Http::consumeOld(),
        ], $data);
    }
}

