<?php

namespace WpBookingEventAdmin\app\views\event;

use WpBookingEvent\Html\ToolBar;
use WpBookingEvent\Mvc\Model\Model;
use WpBookingEvent\Mvc\View\View;
use WpBookingEvent\Factory as FactoryAlias;

class EventView extends View
{
    public function display($tpl)
    {    
        $modelEvent = Model::getInstance("event");
        $input = FactoryAlias::getInput();
        $id = $input->getInt('id', 0);
        $this->item = $modelEvent->getItem($id);
        switch ($tpl) {
            case "list":
                ToolBar::add("event.add");
                ToolBar::delete("event.delete_list");
                ToolBar::_clone("event.clone_list");
                $model = Model::getInstance("events");
                $this->list = $model->getList();
                break;
            case "form":
                $id = $input->getInt('id', 0);
                $this->item = $modelEvent->getItem($id);
                $this->form = $modelEvent->getForm();
                if ($this->item != null){
                    ToolBar::setTitle("Edit Event");
                }else{
                    ToolBar::setTitle("Add Event");
                }
                ToolBar::apply("event.apply");
                ToolBar::save("event.save_event");
                ToolBar::cancel("event.cancel");
                ToolBar::back_to_list("event.back_to_list");

                break;
        }
        return parent::display($tpl);
    }
}