<!DOCTYPE html>
<html>
    <style>
        table.outter_table {
            border: 1px solid black;
            width: 800px;
        }
        table.outter_table td, th {
            border: 1px solid black;
            width: fit-content;
        }
        table.inner_table td {
            border: 0px;
            width: fit-content;
        }
    </style>
    <body>
        <h1>{{ heading1 }}</h1>
        <h2>{{ heading2 }}</h2>
        <table class="outter_table">
            <thead>
                <th>Register</th>
                <th>Width</th>
                <th>Bit</th>
                <th>Bitfield</th>
                <th>Description</th>
            </thead>
            <tbody>
                {% for register in data %}
                <tr>
                    <td rowspan="{{ 1 + register.bitfields|length }}">{{ register.name }}</td>
                    <td>{{ register.width }}</td>
                    <td colspan="3">{{ register.desc }}</td>
                </tr>
                {% for bitfield in register.bitfields %}
                <tr>
                    <td>{{ bitfield.width }}</td>
                    {% if bitfield.width == '1' %}
                    <td>{{ bitfield.offset}}</td>
                    {% else %}
                    <td>{{ (bitfield.offset|int + bitfield.width|int) - 1  }}:{{ bitfield.offset }}</td>
                    {% endif %}
                    <td>{{ bitfield.name }}</td>
                    <td>
                        <table class="inner_table">
                            <tr><td colspan="2">{{ bitfield.desc }}</td></tr>
                            {% for key, val in bitfield.bit_values.items() %}
                            <tr><td style="width: 20px;">{{ key }}</td><td style="white-space: nowrap;">{{ val }}</td></tr>
                            {% endfor %}
                            
                        </table>
                    </td>
                </tr>
                {% endfor %}
                {% endfor %}
            </tbody>
        </table>
    </body>
</html>
