<?php

namespace Modules\Ajax\Controller;

use Skeleton\Controller\Controller;
use GuzzleHttp\Psr7\Response;
use Helpers\Validator\Validator;

class AjaxServerController extends Controller
{
    
    public function cookieMenuAction() :Response
    {
        $post = $this->request->getParsedBody();
        $_SESSION['menuDeplier'] = $post['active'];
        return new Response(200, [], '1');
    }
    
    public function zoomAction() :Response
    {
        $post = $this->request->getParsedBody();
        $nomChamp = $post['nomChamp'] ?? '';
        
        $validator = $this->createValidator();
        $validator->zoom($post['entity'], $post['value'], $nomChamp, $this->pdo);
        
        if ($validator->isValid()) {
            return new Response(200, [
                
            ], $validator->getError());
        } else {
            return new Response(200, [
                
            ], $validator->getError());
        }
    }
    
    public function dateAction() :Response
    {
        $post = $this->request->getParsedBody();
        
        $validator = $this->createValidator();
        
        if ($validator->isDate($post['value'])) {
            return new Response(200, [
                
            ], $validator->getError());
        } else {
            return new Response(200, [
                
            ], '<br /> erreur date');
        }
    }
}
