
{{ $tag_color := .Site.Params.categories_colors }}

{{ if eq .card_type "upcoming" }}
    {{ with .context }}

        <div class="postcard">
        {{ if ne (.Params.eventStartDate) (.Params.eventEndDate) }}

            <div class="eventdate">
            {{ dateFormat "2 Jan, 2006" .Params.eventStartDate }}-{{ dateFormat "2 Jan, 2006" .Params.eventEndDate }}
            {{ if .Params.tags }}
                {{ $numtags := len .Params.tags }}
                {{ $first_tag := index .Params.tags 0 }}

                {{ if gt $numtags 0 }} {{ if ne $first_tag "" }} {{/* --if-- insert tag box */}}
                    <div class="tags">
                    {{ range .Params.tags }}
                        {{ $param_tag_name := . }}
                        {{ if in $tag_color $param_tag_name }} {{/* if tag_name is defined in categories_color */}}
                            {{ range $i, $tag_name := $tag_color }}
                                {{ if eq $tag_name $param_tag_name }} 
                                    <a href="{{ $.Site.BaseURL | absLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton {{ index $tag_color (add $i 1) }}">{{ $param_tag_name }}</a>
                                {{ end }}
                            {{ end }}
                        {{ else }}
                            <a href="{{ $.Site.BaseURL | absLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton">{{ $param_tag_name }}</a>
                        {{ end }}
                    {{ end }}
                    </div>
                {{ end }} {{ end }} {{/* --end-- insert tag box */}}

            {{ end }}
            </div>

        {{ else }} {{/* if eventStartDate == eventEndDate  */}}

            <div class="eventdate">
            {{ dateFormat "2 Jan, 2006" .Params.eventEndDate }}
            {{ if .Params.tags }}
                {{ $numtags := len .Params.tags }}
                {{ $first_tag := index .Params.tags 0 }}
                {{ if gt $numtags 0 }} {{ if ne $first_tag "" }}

                    <div class="tags"> {{/* --if-- insert tag box */}}
                    {{ range .Params.tags }}
                        {{ $param_tag_name := . }}
                        {{ if in $tag_color $param_tag_name }} {{/* if tag_name is defined in categories_color */}}
                            {{ range $i, $tag_name := $tag_color }}
                                {{ if eq $tag_name $param_tag_name }} 
                                    <a href="{{ $.Site.BaseURL | relLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton {{ index $tag_color (add $i 1) }}">{{ $param_tag_name }}</a>
                                {{ end }}
                            {{ end }}
                        {{ else }}
                            <a href="{{ $.Site.BaseURL | relLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton">{{ $param_tag_name }}</a>
                        {{ end }}
                    {{ end }} {{/* --end-- insert tag box */}}
                    </div>

                {{ end }} {{ end }}
            {{ end }}
            </div>

        {{ end }}

        <h2 class="post-title">{{ .Title }}</h2>
        <p>{{ .Content }}</p>
        <p><a href="{{ .Permalink }}" class="read-more">Read more</a></p>

        </div>

    {{ end }} {{/* --end-- with */}}

{{ else if eq .card_type "normal" }}
    {{ with .context }}
        <div class="postcard">
        <div class="eventdate">
        {{ dateFormat "2 Jan, 2006" .Date }}
        {{ if .Params.tags }}
            {{ $numtags := len .Params.tags }}
            {{ $first_tag := index .Params.tags 0 }}

            {{ if gt $numtags 0 }} {{ if ne $first_tag "" }}
                <div class="tags">
                {{ range .Params.tags }}
                    {{ $param_tag_name := . }}
                    {{ if in $tag_color $param_tag_name }} {{/* if tag_name is defined in categories_color */}}
                        {{ range $i, $tag_name := $tag_color }}
                            {{ if eq $tag_name $param_tag_name }} 
                                <a href="{{ $.Site.BaseURL | relLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton {{ index $tag_color (add $i 1) }}">{{ $param_tag_name }}</a>
                            {{ end }}
                        {{ end }}
                    {{ else }}
                        <a href="{{ $.Site.BaseURL | relLangURL }}tags/{{ lower $param_tag_name }}/" class="tagbutton">{{ $param_tag_name }}</a>
                    {{ end }}
                {{ end }}
                </div>

            {{ end }} {{ end }}
        {{ end }}
        </div>
        <h2 class="post-title">{{ .Title }}</h2>
        <p>{{ .Content }}</p>
        <p><a href="{{ .Permalink }}" class="read-more">Read more</a></p>
        </div>
    {{ end }}

{{ else if eq .card_type "simple" }}
    {{ with .context }}
        <div class="postcard">
        <div class="eventdate">
        {{ dateFormat "2 Jan, 2006" .Date }}
        </div>
        <h2 class="post-title">{{ .Title }}</h2>
        <p>{{ .Content }}</p>
        <p><a href="{{ .Permalink }}" class="read-more">Read more</a></p>
        </div>
    {{ end }}
{{ end }}
