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

defined('JPATH_BASE') or die;

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

extract($displayData);

$countries = CMGiftCardHelper::getCountries();

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

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

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

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

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

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

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

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

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

if ($params->get('country') && $card->to_country != '')
	$shippingInfo[] = $countries[$card->to_country];
?>
<div class="cmgiftcard">
	<table class="table table-striped">
		<tbody>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_CARD_CODE'); ?>
				</td>
				<td><?php echo $card->card_code; ?></td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_CARD_TYPE'); ?>
				</td>
				<td>
				<?php
				if ($card->card_type == 'physical')
					echo Text::_('COM_CMGIFTCARD_CARD_TYPE_PHYSICAL');
				elseif ($card->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', $card->amount); ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_SENDER_NAME'); ?>
				</td>
				<td><?php echo $card->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 $card->message; ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_ORDER_SCHEDULED_DELIVER_DATE'); ?>
				</td>
				<td>
					<?php
					if ($card->deliver_date)
					{
						$deliverDate = new Date($card->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 ($card->delivered) : ?>
					<?php echo HTMLHelper::_('date', $card->delivered, Text::_('DATE_FORMAT_LC1') . ' H:i'); ?>
					<?php else : ?>
						<?php echo Text::_('COM_CMGIFTCARD_ORDER_NOT_DELIVERED'); ?>
					<?php endif; ?>
				</td>
			</tr>
			<tr>
				<td class="table-heading">
					<?php echo Text::_('COM_CMGIFTCARD_REDEEMED'); ?>
				</td>
				<td>
					<?php if ($card->redeemed !== null) : ?>
					<?php echo HTMLHelper::_('date', $card->redeemed, Text::_('DATE_FORMAT_LC1') . ' H:i'); ?>
					<?php else : ?>
						<?php echo Text::_('COM_CMGIFTCARD_NOT_REDEEMED'); ?>
					<?php endif; ?>
				</td>
			</tr>
		</tbody>
	</table>
</div>