<?php

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

////Load Helix
//$helix3_path = JPATH_PLUGINS . '/system/helix3/core/helix3.php';
//
//if (file_exists($helix3_path)) {
//    require_once($helix3_path);
//    helix3::addCSS('owl.carousel.css, owl.theme.css, owl.transitions.css, slide-animate.css') // CSS Files
//            ->addJS('owl.carousel.min.js, addon.slider.js'); // JS Files
//}
//
//
//AddonParser::addAddon('sp_slideshow_full', 'sp_slideshow_full_addon');
//AddonParser::addAddon('sp_slideshow_full_item', 'sp_slideshow_full_item_addon');
//
//function sp_slideshow_full_addon($atts, $content) {
//
//    extract(spAddonAtts(array(
//        'autoplay' => '',
//        'controllers' => '',
//        'arrows' => '',
//        'color' => '',
//        'background' => '',
//        "class" => '',
//                    ), $atts));
//
//    //Check Auto Play
//    $slide_autoplay = ($autoplay) ? 'data-sppb-slide-ride="true"' : '';
//    $slide_controllers = ($controllers) ? 'data-sppb-slidefull-controllers="true"' : '';
//
//    // Generate css styles
//    $SlideStyle = '';
//    if ($background || $color) {
//        $SlideStyle .='style="';
//        if ($background) {
//            $SlideStyle .='background: ' . $background . '; ';
//        }
//
//        if ($color) {
//            $SlideStyle .='color: ' . $color . '; ';
//        }
//        $SlideStyle .='"';
//    }
//
//
//    $output = '<div class="sppb-addon sppb-slider-wrapper sppb-slider-fullwidth-wrapper owl-theme' . $class . '">';
//    $output .= '<div class="sppb-slider-item-wrapper" ' . $SlideStyle . '>';
//    $output .= '<div id="slide-fullwidth" class="owl-carousel" ' . $slide_controllers . ' ' . $slide_autoplay . ' >';
//    $output .= AddonParser::spDoAddon($content);
//    $output .= '</div>'; //END:: /.sppb-slider-items
//    $output .= '</div>'; // END:: /.sppb-slider-item-wrapper
//    // has next/previous arrows
//    if ($arrows) {
//        $output .= '<div class="customNavigation">';
//        $output .= '<div class="container">';
//        $output .= '<a class="sppbSlidePrev"><i class="fa fa-angle-left"></i></a>';
//        $output .= '<a class="sppbSlideNext"><i class="fa fa-angle-right"></i></a>';
//        $output .= '</div>';
//        $output .= '</div>'; // END:: /.customNavigation
//    }
//
//    $output .= '</div>'; // /.sppb-slider-wrapper
//    // has dot controls
//    if ($controllers) {
//        $output .='<div class="owl-dots">';
//        $output .='<div class="owl-dot active"><span></span></div>';
//        $output .='<div class="owl-dot"><span></span></div>';
//        $output .='<div class="owl-dot"><span></span></div>';
//        $output .='</div>';
//    }
//
//
//
//
//    return $output;
//}
//
//function sp_slideshow_full_item_addon($atts) {
//
//    extract(spAddonAtts(array(
//        "title" => '',
//        "sub_title" => '',
//        "bg" => '',
//        'content' => '',
//        "button_one_text" => '',
//        "button_one_url" => '',
//        "button_two_text" => '',
//        "button_two_url" => '',
//        "target" => '_self',
//        "button_one_before_icon" => '',
//        "button_two_before_icon" => '',
//        "title_animation" => '',
//        "title_animationduration" => '',
//        "title_animationdelay" => '',
//        "subtitle_animation" => '',
//        "subtitle_animationduration" => '',
//        "subtitle_animationdelay" => '',
//        "cotent_animation" => '',
//        "cotent_animationduration" => '',
//        "cotent_animationdelay" => '',
//        "button_animation" => '',
//        "button_animationduration" => '',
//        "button_animationdelay" => '',
//                    ), $atts));
//
//
//    // if have bg
//    $bg_image = ($bg) ? 'style="background-image: url(' . JURI::base() . $bg . ');"' : '';
//
//
//    // *** animation *** //
//    // Title animation
//    if (isset($title_animation) && $title_animation) {
//        $title_animation .= ' sppb-wow ' . $title_animation;
//    }
//
//    $title_data_attr = '';
//    if (isset($title_animationduration) && $title_animationduration)
//        $title_data_attr .= ' data-sppb-wow-duration="' . $title_animationduration . 'ms"';
//    if (isset($title_animationdelay) && $title_animationdelay)
//        $title_data_attr .= ' data-sppb-wow-delay="' . $title_animationdelay . 'ms"';
//
//    // sub title animation
//    if (isset($subtitle_animation) && $subtitle_animation) {
//        $subtitle_animation .= ' sppb-wow ' . $subtitle_animation;
//    }
//
//    $subtitle_data_attr = '';
//    if (isset($subtitle_animationduration) && $subtitle_animationduration)
//        $subtitle_data_attr .= ' data-sppb-wow-duration="' . $subtitle_animationduration . 'ms"';
//    if (isset($subtitle_animationdelay) && $subtitle_animationdelay)
//        $subtitle_data_attr .= ' data-sppb-wow-delay="' . $subtitle_animationdelay . 'ms"';
//
//
//    // content animation
//    if (isset($cotent_animation) && $cotent_animation) {
//        $cotent_animation .= ' sppb-wow ' . $cotent_animation;
//    }
//
//    $content_data_attr = '';
//    if (isset($cotent_animationduration) && $cotent_animationduration)
//        $content_data_attr .= ' data-sppb-wow-duration="' . $cotent_animationduration . 'ms"';
//    if (isset($cotent_animationdelay) && $cotent_animationdelay)
//        $content_data_attr .= ' data-sppb-wow-delay="' . $cotent_animationdelay . 'ms"';
//
//    // Button animation
//    if (isset($button_animation) && $button_animation) {
//        $button_animation .= ' sppb-wow ' . $button_animation;
//    }
//
//    $button_data_attr = '';
//    if (isset($button_animationduration) && $button_animationduration)
//        $button_data_attr .= ' data-sppb-wow-duration="' . $button_animationduration . 'ms"';
//    if (isset($button_animationdelay) && $button_animationdelay)
//        $button_data_attr .= ' data-sppb-wow-delay="' . $button_animationdelay . 'ms"';
//
//
//
//    // Before button icon
//    $button_one_before_icon = ($button_one_before_icon) ? '<i class="fa ' . $button_one_before_icon . '"></i>' : '';
//    $button_two_before_icon = ($button_two_before_icon) ? '<i class="fa ' . $button_two_before_icon . '"></i>' : '';
//
//    $output = '<div class="sppb-slideshow-fullwidth-item item">';
//    $output .= '<div class="sppb-slide-item-bg sppb-slideshow-fullwidth-item-bg" ' . $bg_image . '>';
//    $output .= '<div class="container">';
//    $output .= '<div class="row">';
//    $output .= '<div class="col-sm-8 col-md-7 col-lg-5">';
//    $output .= '<div class="sppb-slideshow-fullwidth-item-text">';
//
//    if (($title) || ($content)) {
//
//        $sub_title = ($sub_title) ? '<small class="sppb-slidehsow-sub-title ' . $subtitle_animation . '" ' . $subtitle_data_attr . '>' . $sub_title . '</small>' : '';
//
//        if ($title) {
//            $output .= '<h1 class="sppb-fullwidth-title ' . $title_animation . '" ' . $title_data_attr . '> ' . $title . $sub_title . ' </h1>';
//        }
//
//        if ($content) {
//            $output .= '<p class="details ' . $cotent_animation . '" ' . $content_data_attr . '>' . $content . '</p>';
//        }
//
//        if (($button_one_text && $button_one_url) || ($button_two_text && $button_two_url)) {
//            $output .= '<div class="sppb-fw-slider-button-wrapper ' . $button_animation . '" ' . $button_data_attr . '> ';
//            if ($button_one_text && $button_one_url) {
//                $output .= '<a target="' . $target . '" href="' . $button_one_url . '" class="btn btn-primary"> <span>' . $button_one_text . '</span></a>';
//            }
//            if ($button_two_text && $button_two_url) {
//                $output .= '<a target="' . $target . '" href="' . $button_two_url . '" class="btn btn-primary"> <span>' . $button_two_before_icon . $button_two_text . '</span></a>';
//            }
//
//            $output .= '</div>';
//        }
//    }
//
//    $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item-text
//    $output .= '</div>'; // END:: /.col-sm-5
//    $output .= '</div>'; // END:: /.row
//    $output .= '</div>'; // END:: /.container
//    $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item-bg
//    $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item
//    return $output;
//}


