<?php

namespace Apps\Booking\Decorator;

use Core\View\View;
use Core\View\ElementView;
use Core\Control\TextBox\TextBox;
use Core\Control\EntityListBox\EntityListBox;
use Core\Entity\Entity\Argument;

use Apps\Booking\Entity\BookingCaracteristique;
use Apps\Booking\Entity\BookingCaracteristiqueItem;


class CaracteristiqueDecorator {

    public function __construct($core) {
        $this->Core = $core;
    }

    /****
     * Render the available caracteristique
     */
    public function RenderCaracteristiques(){

        $view ="";

        $caracteristique = new BookingCaracteristique($this->Core);
        $caracteristiques = $caracteristique->GetAll();
        
        foreach($caracteristiques as $caracteristique){

            $item = new BookingCaracteristiqueItem($this->Core);
            $items = $item->Find("CaracteristiqueId=" .$caracteristique->IdEntite);
            
            if(count($items) > 0){

                $textBox = new EntityListBox($caracteristique->IdEntite, $this->Core);
                $textBox->Entity = "Apps\Booking\Entity\BookingCaracteristiqueItem";
                $textBox->AddField("Label");
                $textBox->AddArgument(new Argument("Apps\Booking\Entity\BookingCaracteristiqueItem", "CaracteristiqueId", EQUAL, $caracteristique->IdEntite));
                $view .= "<div class='col-md-6'><label>" .$caracteristique->Name->Value."</label>";
                $view .= $textBox->Render(); 
                $view .= "</div>";

            } else {

                $textBox = new TextBox($caracteristique->IdEntite);
                $view .= "<div class='col-md-6'><label>" .$caracteristique->Name->Value."</label>";
                $view .= $textBox->Render(); 
                $view .= "</div>";
            }

        }

        return $view;
    }
}