<?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\Category;
defined('_JEXEC') or die;
use DJExtensions\DJCatalog2\YOOtheme\Builder\Source\CategoryHelper;
class CategoryQueryType
{
	/**
	 * @return array
	 */
	public static function config()
	{
		return [

			'fields' => [

				'singlecategoryproduct' => [
					'type' => 'SingleCategoryProduct',
					'metadata' => [
						'view' => ['com_djcatalog2.items.list'],
						'label' => 'Single Category',
						'group' => 'DJ-Catalog2',
						'fields' => [


						]
					],
					'extensions' => [
						'call' => __CLASS__ . '::resolve',
					],
				],
			],
		];
	}

	public static function resolve($root, array $args, $context, $info)
	{
		$app = \JFactory::getApplication();
		$cid = $app->input->get('cid', '', 'array');
		if(!empty($cid)){
			$cidString = $cid[0];
			$cid = explode(":",$cidString);
			$cid = $cid[0];
		}
		if(empty($cid)) $cid = 0;
		$category = CategoryHelper::getItem($cid);


		return $category;
	}


}
