<?php $_testimonialCollection = $this->getCollection(); ?>
<?php $_collectionSize = count($_testimonialCollection) ?>
<?php $helper = $this->helper('MGS\Testimonial\Helper\Data'); ?>
<div class="content-block testimonial-block testimonial-list-block">

	<?php if($this->hasData('mgs_panel_title')): ?>
		<div class="content-heading">
			<h2 class="title"><?php echo $helper->decodeHtmlTag($this->getData('mgs_panel_title')) ?></h2>
		</div>
	<?php endif ?>

	<?php if (count($_testimonialCollection) >0): ?>
		<?php if($this->hasData('mgs_panel_note')): ?>
			<div class="block-note"><?php echo $helper->decodeHtmlTag($this->getData('mgs_panel_note')) ?></div>
		<?php endif ?>
		
		<?php
			$blockId = rand() . time();
			$useSlider = $this->getUseSlider();
			$showAvatar = $this->getShowAvatar();
			$perRow = $this->getPerrow();
		?>
		<?php if ($useSlider): ?>
			<div class="block widget mgs-testimonial">
				<div class="owl-carousel testimonial-list mgs-carousel-<?php echo $blockId; ?>">
					<?php $i=0; foreach ($_testimonialCollection as $testimonial): ?>
						<?php if ($i++ % $perRow == 0): ?>
							<div class="item">
						<?php endif ?>
						<div class="item testimonial-author">
							<?php if($showAvatar && $this->getAvatarUrl($testimonial->getAvatar())): ?>
								<div class="img-thumbnail img-thumbnail-small">							
									<img src="<?php echo $this->getAvatarUrl($testimonial->getAvatar()) ?>" alt="">							
								</div>
							<?php endif;?>
							<div class="testimonial-content">
								<p><?php echo $testimonial->getContent() ?></p>
							</div>
							<p><span><?php echo __('from') ?></span><strong><?php echo $testimonial->getName() ?></strong></p>
						</div>
						<?php if ($i % $perRow == 0 || $i == $_collectionSize): ?>
							</div>
						<?php endif ?>
					<?php endforeach ?>
				</div>
			</div>
			<script type="text/javascript">
				require([
					'jquery',
					'mgs/owlcarousel'
				], function ($) {
					$('.mgs-carousel-<?php echo $blockId ?>').owlCarousel({
						items: 1,
						autoplay: <?php echo $this->getAutoplay() ? 'true' : 'false' ?>,
						autoplayHoverPause: <?php echo $this->getStopAuto() ? 'true' : 'false' ?>,
						nav: <?php echo $this->getNavigation() ? 'true' : 'false' ?>,
                        rtl: RTL,
						dots: <?php echo $this->getPagination() ? 'true' : 'false' ?>,
					});
				});
			</script>
		<?php else: ?>
			<div class="block widget mgs-testimonial testimonial-list">
				<div class="block-content">
					<ul>
						<?php foreach ($_testimonialCollection as $testimonial): ?>
							<li class="item testimonial-content list-content">
								<?php if($showAvatar && $this->getAvatarUrl($testimonial->getAvatar())): ?>
									<div class="img-thumbnail img-thumbnail-small">							
										<img src="<?php echo $this->getAvatarUrl($testimonial->getAvatar()) ?>" alt="">							
									</div>
								<?php endif;?>
								<div class="testimonial-content">
									<p><?php echo $testimonial->getContent() ?></p>
								</div>
								<p><span><?php echo __('from') ?></span><strong><?php echo $testimonial->getName() ?></strong></p>
							</li>
						<?php endforeach ?>
					</ul>
				</div>
			</div>
		<?php endif ?>
	<?php else: ?>
		<div role="alert" class="alert alert-warning"> <?php echo __('There are no testimonials matching the selection.') ?> </div>
	<?php endif ?>
</div>