{{- $piece := . -}}
{{- $fortsPrefix := "" -}}
{{- if $piece.IsContinuation -}}
	{{- $fortsPrefix = "<span class=\"italic text-gray-600\">(Forts.) </span>" -}}
{{- end -}}


<div class="entry-description leading-snug mb-1">
	{{- $categoryFlags := GetCategoryFlags $piece.Piece -}}

	{{- $place := "" -}}
	{{- if $piece.PlaceRefs -}}
		{{- $placeObj := GetPlace (index $piece.PlaceRefs 0).Ref -}}
		{{- if gt (len $placeObj.Names) 0 -}}
			{{- $place = index $placeObj.Names 0 -}}
		{{- end -}}
	{{- end -}}

	{{- $title := "" -}}
	{{- if $piece.Title -}}
		{{- $title = index $piece.Title 0 -}}
	{{- else if $piece.Incipit -}}
		{{- $title = index $piece.Incipit 0 -}}
	{{- end -}}

	{{- $workTitle := "" -}}
	{{- $workTitleFull := "" -}}
	{{- $workAuthorName := "" -}}
	{{- $workAuthorID := "" -}}
	{{- if $piece.WorkRefs -}}
		{{- $work := GetWork (index $piece.WorkRefs 0).Ref -}}
		{{- /* Determine short title (PreferredTitle) and full title (Citation.Title) */ -}}
		{{- if $work.PreferredTitle -}}
			{{- $workTitle = $work.PreferredTitle -}}
		{{- else if $work.Citation.Title -}}
			{{- $workTitle = $work.Citation.Title -}}
		{{- else if $work.Citation.Chardata -}}
			{{- $workTitle = $work.Citation.Chardata -}}
		{{- end -}}
		{{- /* Always get full title for highlighted state */ -}}
		{{- if $work.Citation.Title -}}
			{{- $workTitleFull = $work.Citation.Title -}}
		{{- else if $work.Citation.Chardata -}}
			{{- $workTitleFull = $work.Citation.Chardata -}}
		{{- else if $work.PreferredTitle -}}
			{{- $workTitleFull = $work.PreferredTitle -}}
		{{- end -}}
		{{- /* Get work author */ -}}
		{{- if $work.AgentRefs -}}
			{{- range $workAgentRef := $work.AgentRefs -}}
				{{- if (or (eq $workAgentRef.Category "") (eq $workAgentRef.Category "autor")) -}}
					{{- $workAgent := GetAgent $workAgentRef.Ref -}}
					{{- if and $workAgent (gt (len $workAgent.Names) 0) -}}
						{{- $workAuthorName = index $workAgent.Names 0 -}}
						{{- $workAuthorID = $workAgentRef.Ref -}}
						{{- break -}}
					{{- end -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
	{{- end -}}

	{{- /* Generate natural text descriptions */ -}}

	{{- if $categoryFlags.Rezension -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600"
						>{{ index $agent.Names 0 }}</a
					>,
					<span class="review-format"
						>Rezension von:
						{{ if $workAuthorName }}
							{{- if $workAuthorID -}}
								<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>
							{{- else -}}
								{{ $workAuthorName }}
							{{- end -}},
						{{ end }}
						{{ if $workTitle }}
							<em
								class="work-title"
								data-short-title="{{ $workTitle }}"
								{{ if $workTitleFull }}data-full-title="{{ $workTitleFull }}"{{ end }}
								>{{ $workTitle }}</em
							>
						{{ else if $title }}
							<em>{{ $title }}</em>
						{{ else }}
							[Werk unbekannt]
						{{ end }}</span
					>{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}<span class="review-format"
				>Rezension von:
				{{ if $workAuthorName }}
					{{- if $workAuthorID -}}
						<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>
					{{- else -}}
						{{ $workAuthorName }}
					{{- end -}},
				{{ end }}
				{{ if $workTitle }}
					<em
						class="work-title"
						data-short-title="{{ $workTitle }}"
						{{ if $workTitleFull }}data-full-title="{{ $workTitleFull }}"{{ end }}
						>{{ $workTitle }}</em
					>
				{{ else if $title }}
					<em>{{ $title }}</em>
				{{ else }}
					[Werk unbekannt]
				{{ end }}</span
			>{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}
		{{- end -}}

	{{- else if $categoryFlags.Weltnachrichten -}}
		{{ Safe $fortsPrefix }}Politische Nachrichten aus aller Welt
	{{- else if $categoryFlags.EinkommendeFremde -}}
		{{- if $categoryFlags.Lokalnachrichten -}}
			Lokale Meldungen über einreisende Fremde
		{{- else if $categoryFlags.Nachruf -}}
			Nachruf und Einreiseliste
		{{- else -}}
			Einreiseliste
		{{- end -}}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Wechselkurse -}}
		Wechselkurse{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Buecher -}}
		Bücheranzeigen{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Lokalanzeigen -}}
		{{ if $categoryFlags.Nachruf }}
			Todesanzeige
		{{ else }}
			Lokalanzeige
		{{ end }}{{ if $title }}: <em>{{ $title }}</em>{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Lokalnachrichten -}}
		{{ if $categoryFlags.Lotterie }}
			Lotterienachrichten
		{{ else if $categoryFlags.Nachruf }}
			Nachrufe
		{{ else if $categoryFlags.Theaterkritik }}
			Theaternachrichten
		{{ else if $categoryFlags.Panegyrik }}
			Festlichkeiten
		{{ else }}
			Lokalnachrichten
		{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Gedicht -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ index $agent.Names 0 }}</a>,
					{{ if $categoryFlags.Kommentar }}
						Gedicht mit Kommentar
					{{ else if $categoryFlags.Uebersetzung }}
						Gedichtübersetzung
					{{ else if $categoryFlags.GelehrteNachrichten }}
						Gedicht zu gelehrten Angelegenheiten
					{{ else }}
						Gedicht
					{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}{{ if $categoryFlags.Kommentar }}
				Gedicht mit Kommentar
			{{ else if $categoryFlags.Uebersetzung }}
				Gedichtübersetzung
			{{ else if $categoryFlags.GelehrteNachrichten }}
				Gedicht zu gelehrten Angelegenheiten
			{{ else }}
				Gedicht
			{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
		{{- end -}}

	{{- else if $categoryFlags.Vorladung -}}
		Gerichtliche Vorladung{{ if $title }}: <em>{{ $title }}</em>{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Aufsatz -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600"
						>{{ index $agent.Names 0 }}</a
					>,
					{{ if $categoryFlags.Replik }}
						Erwiderung
					{{ else if $categoryFlags.Uebersetzung }}
						Übersetzung
					{{ else if $categoryFlags.Nachruf }}
						Nachruf
					{{ else if $categoryFlags.Kommentar }}
						Kommentar
					{{ else if $categoryFlags.Rezepte }}
						Rezepte und Anleitungen
					{{ else }}
						Aufsatz
					{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}{{ if $categoryFlags.Replik }}
				Erwiderung
			{{ else if $categoryFlags.Uebersetzung }}
				Übersetzung
			{{ else if $categoryFlags.Nachruf }}
				Nachruf
			{{ else if $categoryFlags.Kommentar }}
				Kommentar
			{{ else if $categoryFlags.Rezepte }}
				Rezepte und Anleitungen
			{{ else }}
				Aufsatz
			{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
		{{- end -}}

	{{- else if $categoryFlags.GelehrteNachrichten -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Theaterkritik }}
			Theaterkritik
		{{ else if $categoryFlags.Kommentar }}
			Gelehrter Kommentar
		{{ else }}
			Gelehrte Nachrichten
		{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Theaterkritik -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600"
						>{{ index $agent.Names 0 }}</a
					>,
					Theaterkritik{{ if $workTitle }}
						zu <em>{{ $workTitle }}</em>{{ if $workAuthorName }}
							von
							<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>
						{{ end }}
					{{ else if $title }}
						zu <em>{{ $title }}</em>
					{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}Theaterkritik{{ if $workTitle }}
				zu <em>{{ $workTitle }}</em>{{ if $workAuthorName }}
					von <a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>
				{{ end }}
			{{ else if $title }}
				zu <em>{{ $title }}</em>
			{{ end }}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}
		{{- end -}}

	{{- else if $categoryFlags.Proklamation -}}
		{{ Safe $fortsPrefix }}Amtliche
		Proklamation{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Ineigenersache -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Kommentar }}
			{{ if $categoryFlags.Nachtrag }}Ergänzender Kommentar{{ else }}Redaktioneller Kommentar{{ end }}
		{{ else if $categoryFlags.Replik }}
			Redaktionelle Stellungnahme
		{{ else }}
			Anmerkung der Redaktion
		{{ end }}
		{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Brief -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Nachruf }}
			Kondolenzbrief
		{{ else }}
			Leserbrief
		{{ end }}
		{{- $authorFound := false -}}{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}{{- if and $agent (gt (len $agent.Names) 0) -}}
					von
					<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ index $agent.Names 0 }}</a
					>{{- $authorFound = true -}}{{- break -}}
				{{- end -}}

			{{- end -}}

		{{- end -}}{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Desertionsliste -}}
		{{ Safe $fortsPrefix }}Desertionsliste{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Notenblatt -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Nachtrag }}Ergänztes{{ end }}Notenblatt{{ if $title }}
			: <em>{{ $title }}</em>
		{{ end }}

	{{- else if $categoryFlags.Vorlesungsverzeichnis -}}
		{{ Safe $fortsPrefix }}Vorlesungsverzeichnis{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Erzaehlung -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600"
						>{{ index $agent.Names 0 }}</a
					>,
					{{ if $categoryFlags.Uebersetzung }}
						Übersetzung einer Erzählung
					{{ else }}
						Erzählung
					{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}{{ if $categoryFlags.Uebersetzung }}
				Übersetzung einer Erzählung
			{{ else }}
				Erzählung
			{{ end }}{{ if $title }}: <em>„{{ $title }}"</em>{{ end }}
		{{- end -}}

	{{- else if $categoryFlags.Abbildung -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Aufsatz }}
			Illustrierter Aufsatz
		{{ else }}
			Abbildung
		{{ end }}
		{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Kriminalanzeige -}}
		{{ Safe $fortsPrefix }}Kriminalanzeige{{ if $place }} <span class="place-tag inline-block bg-slate-200 text-slate-700 text-xs px-2 py-0.5 rounded-md whitespace-nowrap">{{ $place }}</span>{{ end }}

	{{- else if $categoryFlags.Korrektur -}}
		{{ Safe $fortsPrefix }}Korrektur{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Anzeige -}}
		{{ Safe $fortsPrefix }}{{ if $categoryFlags.Auszug }}
			{{ if $categoryFlags.Gedicht }}Gedichtauszug{{ else }}Textauszug{{ end }}
		{{ else }}
			Anzeige
		{{ end }}
		{{ if $title }}: <em>{{ $title }}</em>{{ end }}

	{{- else if $categoryFlags.Auszug -}}
		{{ Safe $fortsPrefix }}{{ if $title }}<em>{{ $title }}</em>, {{ end }}{{ if $categoryFlags.Uebersetzung }}Übersetzung aus:{{ else }}Auszug aus:{{ end }} {{ if $workAuthorName }}
			<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>, {{ end }}{{ if $workTitle }}<em
				class="work-title"
				data-short-title="{{ $workTitle }}"
				{{ if $workTitleFull }}data-full-title="{{ $workTitleFull }}"{{ end }}
				>{{ $workTitle }}</em>{{ else if $title }}<em>{{ $title }}</em>{{ else }}[Werk unbekannt]{{ end }}

	{{- else -}}
		{{- $authorFound := false -}}
		{{- range $agentref := $piece.AgentRefs -}}
			{{- if (or (eq $agentref.Category "") (eq $agentref.Category "autor")) -}}
				{{- $agent := GetAgent $agentref.Ref -}}
				{{- if and $agent (gt (len $agent.Names) 0) -}}
					{{ Safe $fortsPrefix }}<a href="/akteure/{{ $agentref.Ref }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600"
						>{{ index $agent.Names 0 }}</a
					>{{ if $title }}: <em>{{ $title }}</em>{{ end }}{{ if $workTitle }}
						{{ if $title }}, {{ if $categoryFlags.Uebersetzung }}Übersetzung aus:{{ else }}Auszug aus:{{ end }} {{ end }}{{ if $workAuthorName }}
							<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>, {{ end }}<em
							class="work-title"
							data-short-title="{{ $workTitle }}"
							{{ if $workTitleFull }}data-full-title="{{ $workTitleFull }}"{{ end }}
							>{{ $workTitle }}</em>
					{{ end }}
					{{- $authorFound = true -}}
					{{- break -}}
				{{- end -}}
			{{- end -}}
		{{- end -}}
		{{- if not $authorFound -}}
			{{ Safe $fortsPrefix }}{{ if $title }}<em>{{ $title }}</em>{{ end }}{{ if $workTitle }}
				{{ if $title }}, {{ if $categoryFlags.Uebersetzung }}Übersetzung aus:{{ else }}Auszug aus:{{ end }} {{ end }}{{ if $workAuthorName }}
					<a href="/akteure/{{ $workAuthorID }}" class="author-link text-slate-700 hover:text-slate-900 underline decoration-slate-400 hover:decoration-slate-600">{{ $workAuthorName }}</a>, {{ end }}<em
					class="work-title"
					data-short-title="{{ $workTitle }}"
					{{ if $workTitleFull }}data-full-title="{{ $workTitleFull }}"{{ end }}
					>{{ $workTitle }}</em>
			{{ else if not $title }}
				Beitrag ohne Titel
			{{ end }}
		{{- end -}}

	{{- end -}}
</div>

{{- if not $piece.IsContinuation -}}
	{{- range $annotation := $piece.AnnotationNote.Annotations -}}
		<div class="italic text-sm mt-0.5 text-slate-600">
			{{ Safe $annotation.HTML }}
		</div>
	{{- end -}}
{{- end -}}
