<?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;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;

class ItemReviewsType
{
	/**
	 * @return array
	 */
	public static function config()
	{
		return [

			'fields' => [
				'review' => [
					'type' => 'String',
					'extensions' => [
						'call' => __CLASS__ . '::review',
					],
					'metadata' => [
						'label' => 'Review',
					],
				],
				'vote' => [
					'type' => 'String',
					'extensions' => [
						'call' => __CLASS__ . '::vote',
					],
					'metadata' => [
						'label' => 'Vote',
					],
				],
			],
			'metadata' => [
				'type' => true,
				'label' => 'Product Reviews',
			],

		];
	}

	public static function review($item)
	{
		$params = ComponentHelper::getParams('com_djcatalog2');
		$html = '';

		if ($params->get('product_rating', false) && $params->get('show_rating_item', true)) {
			$displayData['review'] = $item->review;
			$displayData['rating'] = $item->rating;
			$displayData['item_author'] = $item->author;
			$displayData['created'] = $item->created;
			$displayData['item_id'] = $item->item_id;
			$displayData['item_name'] = $item->item_name;
			$displayData['rating_count'] = $item->rating_count;
			$displayData['context'] = 'com_djcatalog2.item';
			$displayData['params'] = $params;

			$html .= '<div class="djc_item_rating">';
			ob_start();
			include JPATH_SITE . '/plugins/system/djc2yootheme/modules/html/item/singleReviewComment.php';
			$html .= ob_get_contents();
			ob_end_clean();
			$html .= '</div>';
		}

		return $html;
	}

	public static function vote($item)
	{
		$params = ComponentHelper::getParams('com_djcatalog2');
		$html = '';

		if ($params->get('product_rating', false) && $params->get('show_rating_item', true)) {
			$displayData['review'] = $item->review;
			$displayData['rating'] = $item->rating;
			$displayData['item_author'] = $item->author;
			$displayData['created'] = $item->created;
			$displayData['item_id'] = $item->item_id;
			$displayData['item_name'] = $item->item_name;
			$displayData['rating_count'] = $item->rating_count;
			$displayData['context'] = 'com_djcatalog2.item';
			$displayData['params'] = $params;

			$html .= '<div class="djc_item_rating">';
			ob_start();
			include JPATH_SITE . '/plugins/system/djc2yootheme/modules/html/item/singleReviewRating.php';
			$html .= ob_get_contents();
			ob_end_clean();
			$html .= '</div>';
		}

		return $html;
	}
}
