<?php
namespace Modules\Panier\Controller;

use Entity\Model\ImpPanE;
use Entity\Model\ImpPanL;
use Entity\Model\ImpPanR;
use Entity\Model\OxaUserCnt;
use GuzzleHttp\Psr7\Response;
use Helpers\Ariane\Ariane;
use Helpers\Fichier\Fichier;
use Helpers\Log\LogSysteme;
use Helpers\Outil\Sql;
use Helpers\Pagination\Paginator;
use Modules\Panier\Repository\ImportPanier;
use Modules\Panier\Service\ImportService;
use Skeleton\Controller\Controller;
use Helpers\Session\ParseBase1;

class ImportDevisController extends Controller
{

    public function indexAction() : string
    {
        Ariane::generate(0, 'Import Devis');

        return $this->renderer->render('@Panier/Devis/index', [
            'menuActive'            => 'eproc',
            'menuLeft'              => 'import',
        ]);
    }

    public function ajaxImportFileAction():Response
    {
        $post = $this->request->getParsedBody();
        $file = $this->request->getUploadedFiles();
        $trad = $this->getTranslationService();

        $validator = $this->createValidator();

        if ($file) {
            $fileName = $file['importimport']->getClientFilename();
            $fileSize = $file['importimport']->getSize();
        }

        $validator->fileCheck($trad->t('devis'), $fileName ?? '', [], '', $fileSize ?? 0);

        if ($validator->isValid()) {
            return new Response(200, [], $this->renderer->render('@popup-erreur/information', [
                'message' => $trad->t('Votre devis est en cours de traitement, vous serez notifié quand celui-ci sera terminé.'),
            ]));
        } else {
            return new Response(200, [], $this->renderer->render('@popup-erreur/ErreurCreation', [
                'ErreurValid' => $validator->getError(),
                'desactiveRow' => true,
            ]));
        }
    }
}
