{namespace vh=Newland\NeosViewHelpers\ViewHelpers}
{namespace components=Newland\NeosCommon\ViewHelpers}
{namespace common=Newland\Toubiz\Common\Neos\ViewHelpers}
{namespace event=Newland\Toubiz\Events\Neos\ViewHelpers}

<common:slot.render slot="SearchResult" context="{ events: events }" />

<li class="tb-search-result-list__item tb-search-result-list__item--{result.scope} {additionalClass.wrapper}">
    <a
        href="{url}"
        class="tb-search-result-list__link {additionalClass.link}"
        itemscope="itemscope"
        itemtype="{schemaOrg.itemType}"
        itemid="urn:uuid:{result.identifier}"
    >

        <article>
            <header>
                <p class="tb-teaser__topline">
                    <span
                        class="tb-teaser__dates"
                        itemprop="startDate"
                        content="{event.beginsAt -> f:format.date(format: 'Y-m-d')}">

                        <events:format.timeRange
                            event="{event}"
                            dateFormat="{f:if(
                                condition: '{event.language} === \'de\'',
                                then: 'E, dd. MMMM yyyy',
                                else: 'E, dd MMMM yyyy'
                            )}"
                            timeFormat="HH:mm"
                            dateTimeFormat="{f:if(
                                condition: '{event.language} === \'de\'',
                                then: 'E, dd. MMMM yyyy, HH:mm',
                                else: 'E, dd MMMM yyyy, HH:mm'
                            )}"
                        />

                        <f:if condition="{event.eventDates -> f:count()} == 1 && {event.beginsAt}">
                            {f:translate(id: 'views._shared.word.clock', package: 'Newland.Toubiz.Events.Neos')}
                        </f:if>
                    </span>

                    <f:if condition="{event.beginsAt}
                        && ({event.eventDates -> f:count()} > 1)
                        && {event.beginsAtSpecificTime}"
                    >
                        •
                        <span class="tb-teaser__time {f:if(condition: event.cancelled, then: 'line-through', else: '')}">
                            {event.beginsAt -> f:format.date(format: 'H:i')}
                            {f:translate(id: 'views._shared.word.clock', package: 'Newland.Toubiz.Events.Neos')}

                            <f:if condition="{event.endsAt}">
                                -
                                {event.endsAt -> f:format.date(format: 'H:i')}
                                {f:translate(id: 'views._shared.word.clock', package: 'Newland.Toubiz.Events.Neos')}
                            </f:if>
                        </span>
                    </f:if>
                </p>
                <h3 class="tb-search-result-list__title {additionalClass.title} tb-teaser__title">
                    {title -> f:format.htmlentitiesDecode()}
                </h3>
            </header>

            <f:if condition="{event.additionalInformation} || {event.description}">
                <div class="tb-search-result-list__content {additionalClass.content}">
                    <p>
                        <f:if condition="{event.additionalInformation}">
                            <f:then>
                                <vh:format.crop
                                    maxCharacters="250"
                                    append="..."
                                    input="{event.additionalInformation -> f:format.htmlentitiesDecode()}"
                                    respectWordBoundaries="true"
                                />
                            </f:then>
                            <f:else>
                                <vh:format.crop
                                    maxCharacters="250"
                                    append="..."
                                    input="{event.description -> f:format.htmlentitiesDecode()}"
                                    respectWordBoundaries="true"
                                />
                            </f:else>
                        </f:if>
                    </p>

                    <f:if condition="{image}">
                        <div class="tb-search-result-list__image-wrapper {additionalClass.imageWrapper}">
                            <img data-src="{image.sourceUri}" alt="{image.title}" class="lazyload {additionalClass.image}" />
                        </div>
                    </f:if>
                </div>
            </f:if>
        </article>
    </a>
</li>

<components:pagination
    currentPage="{pagination.page}"
    totalPageCount="{pagination.count.pages}"
/>
