{% include 'content_block_header.j2' %}

{% if "styling" in content_block and "body" in content_block["styling"] -%}
    {% set content_block_body_styling = content_block["styling"]["body"] | render_styling -%}
{% else -%}
    {% set content_block_body_styling = "" -%}
{% endif -%}

<table id="{{content_block_id}}-body" {{ content_block_body_styling | replace("{{section_id}}", section_id) | replace("{{content_block_id}}", content_block_id) }}>
    {% if content_block.get("header_row") %}
        <tr>
            {% for header_cell in content_block.get("header_row") %}
                <th>{{ header_cell | render_content_block }}</th>
            {% endfor %}
        </tr>
    {% endif %}

    {% for row in content_block["table"] -%}
        <tr>
        {% set rowloop = loop -%}
        {% for cell in row -%}
            {% if cell is mapping and "styling" in cell -%}
                {% set cell_styling = cell["styling"].get("parent", {}) | render_styling | replace("{{section_id}}", section_id) | replace("{{content_block_id}}", content_block_id) -%}
            {% else -%}
                {% set cell_styling = "" -%}
            {% endif -%}
            <td id="{{content_block_id}}-cell-{{ rowloop.index }}-{{ loop.index }}" {{ cell_styling }}>{{ cell | render_content_block }}</td>
        {%- endfor -%}
        </tr>
    {%- endfor -%}
</table>