package main

import (
	"strconv"
)

templ detailsTemplate(details DetailsParams) {
	<div class="-ml-4 mb-6 h-1.5 w-1/3 bg-zinc-100 dark:bg-zinc-700 sm:-ml-2.5"></div>
	if details.Metadata.Npub() != "" {
		<div class="mb-6 break-all leading-5">
			<div class="text-sm text-strongpink">Author Public Key</div>
			<a href={ templ.SafeURL("/" + details.Metadata.Npub()) } class="text-neutral-500 dark:text-neutral-300 text-[16px] underline-offset-[6px] hover:underline">{ details.Metadata.Npub() }</a>
		</div>
	}
	if details.Extra != nil {
		@details.Extra
	}
	<span></span>
	if len(details.SeenOn) != 0 {
		<div class="mb-6 leading-5 text-neutral-500 dark:text-neutral-300 text-[16px]">
			<div class="text-sm text-strongpink">Seen on</div>
			for _, v := range details.SeenOn {
				<a
					href={ templ.URL("/r/" + v) }
					class="underline-none pr-2 decoration-neutral-200 decoration-1 underline-offset-[6px] hover:underline"
				>{ v }</a>
			}
		</div>
	}
	<!-- details hidden behind a toggle -->
	if details.HideDetails {
		<div class="mb-6 flex items-center print:hidden">
			<input
				type="checkbox"
				id="advanced-switch"
				class="hidden"
				_="on load make a URLSearchParams from location.search then get it.get('details') then if it is 'yes' set my.checked to true then trigger switch on me end
				   on change or switch log my checked then if my checked is true
				     remove .hidden from #hidden-fields
				     tell the next <label /> from me
				       add .bg-strongpink .after:translate-x-full
				       remove .bg-gray-300 .dark:bg-zinc-800
				     end
				   otherwise
				     add .hidden to #hidden-fields
				     tell the next <label /> from me
				       remove .bg-strongpink .after:translate-x-full
				       add .bg-gray-300 .dark:bg-zinc-800
				     end
				   end
				"
			/>
			<label for="advanced-switch" class="after:content-[''] relative mr-2 inline-block h-5 w-9 cursor-pointer rounded-full bg-gray-300 -indent-96 after:absolute after:inset-0.5 after:h-4 after:w-4 after:rounded-2xl after:bg-zinc-50 after:transition dark:bg-zinc-800 dark:after:bg-gray-700">
				&nbsp;
			</label>
			<label
				for="advanced-switch"
				class="cursor-pointer leading-4 underline text-neutral-500 dark:text-neutral-300 text-[16px] decoration-neutral-200 dark:decoration-neutral-500 decoration-1 underline-offset-[6px]"
			>Show more details</label>
		</div>
	}
	<div id="hidden-fields" class={ templ.KV("hidden", details.HideDetails) }>
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Published at</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ details.CreatedAt }</span>
		</div>
		<div class="mb-6 leading-5">
			<div class="text-sm text-strongpink">Kind type</div>
			<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ strconv.Itoa(details.Kind) }</span>
			if details.KindNIP != "" {
				<a
					href={ templ.URL("https://github.com/nostr-protocol/nips/blob/master/" + details.KindNIP + ".md") }
					class="underline decoration-neutral-200 dark:decoration-neutral-500 decoration-1 underline-offset-[6px] text-neutral-500 dark:text-neutral-300 text-[16px]"
				>{ details.KindDescription }</a>
			}
		</div>
		if details.Nevent != "" {
			<div class="mb-6 leading-5">
				<div class="text-sm text-strongpink">Address Code</div>
				<span class="text-[16px] text-neutral-500 dark:text-neutral-300">{ details.Nevent }</span>
			</div>
		}
		<div class="-mx-4 my-8 bg-neutral-100 px-4 pb-4 leading-5 dark:bg-neutral-700">
			<div
				class="-mx-4 bg-neutral-300 px-4 py-1 text-neutral-100 dark:bg-neutral-800 dark:text-neutral-400"
			>
				Event JSON
			</div>
			<div class="mt-4 whitespace-pre-wrap break-all font-mono text-sm">
				@templ.Raw(details.EventJSON)
			</div>
		</div>
		if details.Nprofile != "" {
			<div class="mb-6 break-all leading-5">
				<div class="text-sm text-strongpink">Author Profile Code</div>
				<span class="text-neutral-500 dark:text-neutral-300 text-[16px]">{ details.Nprofile }</span>
			</div>
		}
	</div>
}
