package main

import "github.com/nbd-wtf/go-nostr"

templ reportsPage(reports chan *nostr.Event, loggedUser string) {
	@layout(loggedUser) {
		<div>
			<h1 class="text-xl p-4">reports received</h1>
			<div>
				for report := range reports {
					<div>
						if e := report.Tags.GetFirst([]string{"e", ""}); e != nil {
							@eventReportComponent(e, report)
						} else if p := report.Tags.GetFirst([]string{"p", ""}); p != nil {
							@profileReportComponent(p, report)
						}
					</div>
				}
			</div>
		</div>
	}
}

templ eventReportComponent(e *nostr.Tag, report *nostr.Event) {
	if res, _ := sys.StoreRelay.QuerySync(ctx, nostr.Filter{IDs: []string{(*e)[1]}}); len(res) > 0 {
		<div>
			<div class="font-lg">
				<span class="font-semibold">
					if len(*e) >= 3 {
						{ (*e)[2] }
					}
				</span>
				{ " report" }
			</div>
			<div>by @userNameComponent(sys.FetchProfileMetadata(ctx, report.PubKey))</div>
			<div class="p-3">{ report.Content }</div>
			<div>
				event reported:
				<div class="text-mono">{ res[0].String() }</div>
			</div>
		</div>
	}
}

templ profileReportComponent(p *nostr.Tag, report *nostr.Event) {
	if isPublicKeyInWhitelist((*p)[1]) {
		<div>
			<div class="font-lg">
				<span class="font-semibold">
					if len(*p) >= 3 {
						{ (*p)[2] }
					}
				</span>
				{ " report" }
			</div>
			<div>by @userNameComponent(sys.FetchProfileMetadata(ctx, report.PubKey))</div>
			<div class="p-3">{ report.Content }</div>
			<div>
				profile reported:
				@userNameComponent(sys.FetchProfileMetadata(ctx, (*p)[1]))
			</div>
		</div>
	}
}
