{namespace vh=Newland\NeosViewHelpers\ViewHelpers}
{namespace search=Newland\Toubiz\Search\Neos\ViewHelpers}

<tr>
    <th style="font-family: monospace; text-align: right; border: 1px solid gray;">
        {explanation.value}
    </th>
    <td style="border: 1px solid gray; width: 100%;">
        {explanation.description}
        <vh:render section="Hints" arguments="{_all}" />
    </td>
</tr>
<f:if condition="{explanation.details} && {depth} > 0">
    <tr>
        <td colspan="2" style="border-left: 1px solid #eee">
            <table style="margin-left: 2em;">
                <f:for each="{explanation.details}" as="ex">
                    <vh:render partial="ElasticSearchExplanation"
                               arguments="{ explanation: ex, depth: '{depth - 1}', result: result }"/>
                </f:for>
            </table>
        </td>
    </tr>
</f:if>

<f:section name="Hints">
    <f:if condition="{explanation.description -> search:stringContains(contains: 'idf,')}">
        <a href="https://en.wikipedia.org/wiki/Tf%E2%80%93idf"
           title="importance of word in document
               - increases with more mentions of word in this result
               - decreases with more mentions of word in all results">
            <vh:render section="InfoIcon"/>
        </a>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: 'boost')}">
        <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html"
           title="Boost as configured in query. See configuration in Newland.Toubiz.Search.Neos.elastic.simpleQueryString.fields">
            <vh:render section="InfoIcon" />
        </a>
    </f:if>
    <f:if condition="{explanation.details} && {depth} == 0">
            <span title="Maximum depth reached, but more information available. Increase Newland.Toubiz.Search.Neos.elastic.explanationDepth if you need more detailed information">
                <vh:render section="DepthIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(title')}">
            <span title="{result.rawResult._source.title}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(description')}">
            <span title="{result.rawResult._source.description}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(content')}">
            <span title="{result.rawResult._source.content}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(type')}">
            <span title="{result.rawResult._source.type}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(language')}">
            <span title="{result.rawResult._source.language}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
    <f:if condition="{explanation.description -> search:stringContains(contains: '(scopes')}">
            <span title="{vh:collection.implode(glue: ', ', collection: result.rawResult._source.scopes)}">
                <vh:render section="ContentIcon" />
            </span>
    </f:if>
</f:section>

<f:section name="InfoIcon">
    <svg
        aria-hidden="true"
        focusable="false"
        data-prefix="fas"
        data-icon="info-circle" role="img"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 512 512"
        class="svg-inline--fa fa-info-circle fa-w-16"
        style="height: 1.5em"
    >
        <path
            fill="currentColor"
            d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"
        ></path>
    </svg>
</f:section>

<f:section name="DepthIcon">
    <svg
        aria-hidden="true"
        focusable="false"
        data-prefix="fas"
        data-icon="asterisk"
        role="img"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 512 512"
        class="svg-inline--fa fa-asterisk fa-w-16"
        style="height: 1.5em"
    >
        <path
            fill="currentColor"
            d="M478.21 334.093L336 256l142.21-78.093c11.795-6.477 15.961-21.384 9.232-33.037l-19.48-33.741c-6.728-11.653-21.72-15.499-33.227-8.523L296 186.718l3.475-162.204C299.763 11.061 288.937 0 275.48 0h-38.96c-13.456 0-24.283 11.061-23.994 24.514L216 186.718 77.265 102.607c-11.506-6.976-26.499-3.13-33.227 8.523l-19.48 33.741c-6.728 11.653-2.562 26.56 9.233 33.037L176 256 33.79 334.093c-11.795 6.477-15.961 21.384-9.232 33.037l19.48 33.741c6.728 11.653 21.721 15.499 33.227 8.523L216 325.282l-3.475 162.204C212.237 500.939 223.064 512 236.52 512h38.961c13.456 0 24.283-11.061 23.995-24.514L296 325.282l138.735 84.111c11.506 6.976 26.499 3.13 33.227-8.523l19.48-33.741c6.728-11.653 2.563-26.559-9.232-33.036z"
        ></path>
    </svg>
</f:section>


<f:section name="ContentIcon">
    <svg
        aria-hidden="true"
        focusable="false"
        data-prefix="fas"
        data-icon="asterisk"
        role="img"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 512 512"
        class="svg-inline--fa fa-file fa-w-12"
        style="height: 1.5em"
    >
        <path
            fill="currentColor"
            d="M369.9 97.9L286 14C277 5 264.8-.1 252.1-.1H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V131.9c0-12.7-5.1-25-14.1-34zM332.1 128H256V51.9l76.1 76.1zM48 464V48h160v104c0 13.3 10.7 24 24 24h104v288H48z"
        ></path>
    </svg>
</f:section>
