<?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;
defined('_JEXEC') or die;
use YOOtheme\Builder;
use YOOtheme\Path;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use YOOtheme\Builder\Source\SourceTransform;
use YOOtheme\Config;

return [

	'routes' => [
		['post', '/djc2page', ItemListener::class . '@savePage'],
		['get', '/producers', [SourceController::class, 'producers']],
		['get', '/producer', [SourceController::class, 'producer']],
		['get', '/items', [SourceController::class, 'items']],
		['get', '/item', [SourceController::class, 'item']],
	],

	'actions' => [
		'onPrepareItemDescription' => [
			ItemListener::class => ['@prepareContent', -55],
		],

		'onLoadTemplate' => [
			ItemListener::class => ['loadTemplate', 15],
			ProducerListener::class => ['loadTemplate', 15]
		],
	],

	'events' => [

		'source.init' => [
			SourceListener::class => 'initSource',
		],

		'customizer.init' => [
			SourceListener::class => 'initCustomizer',
		],
		'builder.template' => [
			TemplateListener::class => 'matchTemplate',
		],
	],

	'extend' => [

		Builder::class => function (Builder $builder) {
			$builder->addTypePath(Path::get('./elements/*/element.json'));
		},

		Config::class => function (Config $config){
			$config->addFile('djcatalog2', Path::get('../config/djcatalog2.json'));
			$config->addFilter('djcatalog2', function ($value) use ($config) { // map djcatalog2: to djcatalog2.
				return $config->get("djcatalog2.{$value}");
			});
		},

		SourceTransform::class => function (SourceTransform $transform, $app) {
			$transform->addFilter('date', function ($value, $format) {
				return HTMLHelper::_('date', $value, $format ?: Text::_('DATE_FORMAT_LC3'));
			});
		},
	],
];
