<?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\Component\ComponentHelper;

$params = ComponentHelper::getParams('com_cmgiftcard');
$physicalTitle = $params->get('physical_title', Text::_('COM_CMGIFTCARD_PHYSICAL_DEFAULT_TITLE'));
$electronicTitle = $params->get('electronic_title', Text::_('COM_CMGIFTCARD_ELECTRONIC_DEFAULT_TITLE'));

$physicalImage = $params->get('physical_image');
$electronicImage = $params->get('electronic_image');

$physicalDesc = $params->get('physical_description');
$electronicDesc = $params->get('electronic_description');

$physicalLabel = $params->get('physical_button_label', Text::_('COM_CMGIFTCARD_PHYSICAL_DEFAULT_BUTTON_LABEL'));
$electronicLabel = $params->get('electronic_button_label', Text::_('COM_CMGIFTCARD_ELECTRONIC_DEFAULT_BUTTON_LABEL'));

$formUrl = 'index.php?option=com_cmgiftcard&view=form';
$physicalLink = CMGiftCardHelper::prepareRoute($formUrl . '&type=physical');
$electronicLink = CMGiftCardHelper::prepareRoute($formUrl . '&type=electronic');

Factory::getDocument()->addStyleSheet('components/com_cmgiftcard/assets/css/styles.css');

$giftCardType = $params->get('gift_card_type', 'all');
$col = ($giftCardType == 'all') ? '6' : '12';
?>
<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; ?>

	<div class="row">
		<?php if ($giftCardType != 'electronic') : ?>
		<div class="col-md-<?php echo $col; ?>">
			<h3><?php echo $physicalTitle; ?></h3>
			<?php if ($physicalImage != '') : ?>
			<div class="list-thumbnail">
				<a href="<?php echo $physicalLink; ?>">
					<img src="<?php echo CMGiftCardHelper::getImageUrl($physicalImage); ?>">
				</a>
			</div>
			<?php endif; ?>
			<?php if ($physicalDesc != '') : ?>
			<div class="list-description"><?php echo $physicalDesc; ?></div>
			<?php endif; ?>
			<a href="<?php echo $physicalLink; ?>" class="btn btn-primary"><?php echo $physicalLabel; ?></a>
		</div>
		<?php endif; ?>
		<?php if ($giftCardType != 'physical') : ?>
		<div class="col-md-<?php echo $col; ?>">
			<h3><?php echo $electronicTitle; ?></h3>
			<?php if ($electronicImage != '') : ?>
			<div class="list-thumbnail">
				<a href="<?php echo $electronicLink; ?>">
					<img src="<?php echo CMGiftCardHelper::getImageUrl($electronicImage); ?>">
				</a>
			</div>
			<?php endif; ?>
			<?php if ($electronicDesc != '') : ?>
			<div class="list-description"><?php echo $electronicDesc; ?></div>
			<?php endif; ?>
			<a href="<?php echo $electronicLink; ?>" class="btn btn-primary"><?php echo $electronicLabel; ?></a>
		</div>
		<?php endif; ?>
	</div>
</div>
