@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Frontend
@using System.IO

@if (Model.Item is null) return;

<div data-swift-poster="bottom-left" class="d-grid position-relative align-content-end" data-swift-poster-height="@(Model.Item.GetString("Height"))">
	@if(Model.Item.TryGetVideo("VideoSource", out VideoViewModel? video)) {
		<figure class="position-absolute top-0 bottom-0 end-0 start-0 m-0 pe-none ratio overflow-hidden" itemscope itemtype="https://schema.org/VideoObject">	
			@if (Model.Item.TryGetString("VideoName", out string? videoName)) 
			{
				<meta itemprop="name" content="@videoName"/>
			} 
			else 
			{
				<meta itemprop="name" content="@video.Name"/>
			}
			@if (Model.Item.TryGetString("VideoDescription", out string? videoDescription)) 
			{
				<meta itemprop="description" content="@videoDescription"/>
			}
			<meta itemprop="contentUrl" content="@video.Path"/>
			<meta itemprop="thumbnailUrl" content="@video.Thumbnail"/>

			@if (video.IsExternalLink())
			{
				<iframe src="@(video.ToEmbedUrl())?autoplay=1&controls=0&showinfo=0&rel=0&mute=1&muted=1&loop=1&autopause=0&background=0" class="object-fit-cover" title="@video.Name" frameborder="0" allow="fullscreen; autoplay;encrypted-media;"></iframe>
			}
			else
			{
				<video preload="auto" loop autoplay muted playsinline class="object-fit-cover">
					<source src="@(video.Path)" type="video/@Path.GetExtension(video.Path)?.ToLower().Replace(".", string.Empty)">
				</video>
			}
		</figure>
	}

	<div data-swift-container class="position-relative z-1">
		<div data-swift-text class="mb-0-last-child">
			@if (Model.Item.TryGetString("Eyebrow", out string? eyebrow)) {
				@eyebrow
			}
			@if (Model.Item.TryGetString("Title", out string? title)) {
				@title
			}
			@if (Model.Item.TryGetString("Text", out string? text)) {
				@text
			}
		</div>
		<div class="d-flex flex-wrap gap-2 align-items-center">
			@if (Model.Item.TryGetButton("FirstButton", out ButtonViewModel? firstButton)) {
				<a role="button" href="@firstButton.Link?.Url" class="btn btn-@firstButton.Style" data-dw-button="@firstButton.Style" aria-label="@firstButton.Label">@firstButton.Label</a>
			}
			@if (Model.Item.TryGetButton("SecondButton", out ButtonViewModel? secondButton)) {
				<a role="button" href="@secondButton.Link?.Url" class="btn btn-@secondButton.Style" data-dw-button="@secondButton.Style" aria-label="@secondButton.Label">@secondButton.Label</a>
			}
		</div>
	</div>
</div>
