<?php
//no direct accees
defined ('_JEXEC') or die ('restricted aceess');

class SppagebuilderAddonJd_tab extends SppagebuilderAddons {

	public function render() {

		$class = (isset($this->addon->settings->class) && $this->addon->settings->class) ? $this->addon->settings->class : '';
		$style = (isset($this->addon->settings->style) && $this->addon->settings->style) ? $this->addon->settings->style : '';
		$title = (isset($this->addon->settings->title) && $this->addon->settings->title) ? $this->addon->settings->title : '';
        $display_tab_title = (isset($this->addon->settings->display_tab_title) && $this->addon->settings->display_tab_title) ? 1 : 0;
		$heading_selector = (isset($this->addon->settings->heading_selector) && $this->addon->settings->heading_selector) ? $this->addon->settings->heading_selector : 'h3';

		//Output
		$output  = '<div class="sppb-addon jd-tab '.($display_tab_title?'jd-tab-title-hidden':'').' sppb-addon-tab ' . $class . '">';
		$output .= ($title) ? '<'.$heading_selector.' class="sppb-addon-title">' . $title . '</'.$heading_selector.'>' : '';
		$output .= '<div class="sppb-addon-content sppb-tab">';
		
		//Tab Title
		$output .='<ul class="sppb-nav">';
		foreach ($this->addon->settings->sp_tab_item as $key => $tab) {
			$title = (isset($tab->tab_media) && $tab->tab_media) ? '<img class="tab_image" src="' . $tab->tab_media . '">' . $tab->title : $tab->title;
			$output .='<li class="'. ( ($key==0) ? "active" : "").'"><a data-toggle="sppb-tab" href="#sppb-tab-'. ($this->addon->id + $key) .'">'. $title .'</a></li>';
		}
		$output .='</ul>';
		$output .='<div class="sppb-tab-content sppb-nav-' . '-content">';
		foreach ($this->addon->settings->sp_tab_item as $key => $tab) {
			$numofmemberperrow = $tab->numofmemberperrow;
			$viewmoretext = $tab->viewmoretext;
			$viewmorelink = $tab->viewmorelink;
			$output .='<div id="sppb-tab-'. ($this->addon->id + $key) .'" class="sppb-row sppb-tab-pane sppb-fade'. ( ($key==0) ? " active in" : "").'"><div class="jd_tab_member_list sppb-row">';
			$numberOfFields =6;
			for ($q = 1; $q <= $numberOfFields; $q++){
			 if (!empty($tab->{"member".$q."name"}) || !empty($tab->{"member".$q."image"})){
						$output .='<div class="member '.$class.' sppb-col-sm-'. round(12/$numofmemberperrow).'"><div class="jd_members_tab">
									<div class="jd_members_tab_inner">
										<img src="'.$tab->{'member'.$q.'image'}.' "/>
										<div class="jd_members_desc">
                                            <a href="'.(empty($tab->{'member'.$q.'_profile_link'})?'#':$tab->{'member'.$q.'_profile_link'}).'">
											<span class="jd_name">'.$tab->{'member'.$q.'name'}.'</span>
											<span class="jd_specialty">'.$tab->{'member'.$q.'specialty'}.'</span>
                                            </a>
										</div>
									</div>
								</div>
								</div>
							';
				}
			}
				$output .= '<div class="clr"></div>';
				$output .= '</div>';
				$output .= '<div class="jd_viewmore"><a href="'.$viewmorelink.'">'.$viewmoretext.'</a></div>';
			$output .= '</div>';
		}
		$output .='</div>';
		$output .= '</div>';
		$output .= '</div>';

		return $output;

	}

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

		$css = '';
		if($tab_style == 'pills') {
			$style .= (isset($this->addon->settings->active_tab_bg) && $this->addon->settings->active_tab_bg) ? 'background-color: ' . $this->addon->settings->active_tab_bg . ';': '';
			if($style) {
				$css .= $addon_id . ' .sppb-nav-pills > li.active > a,' . $addon_id . ' .sppb-nav-pills > li.active > a:hover,' . $addon_id . ' .sppb-nav-pills > li.active > a:focus {';
				$css .= $style;
				$css .= '}';
			}
		} else if ($tab_style == 'lines') {
			$style .= (isset($this->addon->settings->active_tab_bg) && $this->addon->settings->active_tab_bg) ? 'border-bottom-color: ' . $this->addon->settings->active_tab_bg . ';': '';
			if($style) {
				$css .= $addon_id . ' .sppb-nav-lines > li.active > a,' . $addon_id . ' .sppb-nav-lines > li.active > a:hover,' . $addon_id . ' .sppb-nav-lines > li.active > a:focus {';
				$css .= $style;
				$css .= '}';
			}
		}

		return $css;
	}

}
