<?php

/**psr-4 */
require_once "vendor/autoload.php";

use App\Libreria\Conexion;
use App\Models\Empresa;
use App\Models\Carrusel;
new Conexion();

require_once('session.php');
require_once('session.php');
$count = 0;
foreach ($_SESSION['privilegios'] as $key) {
    if ($key->nombre == "carrusel") {
        $count++;
    }
}
if ($count == 0) {
    echo "acceso denegado";
    die();
}

$carruseles = Carrusel::all();
$empresa = Empresa::first();

$loader = new \Twig\Loader\FilesystemLoader('public/views');
$twig = new \Twig\Environment($loader, [
    'debug' => true,
    'cache' => false,
]);

$message_error = null;
$message_success = null;
if (isset($_SESSION['message_error'])) {
    $message_error = $_SESSION['message_error'];
    unset($_SESSION['message_error']);
}
if (isset($_SESSION['message_success'])) {
    $message_success = $_SESSION['message_success'];
    unset($_SESSION['message_success']);
}
echo $twig->render('soporte_carrusel.html',[
    'message_error' => $message_error,
    'message_success' => $message_success,
    'carruseles' => $carruseles,
    'empresa' => $empresa,
    'user' => $_SESSION['user'],
    'privilegios' => $_SESSION['privilegios']
]);