<?php
/**
 *----------------------------------------------------------------------------
 * iCagenda     Events Management Extension for Joomla!
 *----------------------------------------------------------------------------
 * @version     3.9.0 2024-02-24
 *
 * @package     iCagenda.Site
 * @subpackage  tmpl.registration
 * @link        https://www.joomlic.com
 *
 * @author      Cyril Reze
 * @copyright   (c) 2012-2026 Cyril Reze / JoomliC. All rights reserved.
 * @license     GNU General Public License version 3 or later; see LICENSE.txt
 *
 * @since       3.6
 *----------------------------------------------------------------------------
*/

defined('_JEXEC') or die;

use iClib\Date\Date as iCDate;
use iCutilities\Event\Event as icagendaEvent;
use iCutilities\Render\Render as icagendaRender;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;

$app     = Factory::getApplication();
$isSef   = $app->getCfg('sef');
$eventId = $app->input->getInt('id');
$menu    = $app->getMenu();

$lang    = Factory::getLanguage();

// Look for the home menu
if (Multilanguage::isEnabled()) {
	$home = $menu->getDefault($lang->getTag());
} else {
	$home  = $menu->getDefault();
}

//$regid = $app->input->get('reg');

$startDate = icagendaRender::dateToFormat($this->item->startdate);
$startTime = icagendaRender::dateToTime($this->item->startdate);
$endDate   = icagendaRender::dateToFormat($this->item->enddate);
$endTime   = icagendaRender::dateToTime($this->item->enddate);

if ( ! $this->registration) {
	$app->redirect(Route::_('index.php?option=com_icagenda&view=event&id=' . $app->input->getInt('id'), false));
}

$regDateTime = icagendaRender::dateToFormat($this->registration->date)
				. ' - ' . icagendaRender::dateToTime($this->registration->date);

$period_set = substr($this->item->startdate, 0, 4);

$vars = array();

// Registration Type is 'all dates of the event' (single dates + period)
if ($this->registration->period == 1) {
	$registrationDates  = '';
} elseif ($this->registration->date == '' && ! $this->registration->period) {
	// Registration Type is 'select list of dates'
	// Is a Period (no date, and period = 0)
	$registrationDates  = (iCDate::isDate($this->item->startdate) && iCDate::isDate($this->item->enddate))
						? '<div class="ic-label">' . Text::_('COM_ICAGENDA_REGISTRATION_DATES') . ': </div>'
							. '<div class="ic-value">' . Text::_('COM_ICAGENDA_PERIOD_FROM') . ' ' . $startDate . ' ' . $startTime
							. ' ' . Text::_('COM_ICAGENDA_PERIOD_TO') . ' ' . $endDate . ' ' . $endTime . '</div>'
						: '';
} else {
	// Registration Type is 'select list of dates' (single dates + period)
	// Is a Single date
	$registrationDates  = '<div class="ic-label">' . Text::_('COM_ICAGENDA_REGISTRATION_DATE') . '</div>'
						. '<div class="ic-value">' . $regDateTime . '</div>';

	$vars = array('date' => iCDate::dateToAlias($this->registration->date, 'Y-m-d-H-i'));
}

$eventURL = icagendaEvent::url($eventId, $this->item->alias, '', $vars);

// Complete Page Content
$content  = '<p>' . Text::sprintf('COM_ICAGENDA_REGISTRATION_COMPLETE_THANK_YOU_NAME', $this->registration->name) . '</p>';
$content .= '<p>' . Text::sprintf('COM_ICAGENDA_REGISTRATION_COMPLETE_CONFIRMED', $this->item->title) . '</p>';

$content .= '<div class="ic-divTable ic-align-left ic-clearfix">';

// Currently, only 'Registration Form' system (in roadmap: 'Attend/Not Attend' system)
$simpleRegSystem = Text::_('COM_ICAGENDA_REGISTRATION_SUMMARY_REGISTRATION');

$content .= '<legend>' . Text::sprintf('COM_ICAGENDA_REGISTRATION_SUMMARY_LEGEND', $simpleRegSystem) . '</legend>';

// Event
$content .= '<div class="ic-divRow">';
$content .= '<div class="ic-label">' . Text::_('IC_EVENT') . '</div>'
			. '<div class="ic-value">' . $this->item->title . '</div>';
$content .= '</div>';

// Date(s) booked
$content .= '<div class="ic-divRow">';
$content .= $registrationDates;
$content .= '</div>';

// Number of tickets booked
$content .= '<div class="ic-divRow">';
$content .= '<div class="ic-label">' . Text::_('COM_ICAGENDA_REGISTRATION_PEOPLE_LABEL') . '</div>'
			. '<div class="ic-value">' . $this->registration->people . '</div>';
$content .= '</div>';

// Content is generated by icagenda plugin event "onICagendaRegistrationCompleteAfterDataDisplay"
$content .= $this->item->pluginEvent->afterDisplayCompleteData;

$content .= '</div>';

?>
<div id="icagenda" class="ic-registration-complete<?php echo $this->pageclass_sfx; ?>">
	<h1>
		<?php echo $this->escape(Text::_('COM_ICAGENDA_REGISTRATION_TITLE')); ?>
	</h1>
	<div class="ic-registration-complete-content">
		<?php echo $content; ?>
	</div>
	<br />
	<div class="ic-registration-complete-buttons">
		<a href="<?php echo Route::_('index.php?Itemid=' . $home->id); ?>" class="btn btn-info button">
			<i class="icon-home icon-white"></i>&nbsp;<?php echo Text::_('JERROR_LAYOUT_HOME_PAGE'); ?>
		</a>
		&nbsp;
		<a href="<?php echo $eventURL; ?>" class="btn btn-success button">
			<i class="icon-eye icon-white"></i>&nbsp;<?php echo Text::_('COM_ICAGENDA_REGISTRATION_EVENT_LINK'); ?>
		</a>
	</div>
	<br />
</div>
