<?php

namespace WpBookingHotelAdmin\app\views\orders;

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

class OrdersView extends View
{
    public function display($tpl)
    {
        $modelHotel = Model::getInstance("order");
        $input = FactoryAlias::getInput();
        switch ($tpl) {
            case "form":
                ToolBar::setTitle('Edit order');
                ToolBar::apply("order.apply");
                ToolBar::save("order.save");
                ToolBar::cancel("order.cancel");
                ToolBar::back_to_list("order.back_to_list");
                $model = Model::getInstance("order");
                $oder_id = $input->getInt('id');
                $modelListHotel = Model::getInstance('hotels');
                $this->list_hotel = $modelListHotel->getList();
                $this->item = $model->getItem($oder_id);
                $this->form = $model->getForm();
                break;
            case "list":
                ToolBar::delete("order.delete_list");
                $model = Model::getInstance("orders");
                $this->list = $model->getList();
                break;
            case "edit":
                ToolBar::save("order.save");
                ToolBar::setTitle('Edit Order');
                ToolBar::cancel("order.cancel");
                ToolBar::back_to_list("order.back_to_list");
                $appConfig = FactoryAlias::getAppConfig();
                $based = $appConfig->get('currency_converter','');
                $currencyModel = Model::getInstance('currency');
                $symbol = $currencyModel->format_currency($based);
                $this->currency = reset($symbol);
                $model = Model::getInstance("order");
                $order_id = $input->getInt('id');
                $modelListHotel = Model::getInstance('hotels');
                $modelListCountry = Model::getInstance('countries');
                $this->list_country = $modelListCountry->getList();
                $this->list_hotel = $modelListHotel->getList();
                $this->item = $model->getItem($order_id);
                $this->form = $model->getForm();
                break;
        }
        return parent::display($tpl);
    }
}