<?php

namespace Apps\Annonce\Widget\ListAnnonce;

use Core\View\View;
use Core\View\ElementView;

use Apps\Annonce\Entity\AnnonceAnnonce;

class ListAnnonce {

    /**
     * Constructeur
     */
    function __construct($core = "", $data = "") {
        $this->Core = $core;
        $this->Data = $data;
   }

    /*     * *
     * Render the html form
     */

    function Render() {

        $view = new View(__DIR__ . "/View/index.tpl", $this->Core);

        $caracteristicplugin = \Apps\EeApp\Helper\AppHelper::GetPluginType($this->Core, "Annonce" , "Caracteristic");
        
        if($caracteristicplugin != null){
            $filtersCaracteristics = $caracteristicplugin->RenderFilters("Annonce");
        }    

        $view->AddElement(new ElementView("Filters", $filtersCaracteristics ? $filtersCaracteristics : "" )); 
       
        $view->AddElement(new ElementView("Annonces", $this->GetList())); 

        $alertPlugin = \Apps\EeApp\Helper\AppHelper::GetPluginType($this->Core, "Annonce" , "Alert");
        
        if($alertPlugin != null){
            $alertForm = $alertPlugin->RenderAlertForm("Annonce");
        }    
      
      
        $noResultPlugin = \Apps\EeApp\Helper\AppHelper::GetPluginType($this->Core, "Annonce" , "NoResult");
        
        if($noResultPlugin != null){
            $noResult = $noResultPlugin->RenderNoResultCaracteristic("Annonce");
        }    
        
        $alertForm = "<div class='col-md-6'><div class='block-first row'>".$alertForm ."</div></div>";

        $noResult = "<div class='col-md-6'><div class='block-first row'>".$noResult ."</div></div>";
        
        $view->AddElement(new ElementView("alertForm", $alertForm ?  $alertForm  : "" )); 

        $view->AddElement(new ElementView("noResult", $noResult ? $noResult  : "" )); 

        return $view->Render();
    }

    /***
     * Returtn list of Annonce
     * Filtrer
     */
    function GetList(){

        $annonces = new AnnonceAnnonce($this->Core);


        return $annonces->Find("1 = 1");
    }

}
