<?php
/**
 * @package     CMGiftCard
 * @subpackage  com_cmgiftcard
 * @copyright   Copyright (C) 2016-2024 CMExension
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Date\Date;

$item = $this->item;
$params = $this->params;
$countries = CMGiftCardHelper::getCountries();

$shippingInfo = array();
$shippingInfo[] = $item->to_name;

if ($item->to_email != '')
	$shippingInfo[] = $item->to_email;

if ($item->to_address_1 != '')
	$shippingInfo[] = $item->to_address_1;

if ($params->get('street_address_2') && $item->to_address_2 != '')
	$shippingInfo[] = $item->to_address_2;

if ($params->get('street_address_3') && $item->to_address_3 != '')
	$shippingInfo[] = $item->to_address_3;

if ($params->get('postal_box') && $item->to_postal_box != '')
	$shippingInfo[] = $item->to_postal_box;

if ($item->to_city != '')
	$shippingInfo[] = $item->to_city;

if ($item->to_state != '')
	$shippingInfo[] = $item->to_state;

if ($params->get('postal_code') && $item->to_postal_code != '')
	$shippingInfo[] = $item->to_postal_code;

if ($params->get('country') && $item->to_country != '')
	$shippingInfo[] = $countries[$item->to_country];

Factory::getDocument()->addStyleSheet('components/com_cmgiftcard/assets/css/styles.css');
?>
<div class="cmgiftcard<?php echo $this->pageclass_sfx?>">
	<div class="page-header">
		<h1> <?php echo $this->escape($params->get('page_heading')); ?> </h1>
	</div>

	<table class="table table-striped">
		<tbody>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_CARD_CODE'); ?>
				</td>
				<td><?php echo $item->card_code; ?></td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_CARD_TYPE'); ?>
				</td>
				<td>
				<?php
				if ($item->card_type == 'physical')
					echo Text::_('COM_CMGIFTCARD_CARD_TYPE_PHYSICAL');
				elseif ($item->card_type == 'electronic')
					echo Text::_('COM_CMGIFTCARD_CARD_TYPE_ELECTRONIC');
				?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_AMOUNT'); ?>
				</td>
				<td>
					<?php echo HTMLHelper::_('cmgiftcard.formatPrice', $item->amount); ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_SENDER_NAME'); ?>
				</td>
				<td><?php echo $item->from_name; ?></td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_RECIPIENT_INFO'); ?>
				</td>
				<td>
					<?php echo implode('<br>', $shippingInfo); ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_MESSAGE'); ?>
				</td>
				<td>
					<?php echo $item->message; ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_SCHEDULED_DELIVER_DATE'); ?>
				</td>
				<td>
					<?php
					if ($item->deliver_date)
					{
						$deliverDate = new Date($item->deliver_date);
						echo $deliverDate->format(Text::_('DATE_FORMAT_LC1'));
					}
					?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_DELIVERED'); ?>
				</td>
				<td>
					<?php if ($item->delivered) : ?>
					<?php echo HTMLHelper::_('date', $item->delivered, Text::_('DATE_FORMAT_LC1') . ' H:i'); ?>
					<?php else : ?>
						<?php echo Text::_('COM_CMGIFTCARD_ORDER_NOT_DELIVERED'); ?>
					<?php endif; ?>
				</td>
			</tr>
		</tbody>
	</table>
</div>
