{# Citation formatting is inspired by the MLA style guide(https://style.mla.org/) #}
{% set citation = citation | default(entity) %}
{% set citation_context = entity_contexts['Citation'] %}
<span>
    {% if citation.source and citation.source.public -%}
        {%- if citation.source.author -%}
            <span class="citation-author">{{ citation.source.author }}</span>
        {%- endif %}
        <span class="citation-title">{% with source=citation.source %}{% include 'entity/label--source.html.j2' %}{% endwith %}</span>
        {%- if citation.source.publisher -%}
            <span class="citation-publisher">{{ citation.source.publisher }}</span>
        {%- endif -%}
    {% endif %}
    {%- if citation.location -%}
            <span class="citation-location">
                {% if citation_context == citation %}
                    {{ citation.location | localize }}
                    {% else %}
                    {% if citation is not has_generated_entity_id %}
                        <a href="{{ citation | url }}">
                    {% endif %}
                {{ citation.location | localize }}
                {% if citation is not has_generated_entity_id %}
                    </a>
                {% endif %}
                {% endif %}
            </span>
    {%- endif -%}
    {%- if citation.date -%}
        <span class="citation-date">{% trans date = citation.date | format_datey %}Accessed {{ date }}{% endtrans %}</span>
    {%- endif -%}
</span>
