package main

import "html/template"

type FileMetadataPageParams struct {
	BaseEventPageParams
	OpenGraphParams
	HeadParams

	Details DetailsParams
	Content template.HTML

	FileMetadata Kind1063Metadata
	IsImage      bool
	IsVideo      bool

	Clients []ClientReference
}

templ fileMetadataInnerBlock(params FileMetadataPageParams) {
	if params.FileMetadata.Image != "" {
		<img src={ params.FileMetadata.Image } alt={ params.Alt }/>
	} else if params.IsImage {
		<img src={ params.FileMetadata.URL } alt={ params.Alt }/>
	} else if params.IsVideo {
		<video
			controls
			width="100%%"
			class="max-h-[90vh] bg-neutral-300 dark:bg-zinc-700"
		>
			<source src={ params.FileMetadata.URL } alt={ params.Alt }/>
		</video>
	}
	<a
		href={ templ.URL(params.FileMetadata.URL) }
		target="_new"
		class="not-prose mx-auto mb-3 block w-4/5 basis-full rounded-lg border-0 bg-strongpink px-4 py-2 text-center text-[17px] font-light text-white no-underline sm:w-2/6"
	>Download file</a>
}

templ fileMetadataTemplate(params FileMetadataPageParams, isEmbed bool) {
	<!DOCTYPE html>
	if isEmbed {
		@embeddedPageTemplate(
			params.Event,
			params.NeventNaked,
		) {
			@fileMetadataInnerBlock(params)
		}
	} else {
		@eventPageTemplate(
			"File Metadata",
			params.OpenGraphParams,
			params.HeadParams,
			params.Clients,
			params.Details,
			params.Event,
		) {
			@fileMetadataInnerBlock(params)
		}
	}
}

templ fileMetadataDetails(params FileMetadataPageParams) {
	if params.FileMetadata.Summary != "" {
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Summary</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ params.FileMetadata.Summary }</span>
		</div>
	}
	if params.FileMetadata.Dim != "" {
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Dimension</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ params.FileMetadata.Dim }</span>
		</div>
	}
	if params.FileMetadata.Size != "" {
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Size</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ params.FileMetadata.Size } bytes</span>
		</div>
	}
	if params.FileMetadata.Magnet != "" {
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Magnet URL</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ params.FileMetadata.Magnet }</span>
		</div>
	}
}
