<?php


/**
 * @package com_spbooking
 * @author JoomShaper http://www.joomshaper.com
 * @copyright Copyright (c) 2010 - 2023 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
 */

// No Direct Access
defined('_JEXEC') or die('Resticted Aceess');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;

class SpbookingViewRoom extends HtmlView
{
	protected $item;

	protected $form;

	public function display($tpl = null)
	{
		$this->item = $this->get('Item');
		$this->form = $this->get('Form');

		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode('<br>', $errors), 500);

			return false;
		}

		$this->addToolbar();

		return parent::display($tpl);
	}

	protected function addToolbar()
	{
		$input = Factory::getApplication()->input;
		$input->set('hidemainmenu', true);

		$user = Factory::getUser();
		$userId = $user->get('id');
		$isNew = $this->item->id == 0;
		$canDo = SpbookingHelper::getActions('com_spbooking', 'component');

		ToolbarHelper::title(Text::_('COM_SPBOOKING_ROOM_TITLE_' . ($isNew ? 'ADD' : 'EDIT')), '');

		if ($canDo->get('core.edit'))
		{
			ToolbarHelper::apply('room.apply', 'JTOOLBAR_APPLY');
			ToolbarHelper::save('room.save', 'JTOOLBAR_SAVE');
			ToolbarHelper::save2new('room.save2new');
			ToolbarHelper::save2copy('room.save2copy');
		}

		ToolbarHelper::cancel('room.cancel', 'JTOOLBAR_CLOSE');
	}
}

