<?php
/**
 * @package    VP Email Manager
 * @copyright  Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @author     Abhishek Das <info@virtueplanet.com>
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

jimport('joomla.application.component.view');

use \Joomla\CMS\Factory;
use \Joomla\CMS\Language\Text;

/**
 * View to default
 */
class VpemViewMail extends \Joomla\CMS\MVC\View\HtmlView
{
	protected $state;

	protected $item;

	/**
	 * Display the view
	 *
	 * @param   string  $tpl  Template name
	 *
	 * @return void
	 *
	 * @throws Exception
	 */
	public function display($tpl = null)
	{
		$this->state = $this->get('State');
		$this->item  = $this->get('Item');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			throw new Exception(implode("\n", $errors));
		}

		VpemHelper::addSubmenu('outbox');

		$this->addToolbar();
		
		$this->sidebar = JHtmlSidebar::render();
		
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return void
	 *
	 * @throws Exception
	 */
	protected function addToolbar()
	{
		$canDo = VpemHelper::getActions();
		
		JToolBarHelper::title(Text::_('COM_VPEM_TITLE_OUTBOX') . ': ' . Text::_('COM_VPEM_TITLE_MAIL'), 'mail.png');

		JToolBarHelper::link(JRoute::_('index.php?option=com_vpem&view=outbox'), 'JTOOLBAR_CLOSE', 'cancel');
		
		if ($canDo->get('core.admin'))
		{
			JToolBarHelper::preferences('com_vpem');
		}
	}
}
