<?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\Router\Route;

HTMLHelper::_('bootstrap.tooltip');
HTMLHelper::_('behavior.multiselect');
HTMLHelper::_('formbehavior.chosen', 'select');

$user		= Factory::getUser();
$userId		= $user->get('id');
$canEdit	= $user->authorise('core.edit', 'com_cmgiftcard');
?>

<form action="<?php echo Route::_('index.php?option=com_cmgiftcard&view=templates'); ?>" method="post" name="adminForm" id="adminForm">
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
		<?php if (empty($this->items)) : ?>
			<div class="alert alert-no-items">
				<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
			</div>
		<?php else : ?>
			<table class="table table-striped" id="templateList">
				<thead>
					<tr>
						<th width="1%" class="center">
							<?php echo HTMLHelper::_('grid.checkall'); ?>
						</th>
						<th>
							<?php echo Text::_('COM_CMGIFTCARD_TEMPLATE_FIELD_SUBJECT_LABEL'); ?>
						</th>
						<th>
							<?php echo Text::_('JGLOBAL_DESCRIPTION'); ?>
						</th>
						<th width="1%" class="nowrap">
							<?php echo Text::_('JGRID_HEADING_ID'); ?>
						</th>
					</tr>
				</thead>
				<tfoot>
					<tr>
						<td colspan="4">
							<?php echo $this->pagination->getListFooter(); ?>
						</td>
					</tr>
				</tfoot>
				<tbody>
					<?php foreach ($this->items as $i => $item) :
						$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
						?>
						<tr class="row<?php echo $i % 2; ?>" sortable-group-id="">
							<td class="center">
								<?php echo HTMLHelper::_('grid.id', $i, $item->id); ?>
							</td>
							<td>
								<div class="pull-left">
									<?php if ($item->checked_out) : ?>
										<?php echo HTMLHelper::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'templates.', $canCheckin); ?>
									<?php endif; ?>
									<?php if ($canEdit) : ?>
										<a href="<?php echo Route::_('index.php?option=com_cmgiftcard&task=template.edit&id=' . (int) $item->id); ?>">
											<?php echo $this->escape($item->subject); ?></a>
									<?php else : ?>
										<?php echo $this->escape($item->subject); ?>
									<?php endif; ?>
								</div>
							</td>
							<td>
								<?php echo Text::_('COM_CMGIFTCARD_TEMPLATE_' . strtoupper($item->template_id) . '_DESCRIPTION'); ?>
							</td>
							<td class="hidden-phone">
								<a href="<?php echo Route::_('index.php?option=com_cmgiftcard&task=template.edit&id=' . (int) $item->id); ?>"><?php echo $item->id; ?></a>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>

		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<?php echo HTMLHelper::_('form.token'); ?>
	</div>
</form>
