<?php
namespace JExtstore\Component\JChat\Site\View\Attachments;
/**
 * @package JCHAT::ATTACHMENTS::components::com_jchat
 * @subpackage views
 * @subpackage attachments
 * @author Joomla! Extensions Store
 * @Copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Uri\Uri;
use JExtstore\Component\JChat\Administrator\Framework\View as JChatView;

/**
 * Main view class
 *
 * @package JCHAT::ATTACHMENTS::components::com_jchat
 * @subpackage views
 * @subpackage attachments
 * @since 1.0
 */
class RawView extends JChatView {
	// Template view variables
	protected $to;
	protected $tologged;
	protected $isLiveStreaming;
	protected $liveSite;
	protected $modelMessage;
	protected $success;
	protected $visibleClass;
	protected $joomlaTemplate;
	protected $baseTemplate;
	protected $chatTemplate;
	
	/**
	 * Display the form used to upload file attachments
	 * @access public
	 * @return void
	 */
	public function display($tpl = null) {
		$defaultModelReference = $this->getModel();
		
		// View variables
		$this->to = $defaultModelReference->getState('to');
		$this->tologged = $defaultModelReference->getState('tologged');
		$this->option = $defaultModelReference->getState('option');
		$this->isLiveStreaming = $defaultModelReference->getState('isLiveStreaming');
		$this->liveSite = Uri::base();
		
		// Model message after result, any errors or simply default success result message?
		$this->modelMessage = $defaultModelReference->getError(null, false) ? $defaultModelReference->getError(null, false) : $defaultModelReference->getState('result');
		$this->success = $defaultModelReference->getState('result') ? ' success' : null;
		$this->visibleClass = $this->modelMessage !== null ? 'visible' : '';
		
		$this->joomlaTemplate = $this->app->getTemplate();
		$chosenChatTemplate = $defaultModelReference->getComponentParams()->get('chat_template', 'default.css');
		$this->baseTemplate = $chosenChatTemplate == 'custom.css' ? 'custom.css' : 'default.css';
		
		$this->chatTemplate = null;
		$directTemplates = array('default.css', 'custom.css');
		if(!in_array($chosenChatTemplate, $directTemplates)) {
			$this->chatTemplate = $chosenChatTemplate;
		}
		
		// Evaluate nonce csp feature
		$appNonce = $this->app->get('csp_nonce', null);
		$this->nonce = $appNonce ? ' nonce="' . $appNonce . '"' : '';
		
		parent::display ( $tpl );
	}
}