<?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 UserHTML extends AdminHTML {

	public 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_ACTIVITY' ) . ': ' . $this->name , 'searchtext' );
		$this->getCpanelToolbar();
		ToolbarHelper::back( 'Back' );
		ToolbarHelper::divider();
		if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
			ToolbarHelper::editList( 'edituserdetails' );
		}
		if (UserPoints::getUser()->authorise('core.delete', 'com_userpoints')) {
			ToolbarHelper::custom( 'deleteuserdetails', 'trash.png', 'delete.png', Text::_('AUP_DELETE') );
			ToolbarHelper::custom( 'deleteuserallactivities', 'delete.png', 'delete.png', Text::_('AUP_DELETE_ALL'), false );

			ToolbarHelper::divider();

		}
		if (UserPoints::getUser()->authorise('core.create', 'com_userpoints')) {
			ToolbarHelper::custom( 'exportallactivitiesuser', 'upload.png', 'upload.png', Text::_('AUP_EXPORT_ACTIVITIES'), false );
		}
		ToolbarHelper::divider();
		$bar =  Toolbar::getInstance('toolbar');

		HTMLHelper::_('bootstrap.modal', 'collapseModal');
		$title = Text::_('AUP_CUSTOM_POINTS');
		$dhtml = "<button data-toggle=\"modal\" data-target=\"#generatorModal\" class=\"btn btn-small\">
					<i class=\"icon-apply icon-white\" title=\"$title\"></i>
					$title</button>";
		//$bar->appendButton('Custom', $dhtml, 'applycustom');

		//$bar->appendButton( 'Popup', 'apply', Text::_('AUP_CUSTOM_POINTS'), 'index.php?option=com_userpoints&task=applycustom&layout=modal&tmpl=component&cid='.$this->cid.'&name='.$this->name, 800, 460, 0, 0, 'window.top.location.reload(true);document.location.reload(true);' );

		$this->getPrefHelpToolbar();

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

		parent::display( $tpl) ;
	}

	public function edit_pointsDetails () {

		$document	=  Factory::getDocument();

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

		ToolbarHelper::title( 'UserPoints :: ' . Text::_( 'AUP_ACTIVITY' ) . ': ' . $this->name, 'addedit' );
		$this->getCpanelToolbar();
		if (UserPoints::getUser()->authorise('core.edit.state', 'com_userpoints')) {
			ToolbarHelper::save( 'saveuserdetails' );
		}
		ToolbarHelper::cancel( 'canceluserdetails' );
		$this->getPrefHelpToolbar();

		// JHTML::_('behavior.calendar');
		$document->addScriptDeclaration("window.addEvent('domready', function(){ var JTooltips = new Tips($$('.hasTip'), { maxTitleChars: 50, fixed: false}); });");

		parent::display( "form" ) ;

	}
}
