<?php

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

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

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

$tipo_personas = Item::where('grupo_id','=',1)->get();
$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_tipopersona.html',[
    'empresa' => $empresa,
    'message_error' => $message_error,
    'message_success' => $message_success,
    'tipo_personas' => $tipo_personas,
    'user' => $_SESSION['user'],
    'privilegios' => $_SESSION['privilegios']
]);