<?php
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;
use Joomla\CMS\Uri\Uri;


$config      = $this->config;
$bootstrapHelper = $this->bootstrapHelper;
$rowFluidCss = $bootstrapHelper->getClassMapping('row-fluid');
$span12Css   = $bootstrapHelper->getClassMapping('span12');
$span6Css    = $bootstrapHelper->getClassMapping('span6');
$span4Css    = $bootstrapHelper->getClassMapping('span4');
$span3Css    = $bootstrapHelper->getClassMapping('span3');
$span8Css    = $bootstrapHelper->getClassMapping('span8');
$span9Css    = $bootstrapHelper->getClassMapping('span9');
$relates     = $this->related_items;
?>
<div class="related-documents">
	<h3 class="section-title">
		<i class="fas fa-link"></i> 
		<?php
		echo Text::_('EDOCMAN_RELATED_DOCUMENTS');
		?>
	</h3>
	<div class="related-items">
	 <?php
		$j = 0;
		$Itemid = Factory::getApplication()->getInput()->getInt('Itemid');
		foreach ($relates as $item)
		{
			$item->data     = new EDocman_File($item->id,$item->filename, $config->documents_path);
			$url            = Route::_('index.php?option=com_edocman&view=document&id='.$item->id.'&Itemid='.$Itemid);
			$imgSrc         = '';
			if ($item->image && is_file(Path::clean(JPATH_ROOT.'/media/com_edocman/document/thumbs/'.$item->image)))
			{
				$imgSrc     = Uri::root(true).'/media/com_edocman/document/thumbs/'.$item->image ;
			}
			else
			{
				$imgSrc     = Uri::root(true).'/components/com_edocman/assets/images/icons/thumbs/'.$item->data->ext.'.png';
			}
			?>
			<div class="related-item">
				<div class="related-thumbnail">
					<img src="<?php echo $imgSrc; ?>" alt="<?php echo $item->title; ?>">
				</div>
				<div class="related-info">
					<h4 class="related-title"><a href="<?php echo $url?>"><?php echo $item->title; ?></a></h4>
					<div class="related-meta">
						<span><i class="fas fa-file-<?php echo $item->data->ext; ?>"></i> <?php echo strtoupper($item->data->ext)?></span>
						<span><i class="fas fa-download"></i> <?php echo $item->downloads;?></span>
					</div>
				</div>
			</div>
			<?php
		}
		?>
	</div>
</div>
