{%- set parents = person.parents | list -%}
{%- set siblings = person.siblings | list -%}
{%- set children = person.children | list -%}

{%- set has_family =  parents | length > 0 or siblings | length > 0 or children | length > 0 -%}

{%- if has_family -%}
    <div class="container">
        {% set family_section_count = 0 %}
        {% if parents | length > 0 or siblings | length > 0 %}
            {% set family_section_count = family_section_count + 1 %}
            <div class="mt-2 row row-cols-1 row-cols-lg-2 row-cols-xxl-3 row-gap-3">
                <div class="col d-flex flex-column justify-content-center">
                    <p>
                        {% if parents | length  %}
                            {% set ns = namespace(parents_labels=[]) %}
                            {% for parent in parents %}
                                {% set parent_label %}
                                    {%- with entity = parent -%}
                                        {%- include 'entity/label--person.html.j2' -%}
                                    {%- endwith -%}
                                {% endset %}
                                {% do ns.parents_labels.append(parent_label) %}
                            {% endfor %}
                            {% trans parent_labels = ns.parents_labels | join(', ') %}They are the child of {{ parent_labels }}.{% endtrans %}
                        {% endif %}

                        {% if siblings | length > 0 %}
                            {%- trans sibling_count = siblings | length -%}
                                They grew up with a sibling.
                            {%- pluralize -%}
                                They grew up with {{ sibling_count }} siblings.
                            {%- endtrans -%}
                        {% endif %}
                    </p>
                </div>
                {% set public_siblings = siblings | select('public') | list %}
                {% for public_sibling in public_siblings %}
                    <div class="col">
                        <div class="card">
                            <div class="card-body">
                                {%- with entity = public_sibling -%}
                                    {%- include 'entity/label--person.html.j2' -%}
                                    {%- include 'entity/summary--person.html.j2' -%}
                                {%- endwith -%}
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% endif %}

        {% if children | length > 0 %}
            {% for family_parents, family_children in person_descendant_families %}
                {% set family_section_count = family_section_count + 1 %}
                {% if family_section_count > 1 %}
                    <hr>
                {% endif %}
                <div class="mt-2 row row-cols-1 row-cols-lg-2 row-cols-xxl-3 row-gap-3{% if loop.index0 % 2 == 0 %} flex-row-reverse{% endif %}">
                    {% set family_parents = family_parents | reject('eq', person) | list %}
                    <div class="col d-flex flex-column justify-content-center">
                        <p>
                            {%- if family_parents | length > 0 -%}
                                {% set ns = namespace(family_parent_labels=[]) %}
                                {% for family_parent in family_parents %}
                                    {% set family_parent_label %}
                                        {%- with entity = family_parent -%}
                                            {%- include 'entity/label--person.html.j2' -%}
                                        {%- endwith -%}
                                    {% endset %}
                                    {% do ns.family_parent_labels.append(family_parent_label) %}
                                {% endfor %}
                                {%- trans child_count = family_children | length, co_parent_labels = ns.family_parent_labels | join(', ') -%}
                                    They had a child with {{ co_parent_labels }}.
                                {%- pluralize -%}
                                    They had {{ child_count }} children with {{ co_parent_labels }}.
                                {%- endtrans -%}
                            {%- else -%}
                                {%- trans child_count = family_children | length -%}
                                    They had a child.
                                {%- pluralize -%}
                                    They had {{ child_count }} children.
                                {%- endtrans -%}
                            {%- endif -%}
                        </p>
                    </div>
                    {% set public_family_children = family_children | select('public') | list %}
                    {% for public_family_child in public_family_children %}
                        <div class="col">
                            <div class="card">
                                <div class="card-body">
                                    {%- with entity = public_family_child, document=document.copy(entity_contexts=document.entity_contexts(person)) -%}
                                        {%- include 'entity/label--person.html.j2' -%}
                                        {%- include 'entity/summary--person.html.j2' -%}
                                    {%- endwith -%}
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            {% endfor %}
        {% endif %}
    </div>
{%- endif -%}
