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

    public function show() {
        $document = Factory::getDocument();
        $document->addStyleDeclaration(".icon-32-plugin-add {background-image: url(components/com_userpoints/assets/images/icon-32-plugin-add.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_RULES'), 'article');
        $this->getCpanelToolbar();
        ToolbarHelper::publishList();
        ToolbarHelper::unpublishList();
        ToolbarHelper::divider();
        /*
          if (UserPoints::getUser()->authorise('core.plugins', 'com_userpoints')) {
          ToolbarHelper::custom( 'plugins', 'power-cord.png', 'power-cord.png', Text::_('AUP_PLUGINS'), false );
          ToolbarHelper::divider();
          }
         */
        if (UserPoints::getUser()->authorise('core.create', 'com_userpoints')) {
            ToolbarHelper::addNew('editrule');
        }
        ToolbarHelper::custom('copyrule', 'copy.png', 'copy.png', Text::_('AUP_COPY'));
        if (UserPoints::getUser()->authorise('core.edit', 'com_userpoints')) {
            ToolbarHelper::editList('editrule');
        }
        if (UserPoints::getUser()->authorise('core.delete', 'com_userpoints')) {
            ToolbarHelper::custom('deleterule', 'delete.png', 'delete.png', Text::_('AUP_DELETE'));
        }
        $this->getPrefHelpToolbar();
        $this->isIEAdm();
        $this->pagination = new Pagination($this->total, $this->limitstart, $this->limit);
        $this->display();
    }

    public function show_edit() {
        Factory::getApplication()->input->set('hidemainmenu', 1);
        $document = Factory::getDocument();
        $document->addStyleDeclaration(".icon-32-plugin-add {background-image: url(components/com_userpoints/assets/images/icon-32-plugin-add.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_RULES'), 'article-add');
        $this->getCpanelToolbar();

        // ToolbarHelper::custom('plugins', 'power-cord.png', 'power-cord.png', Text::_('AUP_PLUGINS'), false);
        ToolbarHelper::divider();

        if (UserPoints::getUser()->authorise('core.edit.state', 'com_userpoints')) {
            ToolbarHelper::apply('applyrule');
            ToolbarHelper::save('saverule');
        }

        ToolbarHelper::cancel('cancelrule');
        $this->getPrefHelpToolbar();

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

        $this->lists = [];
        // build the html radio buttons for published
        $this->lists['published'] = HTMLHelper::_('select.booleanlist', 'published', '', $this->row->published);
        $this->lists['autoapproved'] = HTMLHelper::_('select.booleanlist', 'autoapproved', '', $this->row->autoapproved);

        $auth[] = array();
        $auth[] = HTMLHelper::_('select.option', 'Registered', 'Registered');
        $auth[] = HTMLHelper::_('select.option', 'Author', 'Author');
        $auth[] = HTMLHelper::_('select.option', 'Editor', 'Editor');
        $auth[] = HTMLHelper::_('select.option', 'Publisher', 'Publisher');

        $this->lists['percentage'] = HTMLHelper::_('select.booleanlist', 'percentage', '', $this->row->percentage);

        $this->lists['fixedpoints'] = HTMLHelper::_('select.booleanlist', 'fixedpoints', '', $this->row->fixedpoints);

        $this->lists['allow_referral'] = HTMLHelper::_('select.booleanlist', 'allow_referral', '', $this->row->allow_referral);

        //$options[] = array();
        $options[] = HTMLHelper::_('select.option', '', Text::_('AUP_NONE'));
        $options[] = HTMLHelper::_('select.option', 'us', Text::_('AUP_CAT_USER'));
        $options[] = HTMLHelper::_('select.option', 'co', Text::_('AUP_CAT_COMMUNITY'));
        $options[] = HTMLHelper::_('select.option', 'ar', Text::_('AUP_CAT_ARTICLE'));
        $options[] = HTMLHelper::_('select.option', 'li', Text::_('AUP_CAT_LINK'));
        $options[] = HTMLHelper::_('select.option', 'po', Text::_('AUP_CAT_POLL_QUIZZ'));
        $options[] = HTMLHelper::_('select.option', 're', Text::_('AUP_CAT_RECOMMEND_INVITE'));
        $options[] = HTMLHelper::_('select.option', 'fo', Text::_('AUP_CAT_COMMENT_FORUM'));
        $options[] = HTMLHelper::_('select.option', 'vi', Text::_('AUP_CAT_VIDEO'));
        $options[] = HTMLHelper::_('select.option', 'ph', Text::_('CAT_CAT_PHOTO'));
        $options[] = HTMLHelper::_('select.option', 'mu', Text::_('AUP_CAT_MUSIC'));
        $options[] = HTMLHelper::_('select.option', 'sh', Text::_('AUP_CAT_SHOPPING'));
        $options[] = HTMLHelper::_('select.option', 'pu', Text::_('AUP_CAT_PURCHASING'));
        $options[] = HTMLHelper::_('select.option', 'cd', Text::_('AUP_CAT_COUPON_CODE'));
        $options[] = HTMLHelper::_('select.option', 'su', Text::_('AUP_CAT_SUBSCRIPTION'));
        $options[] = HTMLHelper::_('select.option', 'ga', Text::_('AUP_CAT_GAMING'));
        $options[] = HTMLHelper::_('select.option', 'sy', Text::_('AUP_CAT_SYSTEM'));
        $options[] = HTMLHelper::_('select.option', 'ot', Text::_('AUP_CAT_OTHER'));
        $this->lists['category'] = HTMLHelper::_('select.genericlist', $options, 'category', 'class="inputbox" size="1"', 'value', 'text', $this->row->category);

        //$options[] = array();
        $options[] = HTMLHelper::_('select.option', '1', '1 ' . Text::_('AUP_DAY'));
        $options[] = HTMLHelper::_('select.option', '2', '2 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '3', '3 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '4', '4 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '5', '5 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '6', '6 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '7', '7 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '8', '8 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '9', '9 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '10', '10 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '11', '11 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '12', '12 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '13', '13 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '14', '14 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '15', '15 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '20', '20 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '25', '25 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '30', '30 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '60', '2 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '90', '3 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '180', '6 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '365', '1 ' . Text::_('AUP_YEAR'));
        $options[] = HTMLHelper::_('select.option', '730', '2 ' . Text::_('AUP_YEARS'));
        $options[] = HTMLHelper::_('select.option', '1825', '5 ' . Text::_('AUP_YEARS'));

        $this->lists['inactive_preset_period'] = HTMLHelper::_('select.genericlist', $options, 'content_items', 'class="inputbox" size="1"', 'value', 'text', $this->row->content_items);
        $this->lists['displaymsg'] = HTMLHelper::_('select.booleanlist', 'displaymsg', '', $this->row->displaymsg);
        $this->lists['notification'] = HTMLHelper::_('select.booleanlist', 'notification', '', $this->row->notification);

        //$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);

        //$options[] = array();
        $options[] = HTMLHelper::_('select.option', '0', Text::_('AUP_SELECT_A_METHOD_TO_ATTRIB_POINTS'));
        $options[] = HTMLHelper::_('select.option', '1', Text::_('AUP_ONLY_ONCE'));
        $options[] = HTMLHelper::_('select.option', '2', Text::_('AUP_ONCE_PER_DAY'));
        $options[] = HTMLHelper::_('select.option', '3', Text::_('AUP_ONCE_PER_DAY_MIXED'));
        $options[] = HTMLHelper::_('select.option', '5', Text::_('AUP_ONCE_PER_WEEK'));
        $options[] = HTMLHelper::_('select.option', '6', Text::_('AUP_ONCE_PER_MONTH'));
        $options[] = HTMLHelper::_('select.option', '7', Text::_('AUP_ONCE_PER_YEAR'));
        // --------------
        $options[] = HTMLHelper::_('select.option', '4', Text::_('AUP_WHENEVER'));
        $this->lists['methods'] = HTMLHelper::_('select.genericlist', $options, 'method', 'class="inputbox" size="1"', 'value', 'text', $this->row->method);
        $this->lists['groups'] = $this->groups;

        //$options[] = array();
        $options[] = HTMLHelper::_('select.option', '0', Text::_('AUP_DEFAULT'));
        $options[] = HTMLHelper::_('select.option', '1', '1 ' . Text::_('AUP_DAY'));
        $options[] = HTMLHelper::_('select.option', '2', '2 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '3', '3 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '4', '4 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '5', '5 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '6', '6 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '7', '7 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '8', '8 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '9', '9 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '10', '10 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '11', '11 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '12', '12 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '13', '13 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '14', '14 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '15', '15 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '20', '20 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '25', '25 ' . Text::_('AUP_DAYS'));
        $options[] = HTMLHelper::_('select.option', '30', '1 ' . Text::_('AUP_MONTH'));
        $options[] = HTMLHelper::_('select.option', '60', '2 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '90', '3 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '180', '6 ' . Text::_('AUP_MONTHS'));
        $options[] = HTMLHelper::_('select.option', '360', '1 ' . Text::_('AUP_YEAR'));
        $options[] = HTMLHelper::_('select.option', '720', '2 ' . Text::_('AUP_YEARS'));
        $options[] = HTMLHelper::_('select.option', '1080', '3 ' . Text::_('AUP_YEARS'));
        $options[] = HTMLHelper::_('select.option', '1440', '4 ' . Text::_('AUP_YEARS'));
        $options[] = HTMLHelper::_('select.option', '1800', '5 ' . Text::_('AUP_YEARS'));
        $options[] = HTMLHelper::_('select.option', '3600', '10 ' . Text::_('AUP_YEARS'));
        $this->lists['type_expire_date'] = HTMLHelper::_('select.genericlist', $options, 'type_expire_date', 'class="inputbox" size="1"', 'value', 'text', $this->row->type_expire_date);

        //$options[] = array();
        $options[] = HTMLHelper::_('select.option', '0', Text::_('AUP_NONE'));
        foreach ($this->chainedrules as $chain) {
            $options[] = HTMLHelper::_('select.option', $chain->id, Text::_($chain->rule_name));
        }
        $this->lists['linkup'] = HTMLHelper::_('select.genericlist', $options, 'linkup', 'class="inputbox" size="1"', 'value', 'text', $this->row->linkup);
        $this->lists['displayactivity'] = HTMLHelper::_('select.booleanlist', 'displayactivity', '', $this->row->displayactivity);
        parent::display("form");
    }

    public function _displaycustompoints() {
        parent::display("custom");
    }

    public function _displaycustomrulepoints() {
        parent::display("custom2");
    }

}
