<?php

/**
 * @package Finatic
 * @author JoomShaper http://www.joomshaper.com
 * @copyright Copyright (c) 2010 - 2019 JoomShaper
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
 */
//no direct accees
defined('_JEXEC') or die('resticted access');

class SppagebuilderAddonTestimonial_slider extends SppagebuilderAddons {

    public function render() {
				$output = '<div class="finatic-testimonial-slider">';
					$output .= '<div id="finatic-carousel" class="owl-carousel">';
						foreach ($this->addon->settings->finatic_testimonial_slider_item as $key => $item) {
							$output .= '<div class="item">';
								$output .= '<h3>' . $item->title . '</h3>';
								$output .= '<div class="finatic-testimonial-footer">';
									$output .= '<img src="' . $item->img . '">';
									$output .= '<p>' . $item->name . '</p>';
								$output .= '</div>';
							$output .= '</div>';
						}
					$output .= '</div>';
				$output .= '</div>';

        return $output;
    }

    public function scripts() {
        $app = JFactory::getApplication();
        $base_path = JURI::base() . '/templates/' . $app->getTemplate() . '/js/';
        return array($base_path . 'owl.carousel.min.js', $base_path . 'addon.slider.js');
    }

    public function js() {
        $addon_id = '#sppb-addon-' . $this->addon->id;
        return '
            jQuery(document).ready(function($){"use strict";

            $("' . $addon_id . ' #finatic-carousel").owlCarousel({
                margin: 30,
                loop: true,
                video:true,
                autoplay: true,
								dots: false,
								nav: false,
                autoplaySpeed: 800,
                responsive: {
										0: {
											items: 1
										},
                    520: {
											items: 2
                    },
										768: {
											items: 3
                    },
                    1000: {
											items: 4
                    },
                    1310: {
											items: 5
                    }
                },
								onInitialized: function() {
										$(".owl-item.active").last().addClass("last-owl-active-item");
								},
								onTranslated: function() {
										$(event.target).find(".last-owl-active-item").removeClass("last-owl-active-item");
										$(event.target).find(".active").last().addClass("last-owl-active-item");
								}
            });
        });
        ';
    }

    public function stylesheets() {
        $app = JFactory::getApplication();
        $base_path = JURI::base() . '/templates/' . $app->getTemplate() . '/css/';
        return array($base_path . 'owl.carousel.min.css');
    }

    public static function getTemplate() {
        $output = '
					<div class="finatic-testimonial-slider">
						<div id="finatic-carousel" class="owl-carousel">
							<# _.each (data.finatic_testimonial_slider_item, function(item, key) { #>
								<div class="item">
									<h3>{{item.title}}</h3>
									<div class="finatic-testimonial-footer">
										<img src="{{item.img}}">
										<p>{{item.name}}</p>
									</div>
								</div>
							<# }); #>
						</div>
					</div>
					';
        return $output;
    }

}
