<?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;

$items = $this->items;

Factory::getDocument()->addStyleSheet('components/com_cmgiftcard/assets/css/styles.css');
?>
<div class="cmgiftcard<?php echo $this->pageclass_sfx?>">
	<?php if ($this->params->get('show_page_heading')) : ?>
	<div class="page-header">
		<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
	</div>
	<?php endif; ?>
	<?php if (count($items) > 0) : ?>
	<table class="table table-striped">
		<thead>
			<th><?php echo Text::_('COM_CMGIFTCARD_ORDER_NUMBER'); ?></th>
			<th><?php echo Text::_('COM_CMGIFTCARD_ORDER_GIFT_CARDS'); ?></th>
			<th><?php echo Text::_('COM_CMGIFTCARD_AMOUNT'); ?></th>
			<th><?php echo Text::_('COM_CMGIFTCARD_ORDER_STATUS'); ?></th>
			<th><?php echo Text::_('COM_CMGIFTCARD_ORDER_CREATED_DATE'); ?></th>
		</thead>
		<tbody>
			<?php foreach ($items as $item) : ?>
			<tr>
				<td>
					<a href="<?php echo CMGiftCardHelper::prepareRoute('index.php?option=com_cmgiftcard&view=order&order=' . $item->order_number); ?>">
						<?php echo $item->order_number; ?>
					</a>
				</td>
				<td>
				<?php if (count($item->cards)): ?>
					<?php foreach ($item->cards as $card) : ?>
						<?php echo $card->card_code; ?><br>
					<?php endforeach; ?>
				<?php endif; ?>
				</td>
				<td><?php echo HTMLHelper::_('cmgiftcard.formatPrice', $item->amount); ?></td>
				<td>
					<?php
					if ($item->order_status == 'unpaid') :
						echo Text::_('COM_CMGIFTCARD_ORDER_STATUS_UNPAID');
					elseif ($item->order_status == 'paid') :
						echo Text::_('COM_CMGIFTCARD_ORDER_STATUS_PAID');
					elseif ($item->order_status == 'refunded') :
						echo Text::_('COM_CMGIFTCARD_ORDER_STATUS_REFUNDED');
					endif;
					?>
				</td>
				<td>
				<?php
				if ($item->created)
				{
					echo HTMLHelper::_('date', $item->created, Text::_('DATE_FORMAT_LC1') . ' H:i');
				}
				?>
				</td>
			</tr>
			<?php endforeach; ?>
		</tbody>
		<tfoot>
			<tr>
				<td colspan="5">
					<?php echo $this->pagination->getPagesLinks(); ?>
				</td>
			</tr>
		</tfoot>
	</table>
	<?php else : ?>
	<div class="alert alert-warning">
		<?php echo Text::_('COM_CMGIFTCARD_NO_ORDERS_MESSAGE'); ?>
	</div>
	<?php endif; ?>
</div>