<?php
/**
 * @package DJ-Catalog2-Yootheme
 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
 * @license http://www.gnu.org/licenses GNU/GPL
 * @author url: http://dj-extensions.com
 * @author email contact@dj-extensions.com
 */

namespace DJExtensions\DJCatalog2\YOOtheme\Builder\Source\Type\Item;
defined('_JEXEC') or die;
class ItemSectionsType
{
	/**
	 * @return array
	 */
	public static function config()
	{
		return [

			'fields' => [
				'title' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Title',
					],
					'extensions' => [
						'call' => __CLASS__ . '::title',
					],

				],
				'caption' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Caption',
					],
					'extensions' => [
						'call' => __CLASS__ . '::caption',
					],

				],
				'image' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Image',
					],
					'extensions' => [
						'call' => __CLASS__ . '::image',
					],

				],
				'content' => [
					'type' => 'String',
					'metadata' => [
						'label' => 'Content',
					],
					'extensions' => [
						'call' => __CLASS__ . '::content',
					],

				],


			],
			'metadata' => [
				'type' => true,
				'label' => "Product's Sections",
			],

		];
	}

	public static function title($sections)
	{
		return $sections['title'];
	}

	public static function caption($sections)
	{

		return $sections['caption'];
	}

	public static function content($sections)
	{
		if(isset($sections['article'])){
			//load article here
			$args = array();
			$args['article'] = $sections['article'][0];
			$article = \YOOtheme\Builder\Joomla\Source\ArticleHelper::query($args);
			return $article[0]->introtext;
		}
		return $sections['content'];
	}

	public static function image($sections)
	{
		return $sections['image'];
	}
}
