<?php

/*
 * @component UserPoints
 * @copyright Copyright (C) 2015-2016 - Bernard Gilly - Adrien Roussel
 * @license : GNU/GPL
 * @Website : https://remository.com
 */
// no direct access

namespace BlackSheepResearch\Component\UserPoints\Site\Viewers;

// no direct access
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use BlackSheepResearch\Component\UserPoints\Administrator\Viewers\UPJPane;
use BlackSheepResearch\Component\UserPoints\Site\UserPoints;
use BlackSheepResearch\Component\UserPoints\Site\Problems\Invitation;

class InviteHTML extends UserView {

    protected $form;

    function display($tpl = null) {
        $app = Factory::getApplication();
        $doc = Factory::getDocument();
        $this->displ = "view";
        $this->points = 0;

        $cparams = ComponentHelper::getParams('com_userpoints');

        // HTMLHelper::_('behavior.framework', true);

        // $doc->addStyleSheet(Uri::base(true) . '/components/com_userpoints/assets/css/userpoints.css');

        $result = UserPoints::checkRuleEnabled('sysplgup_invite');
        if ($result)
            $this->points = $result->points;

        // JHTML::_('behavior.formvalidation');
        // JHTML::_('behavior.modal');
        $setModal = "window.addEvent('domready', function() {
			SqueezeBox.initialize({});

			$$('a.modal').each(function(el) {
				el.addEvent('click', function(e) {
					new Event(e).stop();
					SqueezeBox.fromElement(el);
				});
			});
		});
		";

        $doc->addScriptDeclaration($setModal);

        $this->referreid = $this->getModel('invite')->_getReferreid();
        $this->referrer_link = Invitation::makeReferralLink($this->referreid);
        $this->user_name = UserPoints::getUser()->name;
        $app_params = $app->getParams();
        $this->params = $app_params->toArray();

        jimport('joomla.form.form');
        // HTMLHelper::_('behavior.keepalive');

        Form::addFormPath(JPATH_COMPONENT . '/models/forms');

        $model = $this->getModel('invite');
        $this->form = $model->getForm();
        parent::display($tpl);
    }

    function _display_addressbook($tpl = null) {
        parent::display('addressbook');
    }

}
