<?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;
use BlackSheepResearch\Component\UserPoints\Site\Problems\Rule;

class StatisticsHTML extends AdminHTML {

    function show() {
        $document = Factory::getDocument();
        $document->addStyleDeclaration(".icon-32-user-reset {background-image: url(components/com_userpoints/assets/images/icon-32-user-reset.png);}", "text/css");
        $logo = '<img src="' . Uri::root() . 'administrator/components/com_userpoints/assets/images/icon-48-userpoints.png" />&nbsp;&nbsp;';

        ToolbarHelper::title($logo . 'UserPoints :: ' . Text::_('AUP_USERS'), 'user');
        $this->getCpanelToolbar();
        if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
            ToolbarHelper::editList('edituser');
        }
        if (Rule::withRuleName('sysplgup_bonuspoints')->published) {
            ToolbarHelper::custom('applybonus', 'new.png', 'new.png', Text::_('AUP_BONUS'), true);
        }
        if (Rule::withRuleName('sysplgup_custom')->published) {
            ToolbarHelper::custom('applycustomrule', 'apply.png', 'new.png', Text::_('AUP_CUSTOM_POINTS'), true);
        }
        ToolbarHelper::divider();
        if (UserPoints::getUser()->authorise('core.create', 'com_userpoints')) {
            ToolbarHelper::custom('exportallactivitiesallusers', 'upload.png', 'upload.png', Text::_('AUP_EXPORT_ACTIVITIES'), false);
        }
        ToolbarHelper::custom('resetuser', 'cancel.png', 'cancel.png', Text::_('AUP_RESET_USER'), true);
        $this->getPrefHelpToolbar();

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

        $this->display();
    }

    function edit_user() {

        $document = Factory::getDocument();

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

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

        ToolbarHelper::title($logo . 'UserPoints :: ' . Text::_('AUP_USERS_POINTS') . ': ' . $this->row->name, 'user');
        $this->getCpanelToolbar();
        if (UserPoints::getUser()->authorise('core.edit.state', 'com_userpoints')) {
            ToolbarHelper::apply('applyuser');
            ToolbarHelper::save('saveuser');
        }
        ToolbarHelper::cancel('canceluser');
        $this->getPrefHelpToolbar();

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

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

        $this->display("form");
    }

}
