<p class="d-flex gap-4">
    <a href="{{ url("api/download/") }}{{ path }}" class="text-decoration-none"><i class="fa-solid fa-download"></i> Download</a>
    {% if can_delete %}
    <a href="#" class="text-decoration-none link-danger"
        hx-delete="{{ url("htmx/delete/") }}{{path}}" hx-confirm="Do you confirm deletion?"
    >
        <i class="fa-solid fa-trash"></i> Delete
    </a>
    {% endif %}
</p>

<table class="table table-sm">
    <!---  Adapt meta to desired output --->
    {% if meta.schunk %}
        {% set shape = '%s items (%s)' % (meta.shape, meta.schunk.nbytes|filesizeformat) %}
        {% set _ = meta.__setattr__('shape', shape) %}

        {% set chunks = '%s items (%s)' % (meta.chunks, meta.schunk.chunksize|filesizeformat) %}
        {% set _ = meta.__setattr__('chunks', chunks) %}

        {% set cparams = meta.schunk.cparams %}
        <!---  We don't want to show everything --->
        {% set _ = cparams.__delattr__('codec_meta') %}
        {% set _ = cparams.__delattr__('clevel') %}
        {% set _ = cparams.__delattr__('nthreads') %}
        {% set _ = cparams.__delattr__('splitmode') %}
        {% set _ = cparams.__delattr__('tuner') %}
        {% set _ = cparams.__delattr__('use_dict') %}
        {% set _ = cparams.__delattr__('typesize')  %}

        {% set schunk = meta.schunk %}
        {% for key, value in cparams %}
            {% if key not in ['filters', 'filters_meta'] %}
                {% set _ = schunk.__setattr__(key, value) %}
            {% endif %}
        {% endfor %}
        {% set _ = schunk.__delattr__('cparams') %}
        {% set _ = meta.__setattr__('schunk', schunk) %}

        {% set blocks = '%s items (%s)' % (meta.blocks, meta.schunk.blocksize|filesizeformat) %}
        {% set _ = meta.__setattr__('blocks', blocks) %}

        {% set nbytes_value = '%d (cbytes: %d ; cratio: %.2f)' %
            (meta.schunk.nbytes, meta.schunk.cbytes, meta.schunk.cratio) %}
        {% set _ = meta.schunk.__setattr__('nbytes', nbytes_value) %}
        {% set _ = meta.schunk.__delattr__('cbytes') %}
        {% set _ = meta.schunk.__delattr__('cratio') %}

    {% else %}
        {% if meta.nbytes %}
            {% set nbytes_value = '%d (cbytes: %d ; cratio: %.2f)' %
                (meta.nbytes, meta.cbytes, meta.cratio) %}
            {% set _ = meta.__setattr__('nbytes', nbytes_value) %}
            {% set _ = meta.__delattr__('cbytes') %}
            {% set _ = meta.__delattr__('cratio') %}
            {% set _ = meta.cparams.__delattr__('filters') %}
            {% set _ = meta.cparams.__delattr__('filters_meta') %}
        {% endif %}
    {% endif %}

    {# All the next information is a bit too much for the main window #}
    {% set excluded_keys = [
        'chunkshape', 'chunksize', 'vlmeta',
        'contiguous', 'urlpath', 'blocksize'
        ] %}
    {% for key, value in meta %}
        {% if key in ['schunk', 'cparams'] %}
            {% for key2, value2 in meta[key] %}
                {% if key2 not in excluded_keys %}
                    {% if value2 is not none %}
                    <tr>
                        <th scope="row" class="text-nowrap">{{ key2 }}</th>
                        <td>{{ value2 }}</td>
                    </tr>
                    {% endif %}
                {% endif %}
            {% endfor %}
        {% else %}
            {% if key != 'urlpath' and value is not none %}
            <tr>
                <th scope="row" class="text-nowrap">{{ key }}</th>
                <td style="width: 100%">{{ value }}</td>
            </tr>
            {% endif %}
        {% endif %}
    {% endfor %}

{% if meta.schunk %}
    {% set vlmeta = meta.schunk.vlmeta %}
{% else %}
    {% set vlmeta = meta.vlmeta %}
{% endif %}
{% if vlmeta %}
    <tr>
        <th colspan="2">
            <h4>VLmeta (user attributes)</h4>
        </th>
    </tr>
    {% for key, value in vlmeta.items() %}
        <tr>
            <th scope="row" class="text-nowrap">{{ key }}</th>
            <td style="width: 100%">{{ value }}</td>
        </tr>
    {% endfor %}
{% endif %}

</table>
