<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2022 Bernard Gilly - Adrien Roussel - Martin Brampton
 * @license : GNU/GPL
 * @Website : https://remository.com
 */

namespace BlackSheepResearch\Component\UserPoints\Administrator\Viewers;

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\HTML\HTMLHelper;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;

class TemplateinviteHTML extends AdminHTML {

	function displaylist($tpl = null) {
		$logo = '<img src="'. Uri::root() . 'administrator/components/com_userpoints/assets/images/icon-48-userpoints.png" />&nbsp;&nbsp;';

		ToolbarHelper::title(  $logo . 'UserPoints :: ' . Text::_( 'AUP_TEMPLATES' ), 'thememanager' );

		$this->getCpanelToolbar();
		if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
			ToolbarHelper::editList( 'edittemplateinvite' );
		}
		if (UserPoints::getUser()->authorise('core.create', 'com_userpoints')) {
			ToolbarHelper::addNew( 'edittemplateinvite' );
		}
		if (UserPoints::getUser()->authorise('core.delete', 'com_userpoints')) {
			ToolbarHelper::custom( 'deletetemplateinvite', 'delete.png', 'delete.png', Text::_('AUP_DELETE') );
		}
		$this->getPrefHelpToolbar();

		$this->pagination = new Pagination( $this->total, $this->limitstart, $this->limit );

		parent::display( $tpl) ;
	}

	function edit_templateinvite($tpl = null) {

		$document	=  Factory::getDocument();

		Factory::getApplication()->input->set( 'hidemainmenu', 1 );

		ToolbarHelper::title( 'UserPoints :: ' .  Text::_( 'AUP_TEMPLATE' ), 'thememanager' );
		$this->getCpanelToolbar();
		if (UserPoints::getUser()->authorise('core.edit.state', 'com_userpoints')) {
			ToolbarHelper::apply('applytemplateinvite');
			ToolbarHelper::save( 'savetemplateinvite' );
		}
		ToolbarHelper::cancel( 'canceltemplateinvite' );
		$this->getPrefHelpToolbar();
		$document->addScriptDeclaration("window.addEvent('domready', function(){ var JTooltips = new Tips($$('.hasTip'), { maxTitleChars: 50, fixed: false}); });");

		$this->lists = [];
		$this->lists['published'] = HTMLHelper::_('select.booleanlist', 'published', '', $this->row->published);
		$options = array();
		$options[] = HTMLHelper::_('select.option', '0', Text::_( 'AUP_PLAIN-TEXT' ) );
		$options[] = HTMLHelper::_('select.option', '1', Text::_( 'AUP_HTML' ) );
		$this->lists['emailformat'] = HTMLHelper::_('select.genericlist', $options, 'emailformat', 'class="inputbox" size="1"' ,'value', 'text', $this->row->emailformat );
		$this->lists['bcc2admin'] = HTMLHelper::_('select.booleanlist', 'bcc2admin', '', $this->row->bcc2admin);

		parent::display( "form" ) ;
	}

}
