<?php

namespace Modules\Ajax\Controller;

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

class AjaxServerController extends Controller
{
    
    public function cookieMenuAction()
    {
        $post = $this->request->getParsedBody();
        $_SESSION['menuDeplier'] = $post['active'];
            return new Response(200, [
                
            ], 1);
    }
    
    public function zoomAction()
    {
        $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()
    {
        $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');
        }
    }
}
