<?php
/**
 * @package DJ-Catalog2
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 *
 */

// no direct access
defined('_JEXEC') or die;

use Joomla\CMS\Factory;

//Joomla\CMS\HTML\HTMLHelper::_('bootstrap.tooltip');

$user = Factory::getUser();
$listOrder = strtolower($this->state->get('list.ordering'));
$listDirn = strtolower($this->state->get('list.direction'));
$saveOrder = ($listOrder == 'a.ordering' && $listDirn == 'asc');
$saveOrderingUrl = '';
if ($saveOrder && !empty($this->items))
{
	$saveOrderingUrl = 'index.php?option=com_djcatalog2&task=labels.saveOrderAjax&tmpl=component&' . Joomla\CMS\Session\Session::getFormToken() . '=1';
	Joomla\CMS\HTML\HTMLHelper::_('draggablelist.draggable');
}

?>
<form action="<?php echo JRoute::_('index.php?option=com_djcatalog2&view=labels');?>" method="post" name="adminForm" id="adminForm">
<div class="row">
	<?php if (!empty($this->sidebar) /*&& !JHtmlDJCatalog2::isJoomla4()*/): ?>
	<div id="j-sidebar-container" class="col-md-2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="col-md-10">
	<?php else : ?>
		<div id="j-main-container">
	<?php endif;?>
	
	<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
	
	<table class="table table-striped">
		<thead>
			<tr>
				<th width="1%" class="hidden-phone">
					<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
				</th>
				<th scope="col" class="w-1 text-center d-none d-md-table-cell">
					<?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
				</th>
				<th>
					<?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'COM_DJCATALOG2_NAME', 'a.name', $listDirn, $listOrder); ?>
				</th>
				<th>
					<?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'COM_DJCATALOG2_LABEL', 'a.label', $listDirn, $listOrder); ?>
				</th>

                <th width="5%">
                    <?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JPUBLISHED', 'a.published', $listDirn, $listOrder); ?>
                </th>
				<th width="1%" class="nowrap">
					<?php echo Joomla\CMS\HTML\HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
				</th>
			</tr>
		</thead>
		
		<tbody<?php if ($saveOrder) : ?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo $listDirn; ?>" data-nested="false"<?php endif; ?>>
		<?php foreach ($this->items as $i => $item) :
			$item->max_ordering = 0; //??
			?>
			<tr class="row<?php echo $i % 2; ?>" data-draggable-group="1" item-id="<?php echo $item->id ?>"  data-direction="<?php echo strtolower($listDirn); ?>" data-nested="false">
				<td class="center">
					<?php echo Joomla\CMS\HTML\HTMLHelper::_('grid.id', $i, $item->id); ?>
				</td>
				<td class="text-center d-none d-md-table-cell">
					<?php
					$iconClass = '';
					if (!$saveOrder)
					{
						$iconClass = ' inactive" title="' . JText::_('JORDERINGDISABLED');
					}
					?>
					<span class="sortable-handler<?php echo $iconClass ?>">
						<span class="icon-ellipsis-v" aria-hidden="true"></span>
					</span>
					<?php if ($saveOrder) : ?>
						<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>" class="width-20 text-area-order hidden">
					<?php endif; ?>
				</td>
				<td>
					<span class="editlinktip hasTip" title="<?php echo JText::_( 'COM_DJCATALOG2_EDIT_TOOLTIP' );?>::<?php echo $this->escape($item->name); ?>">
						<a href="<?php echo JRoute::_('index.php?option=com_djcatalog2&task=label.edit&id='.$item->id);?>">
							<?php echo $this->escape($item->name); ?></a>
						</span>
				</td>
				<td>
					<?php if ($item->label != '') {?>
						<span class="badge"><?php echo $item->label; ?></span>
					<?php } ?>
					<?php if ($item->image != '') {?>
						<img alt="<?php echo $this->escape($item->name); ?>" src="../<?php echo $item->image; ?>" />
					<?php } ?>
				</td>
                <td class="center">
                    <?php echo Joomla\CMS\HTML\HTMLHelper::_('jgrid.published', $item->published, $i, 'labels.', true, 'cb'	); ?>
                </td>
				<td class="center">
					<?php echo (int) $item->id; ?>
				</td>
			</tr>
			<?php endforeach; ?>
		</tbody>
		
		<tfoot>
			<tr>
				<td colspan="6">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
	</table>

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