{namespace vh=Newland\NeosViewHelpers\ViewHelpers}
{namespace poi=Newland\Toubiz\Poi\Neos\ViewHelpers}

<f:comment>
    <!--
        This partial is responsible for rendering article attributes
        in various formats.
    -->
</f:comment>

<vh:render section="{type}Type" arguments="{_all}"/>

<f:comment>
    <!--
        Renders a difficulty label.
    -->
</f:comment>
<f:section name="difficultyType">
    <f:switch expression="{attribute}">
        <f:case value="1">
            <vh:render section="difficultyRating" arguments="{
                name: name,
                attribute: attribute,
                badge: 'easy'
            }"/>
        </f:case>
        <f:case value="2">
            <vh:render section="difficultyRating" arguments="{
                name: name,
                attribute: attribute,
                badge: 'medium'
            }"/>
        </f:case>
        <f:case value="3">
            <vh:render section="difficultyRating" arguments="{
                name: name,
                attribute: attribute,
                badge: 'hard'
            }"/>
        </f:case>
        <f:case value="4">
            <vh:render section="difficultyRating" arguments="{
                name: name,
                attribute: attribute,
                badge: 'hard'
            }"/>
        </f:case>
        <f:case value="5">
            <vh:render section="difficultyRating" arguments="{
                name: name,
                attribute: attribute,
                badge: 'hard'
            }"/>
        </f:case>
    </f:switch>
</f:section>


<f:comment>
    <!--
        Renders horizontal dots.
    -->
</f:comment>
<f:section name="tourRatingType">
    <ul class="tb-tour-rating">
        <li class="tb-tour-rating__item {f:if(condition: '{attribute} >= 1', then: 'tb-tour-rating__item--marked')}">
            •
        </li>
        <li class="tb-tour-rating__item {f:if(condition: '{attribute} >= 2', then: 'tb-tour-rating__item--marked')}">
            •
        </li>
        <li class="tb-tour-rating__item {f:if(condition: '{attribute} >= 3', then: 'tb-tour-rating__item--marked')}">
            •
        </li>
        <li class="tb-tour-rating__item {f:if(condition: '{attribute} >= 4', then: 'tb-tour-rating__item--marked')}">
            •
        </li>
        <li class="tb-tour-rating__item {f:if(condition: '{attribute} >= 5', then: 'tb-tour-rating__item--marked')}">
            •
        </li>
    </ul>
</f:section>


<f:comment>
    <!--
        Renders DTV classification star ratings.
    -->
</f:comment>
<f:section name="starRatingType">
    <f:for each="{starClassifications}" as="classification">
        <f:if condition="{classification.value} > -1">
            <div class="tb-rating">
                <img src="{classification.badgeUrl}" alt="{classification.label}">
            </div>
        </f:if>
    </f:for>
</f:section>

<f:comment>
    <!--
        Renders average user ratings.
    -->
</f:comment>
<f:section name="userRatingType">
    <f:if condition="{averageRating}">
        <f:if condition="{numberOfRatings} > 0">
            <f:then>
                <div class="tb-rating"
                     itemprop="aggregateRating"
                     itemscope
                     itemtype="http://schema.org/AggregateRating">
                    <vh:render section="starRatingContent" arguments="{_all}"/>
                </div>
            </f:then>
            <f:else>
                <div class="tb-rating">
                    <vh:render section="starRatingContent" arguments="{_all}"/>
                </div>
            </f:else>
        </f:if>
    </f:if>
</f:section>

<f:section name="textType">
    {attribute -> f:format.raw()}
</f:section>

<f:section name="listType">
    <ul>
        <f:for each="{attribute}" as="content">
            <li>{content}</li>
        </f:for>
    </ul>
</f:section>

<f:section name="translationArrayType">
    <f:for each="{attribute}" as="item" iteration="iterator">
        <vh:translate id="{path}.{item}" package="Newland.Toubiz.Poi.Neos" source="{source}"/>
        {f:if(condition: iterator.isLast, then: '', else: ', ')}
    </f:for>
</f:section>

<f:section name="distanceType">
    <f:if condition="{subType} == 'meter'">
        {attribute.intValue} m
    </f:if>
    <f:if condition="{subType} == 'kilometer'">
        {attribute -> vh:math.divide(by: 1000) -> vh:math.round(precision: 1)} km
    </f:if>
</f:section>

<f:comment>
    <!--
        Renders a time from minutes.
    -->
</f:comment>
<f:section name="timeType">
    {attribute -> vh:math.toHours()} h
</f:section>

<f:section name="starRatingContent">
    <div class="tb-rating__result">
        <span itemprop="ratingValue">
            <vh:translate
                    id="property.attribute.voteAverage"
                    package="Newland.Toubiz.Poi.Neos"
                    source="Views/Teaser"
                    arguments="{ 0: '{averageRating/20}' }"/>

        </span>
    </div>
    <ul class="tb-rating list-reset" itemprop="ratingValue">
        <f:for each="{poi:ratingAverage(ratingValue: averageRating)}" as="item">
            <li class="tb-rating__item {f:if(condition: item, then: 'tb-rating__item--{item}')}"></li>
        </f:for>
    </ul>
    <f:if condition="{numberOfRatings} > 0">
        <p class="tb-rating__votes">
            (
            <span itemprop="reviewCount">{numberOfRatings}</span>
            <vh:translate
                    id="property.attribute.totalVotes"
                    package="Newland.Toubiz.Poi.Neos"
                    source="Views/Teaser"/>
            )
        </p>
    </f:if>
</f:section>

<f:section name="difficultyRating">
<span itemprop="additionalProperty" itemscope itemtype="http://schema.org/PropertyValue">
    <meta itemprop="name" content="label"/>
    <span class="tb-badge tb-badge--{badge}" itemprop="value">
        <vh:translate
                id="property.attribute.{name}.values.{attribute}"
                package="Newland.Toubiz.Poi.Neos"
                source="Models/Article"/>

    </span>
</span>
</f:section>
