<?php 
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;

AriKernel::import('Application.ARISmartContent.Plugin.CollectionPlugin');

class plgArismartcontentTabs extends AriSmartContentPluginContent
{
	var $_supportNestedTags = true;
	var $_optionsMapping = array(
		'active' => 'widget_active',
		'collapsible' => 'widget_collapsible',
		'event' => 'widget_event',
		'heightStyle' => 'widget_heightStyle',
		'show_duration' => 'widget_show_duration',
		'show_fx' => 'widget_show_easing',
		'hide_duration' => 'widget_hide_duration',
		'hide_fx' => 'widget_hide_easing'
	);
	
	function getTag()
	{
		return 'tabs';
	}

	function contentPluginHandler($params, $content, $sourceContent) 
	{
		jimport('arismartcontent.tabs.tabs');

		$id = AriUtils::getParam($params, 'id');
		if (empty($id))
			$id = uniqid('tabs_', false);

		$tabs = new AriSmartContentWidgetTabs($id, $this->getMergedParams($params));
		$source = AriUtils::getParam($params, 'source');
		
		$output = '';
		if (!empty($source))
			$output = $tabs->getOutput('render');
		else
		{
			$items = $this->getTabsItems($content);
			$output = $tabs->getOutput('renderItems', $items);
		}

		return $output;
	}
	
	function getTabsItems($content)
	{
		$collectionPlugin = new AriSmartContentPluginContentCollection('tab');
		$items = $collectionPlugin->getItems($content);
		
		$tabsItems = array();
		if (!is_array($items))
			return $tabsItems;
			
		foreach ($items as $item)
		{
			$title = AriUtils::getParam($item['params'], 'title', '');

			$tabsItems[] = array(
				'title' => $title,
				'content' => $item['content']
			);
		}
		
		return $tabsItems;
	}
}