<?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;
/**
 * @var ImageProvider $imageProvider
 */
$imageProvider = app(ImageProvider::class);

$el = $this->el('div',[

	'class' => $this->expr([
		'djc_product_video',
		'uk-inline {@position_inline_video}' => ['position_inline_video' => $element['position_inline_video']],
	], $element),

]);

// Video
$video = $this->el('video', [


	'class' => $this->expr([
		'djc-video',
		'uk-margin[-{video_margin}]-top {@!video_margin: remove}',
		'uk-margin-remove-top {@video_margin: remove}',
		'uk-margin-remove-bottom',
	], $element),
	'width' => ['{video_width}'],
	'height' => ['{video_height}'],
	'grid' => true,
], '');

// Iframe?
if ($iframe = $this->iframeVideo($props['video'], [], false)) {

	if ($props['video_width'] && !$props['video_height']) {
		$video->attr('height', round($props['video_width'] * 9 / 16));
	} elseif ($props['video_height'] && !$props['video_width']) {
		$video->attr('width', round($props['video_height'] * 16 / 9));
	}

	$iframe = $video($props, [
		'src' => $iframe,
		'frameborder' => 0,
		'allowfullscreen' => true,
		'uk-responsive' => true,
	], '', 'iframe');

} else {

	$video->attr([
		'src' => ['{video}'],
		'controls' => $props['video_controls'],
		'loop' => $props['video_loop'],
		'muted' => $props['video_muted'],
		'playsinline' => $props['video_playsinline'],
		'preload' => ['none {@video_lazyload}'],
		'poster' => $props['video_poster'] && ($props['video_width'] || $props['video_height'])
			? $imageProvider->getUrl("{$props['video_poster']}#thumbnail={$props['video_width']},{$props['video_height']}")
			: $props['video_poster'],
		$props['video_autoplay'] === 'inview' ? 'uk-video' : 'autoplay' => $props['video_autoplay'],
	]);

}


//Style position && size of an element
$el->attr('style', [
	'position:{position_video};' => ['position_video' => $element['position_video']],
	'left: {position_left_video}px;' => ['position_left_video' => $element['position_left_video']],
	'right: {position_right_video}px;' => ['position_right_video' => $element['position_right_video']],
	'top: {position_top_video}px;' => ['position_top_video' => $element['position_top_video']],
	'bottom: {position_bottom_video}px;' => ['position_bottom_video' => $element['position_bottom_video']],
	'z-index:{position_z_index_video};' => ['position_z_index_video' => $element['position_z_index_video']],

], $element);

echo $el($props, $attrs, ($iframe ?: $video($props)));
