{%- macro _person_name_label(person_name) -%}
    {% include 'entity/label--person-name.html.j2' %}
{%- endmacro -%}
{%- macro _embedded_person_name_label(person_name) -%}
    {% set embedded = True %}
    {% include 'entity/label--person-name.html.j2' %}
{%- endmacro -%}

{% set person = person | default(entity) %}
{%- if not embedded is defined -%}
    {%- set embedded = False -%}
{%- endif -%}
<div class="meta person-meta">
    {%- if person.private -%}
        <p>{%- trans -%}This person's details are unavailable to protect their privacy.{%- endtrans -%}</p>
    {%- else -%}
        {% set alternative_names = (person.names | select('public') | list)[1:] %}
        {%- if alternative_names -%}
            <span class="aka">{%- trans names=alternative_names | map(_embedded_person_name_label if embedded else _person_name_label) | list | join(', ') -%}Also known as {{ names }}{%- endtrans -%}</span>
        {%- endif -%}
        {% set events = person.presences | selectattr('role', 'subject_role') | map(attribute='event') | reject('none') | select('public') | list %}
        {% set start_of_life_events = events | select('start_of_life_event') | list %}
        {%- if start_of_life_events | length -%}
            {% set start_of_life_event = start_of_life_events | first %}
            {%- set formatted_start -%}
                {%- with event=start_of_life_event -%}
                    {%- include 'event-dimensions.html.j2' -%}
                {%- endwith -%}
            {%- endset -%}
        {%- endif -%}
        {% set end_of_life_events = events | select('end_of_life_event') | list %}
        {%- if end_of_life_events | length -%}
            {% set end_of_life_event = end_of_life_events | first %}
            {%- set formatted_end -%}
                {%- with event=end_of_life_event -%}
                    {%- include 'event-dimensions.html.j2' -%}
                {%- endwith -%}
            {%- endset -%}
        {%- endif -%}
        {%- if formatted_start is defined or formatted_end is defined -%}
            <dl>
                {%- if formatted_start is defined -%}
                    <div><dt>{{ start_of_life_event.event_type.label() | localize }}</dt><dd>{{ formatted_start }}</dd></div>
                {%- endif -%}
                {%- if formatted_end is defined -%}
                    <div><dt>{{ end_of_life_event.event_type.label() | localize }}</dt><dd>{{ formatted_end }}</dd></div>
                {%- endif -%}
            </dl>
        {%- endif -%}
    {%- endif -%}
</div>
