{{ $params := . }}

{{ $item := $params.item }}
{{ $list := $params.list }}

{{ $authors := partial "paige/func-authors.html" $item | and ($list.Param "paige.subpages.disable_authors" | not) }}
{{ $categories := $item.GetTerms "categories" }}
{{ $date := $item.PublishDate | and ($list.Param "paige.subpages.disable_date" | not) }}
{{ $description := $item.Description | markdownify | plainify | htmlUnescape | and ($list.Param "paige.subpages.disable_description" | not) }}
{{ $draft := $item.Draft }}
{{ $expired := and $item.ExpiryDate (lt $item.ExpiryDate now) }}
{{ $flags := slice }}
{{ $format := $list.Param "paige.site.date_format" | default ":date_long" }}
{{ $future := and $item.PublishDate (gt $item.PublishDate now) }}
{{ $link := $item.RelPermalink }}
{{ $modified := and $item.PublishDate $item.Lastmod (lt $item.PublishDate $item.Lastmod) }}
{{ $normal := eq ($list.Param "paige.site.keyword_style" | default "text") "text" }}
{{ $series := $item.GetTerms "series" | and ($list.Param "paige.subpages.disable_series" | not) }}
{{ $summary := $item.Summary | markdownify | plainify | htmlUnescape | and ($list.Param "paige.subpages.disable_summary" | not) }}
{{ $tags := $item.GetTerms "tags" }}
{{ $time := $item.ReadingTime | and ($list.Param "paige.subpages.disable_reading_time" | not) }}
{{ $title := $item.LinkTitle | markdownify | plainify | htmlUnescape | and ($list.Param "paige.subpages.disable_title" | not) }}
{{ $words := $item.WordCount | and ($list.Param "paige.subpages.disable_word_count" | not) }}

{{ if $draft }}
    {{ $flags = $flags | append "paige-status-draft" "paige-status-unpublished" }}
{{ end }}

{{ if $expired }}
    {{ $flags = $flags | append "paige-status-expired" "paige-status-unpublished" }}
{{ end }}

{{ if $future }}
    {{ $flags = $flags | append "paige-status-future" "paige-status-unpublished" }}
{{ end }}

{{ if $modified }}
    {{ $flags = $flags | append "paige-status-modified" }}
{{ end }}

{{ if not (or $draft $expired $future) }}
    {{ $flags = $flags | append "paige-status-published" }}
{{ end }}

{{ $class := delimit (slice "paige-page" "w-100" | append $flags | uniq | sort) " " }}
{{ $keywords := sort (append $categories $tags) "LinkTitle" | and ($list.Param "paige.subpages.disable_keywords" | not) }}

<div class="{{ $class }}">
    {{ with $title }}
        <p class="paige-row-short paige-page-title text-center"><a href="{{ $link }}">{{ . }}</a></p>
    {{ end }}

    {{ with $description }}
        <p class="paige-page-description paige-row-short text-center">{{ . }}</p>
    {{ end }}

    {{ with $summary }}
        <p class="fst-italic paige-row-short paige-page-summary text-center">{{ . }}</p>
    {{ end }}

    {{ with $keywords }}
        <p class="paige-page-keywords paige-row-short text-center text-secondary">
            {{ range $i, $term := . -}}
                {{- $kind := false -}}

                {{- if in $categories $term -}}
                    {{- $kind = "category" -}}
                {{- else -}}
                    {{- $kind = "tag" -}}
                {{- end -}}

                {{- if $normal -}}
                    {{- if gt $i 0 }} · {{ end -}}

                    <a class="link-secondary paige-page-keyword-{{ $kind }}" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
                {{- else -}}
                    {{- if gt $i 0 }} {{ end -}}

                    <a class="badge paige-page-keyword-{{ $kind }} text-bg-secondary text-decoration-none" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
                {{- end -}}
            {{- end }}
        </p>
    {{ end }}

    {{ with $series }}
        <p class="paige-row-short paige-page-series text-center text-secondary">
            {{ range $i, $series := . -}}
                {{- if gt $i 0 }} · {{ end -}}

                <a class="link-secondary" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
            {{- end }}
        </p>
    {{ end }}

    {{ with $authors }}
        <p class="paige-page-authors text-center paige-row-short text-secondary">
            {{ range $i, $author := . -}}
                {{- if gt $i 0 }} · {{ end -}}

                <a class="link-secondary" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
            {{- end }}
        </p>
    {{ end }}

    {{ with $date }}
        <p class="paige-page-date text-center paige-row-short text-secondary">
            <time datetime="{{ .Format `2006-01-02` }}">{{ time.Format $format . }}</time>
        </p>
    {{ end }}

    {{ with $words }}
        <p class="paige-page-word-count paige-row-short text-center text-secondary">{{ . }} {{ i18n "paige_words" . }}</p>
    {{ end }}

    {{ with $time }}
        <p class="paige-page-reading-time paige-row-short text-center text-secondary">{{ . }} {{ i18n "paige_minutes" . }}</p>
    {{ end }}
</div>