class SppagebuilderAddonSlideshow_full extends SppagebuilderAddons {

    public function render() {
        $autoplay = (isset($this->addon->settings->autoplay) && $this->addon->settings->autoplay) ? $this->addon->settings->autoplay : '';
        $controllers = (isset($this->addon->settings->controllers) && $this->addon->settings->controllers) ? $this->addon->settings->controllers : '';
        $arrows = (isset($this->addon->settings->arrows) && $this->addon->settings->arrows) ? $this->addon->settings->arrows : '';
        $class = (isset($this->addon->settings->class) && $this->addon->settings->class) ? $this->addon->settings->class : '';


        //Check Auto Play
        $slide_autoplay = ($autoplay) ? 'data-sppb-slide-ride="true"' : '';
        $slide_controllers = ($controllers) ? 'data-sppb-slidefull-controllers="true"' : '';


        //output
        $output = '<div class="sppb-addon sppb-slider-wrapper sppb-slider-fullwidth-wrapper owl-theme' . $class . '">';
        $output .= '<div class="sppb-slider-item-wrapper">';
        $output .= '<div id="slide-fullwidth" class="owl-carousel" ' . $slide_controllers . ' ' . $slide_autoplay . ' >';

        foreach ($this->addon->settings->sp_slideshow_full_item as $key => $slide_item) {

            // if have bg
            $bg_image = ($slide_item->bg) ? 'style="background-image: url(' . JURI::base() . $slide_item->bg . ');"' : '';

            // *** animation *** //
            // Title animation
            $title_animation = '';
            if (isset($slide_item->title_animation) && $slide_item->title_animation) {
                $slide_item->title_animation .= ' sppb-wow ' . $slide_item->title_animation;
            }

            $title_data_attr = '';
            if (isset($slide_item->title_animationduration) && $slide_item->title_animationduration)
                $title_data_attr .= ' data-sppb-wow-duration="' . $slide_item->title_animationduration . 'ms"';
            if (isset($slide_item->title_animationdelay) && $slide_item->title_animationdelay)
                $title_data_attr .= ' data-sppb-wow-delay="' . $slide_item->title_animationdelay . 'ms"';

            // sub title animation
            $subtitle_animation = '';
            if (isset($slide_item->subtitle_animation) && $slide_item->subtitle_animation) {
                $slide_item->subtitle_animation .= ' sppb-wow ' . $slide_item->subtitle_animation;
            }

            $subtitle_data_attr = '';
            if (isset($slide_item->subtitle_animationduration) && $slide_item->subtitle_animationduration)
                $subtitle_data_attr .= ' data-sppb-wow-duration="' . $slide_item->subtitle_animationduration . 'ms"';
            if (isset($slide_item->subtitle_animationdelay) && $slide_item->subtitle_animationdelay)
                $subtitle_data_attr .= ' data-sppb-wow-delay="' . $slide_item->subtitle_animationdelay . 'ms"';


            // content animation
            if (isset($slide_item->cotent_animation) && $slide_item->cotent_animation) {
                $slide_item->cotent_animation .= ' sppb-wow ' . $slide_item->cotent_animation;
            }

            $content_data_attr = '';
            if (isset($slide_item->cotent_animationduration) && $slide_item->cotent_animationduration)
                $content_data_attr .= ' data-sppb-wow-duration="' . $slide_item->cotent_animationduration . 'ms"';
            if (isset($slide_item->cotent_animationdelay) && $slide_item->cotent_animationdelay)
                $content_data_attr .= ' data-sppb-wow-delay="' . $slide_item->cotent_animationdelay . 'ms"';

            // Button animation
            if (isset($slide_item->button_animation) && $slide_item->button_animation) {
                $slide_item->button_animation .= ' sppb-wow ' . $slide_item->button_animation;
            }

            $button_data_attr = '';
            if (isset($slide_item->button_animationduration) && $slide_item->button_animationduration)
                $button_data_attr .= ' data-sppb-wow-duration="' . $slide_item->button_animationduration . 'ms"';
            if (isset($slide_item->button_animationdelay) && $slide_item->button_animationdelay)
                $button_data_attr .= ' data-sppb-wow-delay="' . $slide_item->button_animationdelay . 'ms"';



            // Before button icon
            $button_one_before_icon = (isset($slide_item->button_one_before_icon) && $slide_item->button_one_before_icon) ? '<i class="fa ' . $slide_item->button_one_before_icon . '"></i>' : '';

            $output .= '<div class="sppb-slideshow-fullwidth-item item">';
            $output .= '<div class="sppb-slide-item-bg sppb-slideshow-fullwidth-item-bg" ' . $bg_image . '>';
            $output .= '<div class="container">';
            $output .= '<div class="col-sm-8 col-md-7 col-lg-5">';
            $output .= '<div class="sppb-slideshow-fullwidth-item-text">';

            if (($slide_item->title) || ($slide_item->content)) {

                $sub_title = ($slide_item->sub_title) ? '<small class="sppb-slidehsow-sub-title ' . $slide_item->subtitle_animation . '" ' . $subtitle_data_attr . '>' . $slide_item->sub_title . '</small>' : '';

                if ($slide_item->title) {
                    $output .= '<h1 class="sppb-fullwidth-title ' . $slide_item->title_animation . '" ' . $title_data_attr . '> ' . $slide_item->title . $sub_title . ' </h1>';
                }

                if ($slide_item->content) {
                    $output .= '<p class="details ' . $slide_item->cotent_animation . '" ' . $content_data_attr . '>' . $slide_item->content . '</p>';
                }

                if (($slide_item->button_one_text && $slide_item->button_one_url) || ($slide_item->button_two_text && $slide_item->button_two_url)) {
                    $output .= '<div class="sppb-fw-slider-button-wrapper ' . $slide_item->button_animation . '" ' . $button_data_attr . '> ';
                    if ($slide_item->button_one_text && $slide_item->button_one_url) {
                        $output .= '<a target="' . $slide_item->target . '" href="' . $slide_item->button_one_url . '" class="btn btn-primary"> <span>' . $slide_item->button_one_text . '</span></a>';
                    }

                    $output .= '</div>';
                }
            }

            $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item-text
            $output .= '</div>'; // END:: /.col-sm-8 col-md-7 col-lg-5
            $output .= '</div>'; // END:: /.container
            $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item-bg
            $output .= '</div>'; // END:: /.sppb-slideshow-fullwidth-item
        }

        $output .= '</div>'; //END:: /.sppb-slider-items
        $output .= '</div>'; // END:: /.sppb-slider-item-wrapper
        // has next/previous arrows
        if ($arrows) {
            $output .= '<div class="customNavigation">';
            $output .= '<div class="container">';
            $output .= '<a class="sppbSlidePrev"><i class="fa fa-angle-left"></i></a>';
            $output .= '<a class="sppbSlideNext"><i class="fa fa-angle-right"></i></a>';
            $output .= '</div>';
            $output .= '</div>'; // END:: /.customNavigation
        }

        $output .= '</div>'; // /.sppb-slider-wrapper
        // has dot controls
        if ($controllers) {
            $output .='<div class="owl-dots">';
            $output .='<div class="owl-dot active"><span></span></div>';
            $output .='<div class="owl-dot"><span></span></div>';
            $output .='<div class="owl-dot"><span></span></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 stylesheets() {
        $app = JFactory::getApplication();
        $base_path = JURI::base() . '/templates/' . $app->getTemplate() . '/css/';
        return array($base_path . 'owl.carousel.css', $base_path . 'owl.theme.css', $base_path . 'owl.transitions.css', $base_path . 'slide-animate.css');
    }

    public function css() {
        $addon_id = '#sppb-addon-' . $this->addon->id;
        $addont_styles = '';
        $addont_styles .= (isset($this->addon->settings->background) && $this->addon->settings->background) ? 'background: ' . $this->addon->settings->background . '; ' : '';
        $addont_styles .= (isset($this->addon->settings->color) && $this->addon->settings->color) ? 'color: ' . $this->addon->settings->color . '; ' : '';

        $css = '';
        if ($addont_styles) {
            $css .= $addon_id . ' .sppb-slider-fullwidth-wrapper .sppb-slider-item-wrapper {';
            $css .= $addont_styles;
            $css .= '}';
        }

        return $css;
    }

}
