<?php
namespace Modules\Commande\Controller;

use Skeleton\Controller\Controller;
use Modules\Commande\Repository\CreationCommande;
use Helpers\Pagination\Paginator;
use Helpers\Pagination\PaginatorGestion;

class PopupCreationCommandeController extends Controller
{
    public function popupListeDAAction() : string
    {
        $post = $this->request->getParsedBody();
        

        (new PaginatorGestion())->generate(8);
        $listeDA = (new CreationCommande($this->pdo))->listeDA($post);
        
        return $this->renderer->render('@ajax-liste/listeDA', [
            'entity' => $listeDA,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'path' => 'Commande.popupCreationCde.popupListeDA'
        ]);
    }
    
    public function popupListeligneDAAction() : string
    {
        $post = $this->request->getParsedBody();
        
        $listeDA = new CreationCommande($this->pdo);
        $listeDA = $listeDA->listeLigneDaPourCde($post);
        
        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listeDA, 8, $post, $this->renderer);
        
        return $this->renderer->render('@ajax-liste/listeDA', [
            'entity' => $listeDA,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'ligne' => true,
            'path' => 'Commande.popupCreationCde.popupListeligneDA'
        ]);
    }
    
    public function popupListeAOAction() : string
    {
        $post = $this->request->getParsedBody();
        
        (new PaginatorGestion())->generate(8);
        $listeAO = (new CreationCommande($this->pdo))->listeAO($post);
        
        return $this->renderer->render('@ajax-liste/listeAO', [
            'entity' => $listeAO,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'path' => 'Commande.popupCreationCde.popupListeAO'
        ]);
    }
    
    // TODO : not used -> remove ?
    public function popupListefournisseurAOAction() : string
    {
        $post = $this->request->getParsedBody();
        
        $fournisseur = new CreationCommande($this->pdo);
        $fournisseur = $fournisseur->fournisseurParAo($post);
        
        $paginator = new Paginator();
        $infoPagination = $paginator->generate($fournisseur, 8, $post, $this->renderer);
        
        
        return $this->renderer->render('@ajax-liste/listeFournisseur', [
            'fournisseurs' => $fournisseur,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Commande.popupCreationCde.popupListefournisseurAO',
        ]);
    }
}
