<?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 YOOtheme;
defined('_JEXEC') or die;



return [

	'transforms' => [

		'render' => function ($node) {

			// Define props that are available only in nested panels in order to avoid `Undefined index` notices.
			$undefined_index = ["labels_style_border_size",
				"title_style",
				"title_link",
				"title_hover_style",
				"title_decoration",
				"title_font_family",
				"title_color",
				"title_element",
				"title_margin",
				"sku_text_style",
				"sku_text_hover_style",
				"sku_text_decoration",
				"sku_text_font_family",
				"sku_text_color",
				"sku_text_element",
				"sku_margin",
				"hits_text_style",
				"hits_text_hover_style",
				"hits_text_decoration",
				"hits_text_font_family",
				"hits_text_color",
				"hits_text_element",
				"hits_margin",
				"availinfo_text_style",
				"availinfo_text_hover_style",
				"availinfo_text_decoration",
				"availinfo_text_font_family",
				"availinfo_text_color",
				"availinfo_text_element",
				"availinfo_margin",
				"createdby_text_style",
				"createdby_text_hover_style",
				"createdby_text_decoration",
				"createdby_text_font_family",
				"createdby_text_color",
				"createdby_text_element",
				"createdby_margin",
				"createdon_text_style",
				"createdon_text_hover_style",
				"createdon_text_decoration",
				"createdon_text_font_family",
				"createdon_text_color",
				"createdon_text_element",
				"createdon_margin",
				"price_text_style",
				"price_text_hover_style",
				"price_text_decoration",
				"price_text_font_family",
				"price_text_color",
				"price_text_element",
				"price_margin",
				"address_text_style",
				"address_text_hover_style",
				"address_text_decoration",
				"address_text_font_family",
				"address_text_color",
				"address_text_element",
				"address_margin",
				"city_text_style",
				"city_text_hover_style",
				"city_text_decoration",
				"city_text_font_family",
				"city_text_color",
				"city_text_element",
				"city_margin",
				"postcode_text_style",
				"postcode_text_hover_style",
				"postcode_text_decoration",
				"postcode_text_font_family",
				"postcode_text_color",
				"postcode_text_element",
				"postcode_margin",
				"country_text_style",
				"country_text_hover_style",
				"country_text_decoration",
				"country_text_font_family",
				"country_text_color",
				"country_text_element",
				"country_margin",
				"state_text_style",
				"state_text_hover_style",
				"state_text_decoration",
				"state_text_font_family",
				"state_text_color",
				"state_text_element",
				"state_margin",
				"phone_text_style",
				"phone_text_hover_style",
				"phone_text_decoration",
				"phone_text_font_family",
				"phone_text_color",
				"phone_text_element",
				"phone_margin",
				"mobile_text_style",
				"mobile_text_hover_style",
				"mobile_text_decoration",
				"mobile_text_font_family",
				"mobile_text_color",
				"mobile_text_element",
				"mobile_margin",
				"fax_text_style",
				"fax_text_hover_style",
				"fax_text_decoration",
				"fax_text_font_family",
				"fax_text_color",
				"fax_text_element",
				"fax_margin",
				"website_text_style",
				"website_text_hover_style",
				"website_text_decoration",
				"website_text_font_family",
				"website_text_color",
				"website_text_element",
				"website_margin",
				"email_text_style",
				"email_text_hover_style",
				"email_text_decoration",
				"email_text_font_family",
				"email_text_color",
				"email_text_element",
				"email_margin",
				"rating_text_style",
				"rating_text_hover_style",
				"rating_text_decoration",
				"rating_text_font_family",
				"rating_text_color",
				"rating_text_element",
				"rating_margin",
				"vote_text_style",
				"vote_text_hover_style",
				"vote_text_decoration",
				"vote_text_font_family",
				"vote_text_color",
				"vote_text_element",
				"vote_margin",
				"order_labels",
				"order_product_video",
				"order_category",
				"order_product_image",
				"order_category_image",
				"order_producer",
				"order_producer_image",
				"order_title",
				"order_sku",
				"order_hits",
				"order_availinfo",
				"order_createdby",
				"order_createdon",
				"order_price",
				"order_compare",
				"order_wishlist",
				"order_introdescription",
				"order_description",
				"order_attributes",
				"order_readmore",
				"order_addtocart",
				"order_address",
				"order_city",
				"order_postcode",
				"order_country",
				"order_state",
				"order_phone",
				"order_mobile",
				"order_fax",
				"order_website",
				"order_email",
				"order_rating",
				"order_vote"
			];
			foreach($undefined_index as $x)
				if (!isset($node->props[$x])) {
					$node->props[$x] = '';
				}

			$node->tags = [];
		},

	],

	'updates' => [

		'2.1.0-beta.0.1' => function ($node, array $params) {

			if (@$node->props['item_maxwidth'] === 'xxlarge') {
				$node->props['item_maxwidth'] = '2xlarge';
			}

			if (@$node->props['title_grid_width'] === 'xxlarge') {
				$node->props['title_grid_width'] = '2xlarge';
			}

			if (@$node->props['image_grid_width'] === 'xxlarge') {
				$node->props['image_grid_width'] = '2xlarge';
			}

			if (!empty($node->props['icon_ratio'])) {
				$node->props['icon_width'] = round(20 * $node->props['icon_ratio']);
				unset($node->props['icon_ratio']);
			}

		},

		'2.0.0-beta.8.1' => function ($node) {

			if (isset($node->props['grid_align'])) {
				$node->props['grid_column_align'] = $node->props['grid_align'];
				unset($node->props['grid_align']);
			}

		},

		'2.0.0-beta.5.1' => function ($node) {

			if (@$node->props['link_type'] === 'content') {
				$node->props['title_link'] = true;
				$node->props['image_link'] = true;
				$node->props['link_text'] = '';
			} elseif (@$node->props['link_type'] === 'element') {
				$node->props['panel_link'] = true;
				$node->props['link_text'] = '';
			}
			unset($node->props['link_type']);

		},

		'1.22.0-beta.0.1' => function ($node) {

			if (isset($node->props['gutter'])) {
				$node->props['grid_column_gap'] = $node->props['gutter'];
				$node->props['grid_row_gap'] = $node->props['gutter'];
				unset($node->props['gutter']);
			}

			if (isset($node->props['divider'])) {
				$node->props['grid_divider'] = $node->props['divider'];
				unset($node->props['divider']);
			}

			if (isset($node->props['filter_gutter'])) {
				$node->props['filter_grid_column_gap'] = $node->props['filter_gutter'];
				$node->props['filter_grid_row_gap'] = $node->props['filter_gutter'];
				unset($node->props['filter_gutter']);
			}

			if (isset($node->props['filter_breakpoint'])) {
				$node->props['filter_grid_breakpoint'] = $node->props['filter_breakpoint'];
				unset($node->props['filter_breakpoint']);
			}

			if (isset($node->props['title_gutter'])) {
				$node->props['title_grid_column_gap'] = $node->props['title_gutter'];
				$node->props['title_grid_row_gap'] = $node->props['title_gutter'];
				unset($node->props['title_gutter']);
			}

			if (isset($node->props['title_breakpoint'])) {
				$node->props['title_grid_breakpoint'] = $node->props['title_breakpoint'];
				unset($node->props['title_breakpoint']);
			}

			if (isset($node->props['image_gutter'])) {
				$node->props['image_grid_column_gap'] = $node->props['image_gutter'];
				$node->props['image_grid_row_gap'] = $node->props['image_gutter'];
				unset($node->props['image_gutter']);
			}

			if (isset($node->props['image_breakpoint'])) {
				$node->props['image_grid_breakpoint'] = $node->props['image_breakpoint'];
				unset($node->props['image_breakpoint']);
			}

		},

		'1.20.0-beta.1.1' => function ($node) {

			if (isset($node->props['maxwidth_align'])) {
				$node->props['block_align'] = $node->props['maxwidth_align'];
				unset($node->props['maxwidth_align']);
			}

		},

		'1.20.0-beta.0.1' => function ($node) {

			if (@$node->props['title_style'] === 'heading-hero') {
				$node->props['title_style'] = 'heading-xlarge';
			}

			if (@$node->props['title_style'] === 'heading-primary') {
				$node->props['title_style'] = 'heading-medium';
			}

			/**
			 * @var Config $config
			 */
			$config = app(Config::class);

			list($style) = explode(':', $config('~theme.style'));

			if (in_array($style, ['craft', 'district', 'jack-backer', 'tomsen-brody', 'vision', 'florence', 'max', 'nioh-studio', 'sonic', 'summit', 'trek'])) {

				if (@$node->props['title_style'] === 'h1' || (empty($node->props['title_style']) && @$node->props['title_element'] === 'h1')) {
					$node->props['title_style'] = 'heading-small';
				}

			}

			if (in_array($style, ['florence', 'max', 'nioh-studio', 'sonic', 'summit', 'trek'])) {

				if (@$node->props['title_style'] === 'h2') {
					$node->props['title_style'] = @$node->props['title_element'] === 'h1' ? '' : 'h1';
				} elseif (empty($node->props['title_style']) && @$node->props['title_element'] === 'h2') {
					$node->props['title_style'] = 'h1';
				}

			}

			if (in_array($style, ['fuse', 'horizon', 'joline', 'juno', 'lilian', 'vibe', 'yard'])) {

				if (@$node->props['title_style'] === 'heading-medium') {
					$node->props['title_style'] = 'heading-small';
				}

			}

			if (in_array($style, ['copper-hill'])) {

				if (@$node->props['title_style'] === 'heading-medium') {
					$node->props['title_style'] = @$node->props['title_element'] === 'h1' ? '' : 'h1';
				} elseif (@$node->props['title_style'] === 'h1') {
					$node->props['title_style'] = @$node->props['title_element'] === 'h2' ? '' : 'h2';
				} elseif (empty($node->props['title_style']) && @$node->props['title_element'] === 'h1') {
					$node->props['title_style'] = 'h2';
				}

			}

			if (in_array($style, ['trek', 'fjord'])) {

				if (@$node->props['title_style'] === 'heading-medium') {
					$node->props['title_style'] = 'heading-large';
				}

			}

			if (in_array($style, ['juno', 'vibe', 'yard'])) {

				if (@$node->props['title_style'] === 'heading-xlarge') {
					$node->props['title_style'] = 'heading-medium';
				}

			}

			if (in_array($style, ['district', 'florence', 'flow', 'nioh-studio', 'summit', 'vision'])) {

				if (@$node->props['title_style'] === 'heading-xlarge') {
					$node->props['title_style'] = 'heading-large';
				}

			}

			if (in_array($style, ['lilian'])) {

				if (@$node->props['title_style'] === 'heading-xlarge') {
					$node->props['title_style'] = 'heading-2xlarge';
				}

			}

		},

		'1.19.0-beta.0.1' => function ($node) {

			if (@$node->props['meta_align'] === 'top') {
				$node->props['meta_align'] = 'above-title';
			}

			if (@$node->props['meta_align'] === 'bottom') {
				$node->props['meta_align'] = 'below-title';
			}

			if (@$node->props['link_style'] === 'panel') {
				if (@$node->props['panel_style']) {
					$node->props['link_type'] = 'element';
				} else {
					$node->props['link_type'] = 'content';
				}
				$node->props['link_style'] = 'default';
			}

			if (isset($node->props['image_card'])) {
				$node->props['panel_card_image'] = $node->props['image_card'];
				unset($node->props['image_card']);
			}

		},

		'1.18.10.3' => function ($node) {

			if (@$node->props['meta_align'] === 'top') {
				if (!empty($node->props['meta_margin'])) {
					$node->props['title_margin'] = $node->props['meta_margin'];
				}
				$node->props['meta_margin'] = '';
			}

		},

		'1.18.10.1' => function ($node) {

			if (isset($node->props['image_inline_svg'])) {
				$node->props['image_svg_inline'] = $node->props['image_inline_svg'];
				unset($node->props['image_inline_svg']);
			}

			if (isset($node->props['image_animate_svg'])) {
				$node->props['image_svg_animate'] = $node->props['image_animate_svg'];
				unset($node->props['image_animate_svg']);
			}

		},

		'1.18.0' => function ($node) {

			if (!isset($node->props['grid_parallax']) && @$node->props['grid_mode'] === 'parallax') {
				$node->props['grid_parallax'] = @$node->props['grid_parallax_y'];
			}

			if (!isset($node->props['image_box_decoration']) && @$node->props['image_box_shadow_bottom'] === true) {
				$node->props['image_box_decoration'] = 'shadow';
			}

			if (!isset($node->props['meta_color']) && @$node->props['meta_style'] === 'muted') {
				$node->props['meta_color'] = 'muted';
				$node->props['meta_style'] = '';
			}

		},

	],

];
