{% comment This template expects the default xhtml autoescaping. %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Directory listing for {{ path }}</title>
        <link rel="stylesheet" href="/static/styles.css" />
    </head>
    <body>
        <div id="wrapper">
            <div id="breadcrumb">
                {% for (name, part_path) in breadcrumbs %}
                <a href="{{ part_path }}">{{ name }}</a> /
                {% end %}
            </div>
            <div id="message">
                {% if files_hidden %}
                {% if params.get('hidden') %}
                    <a href=".{{ amend_query(params, hidden=0) }}">Hide hidden files</a>
                {% else %}
                    <a href=".{{ amend_query(params, hidden=1) }}">Show hidden files</a>
                {% end %}
                {% end %}
                {% if params.get('meta') %}
                    <a href=".{{ amend_query(params, meta=0) }}">Hide metadata</a>
                {% else %}
                    <a href=".{{ amend_query(params, meta=1) }}">Show metadata</a>
                {% end %}
                {% if params.get('hash') %}
                    <a href=".{{ amend_query(params, hash=0) }}">Hide hashes</a>
                {% else %}
                    <a href=".{{ amend_query(params, hash=1) }}">Show hashes</a>
                {% end %}
                {% if params.get('human') %}
                    <a href=".{{ amend_query(params, human=0) }}">Show sizes as bytes</a>
                {% else %}
                    <a href=".{{ amend_query(params, human=1) }}">Show readable sizes</a>
                {% end %}
            </div>
            <table>
                <tr>
                    {% if params.get('hash') %}
                        <th class="dir-hash">Hash</th>
                    {% end %}
                    {% if params.get('meta') %}
                        <th class="dir-meta-mode">Mode</th>
                        <th class="dir-meta-owner" colspan="2">Owner</th>
                        <th class="dir-meta-group" colspan="2">Group</th>
                    {% end %}
                    <th class="dir-size">Size</th>
                    {% if params.get('meta') %}
                        <th class="dir-meta-mtime">Last modified</th>
                    {% end %}
                    <th class="dir-name">Name</th>
                </tr>
                {% for (name, link, size, meta, oidx) in dir_contents %}
                <tr>
                    {% if params.get('hash') %}
                        <td class="dir-hash">{{ oidx if oidx else '' }}</td>
                    {% end %}
                    {% if params.get('meta') and meta is not None%}
                        <td class="dir-meta-mode">{{ mode_str(meta.mode) }}</td>
                        <td class="dir-meta-owner">{{ '' if meta.user is None else meta.user }}</td>
                        <td class="dir-meta-uid">{{ '' if meta.uid is None else meta.uid }}</td>
                        <td class="dir-meta-group">{{ '' if meta.group is None else meta.group }}</td>
                        <td class="dir-meta-gid">{{ '' if meta.gid is None else meta.gid }}</td>
                    {% end %}
                    <td class="dir-size">{{ '' if size is None else size }}</td>
                    {% if params.get('meta') and meta %}
                      <td class="dir-meta-mtime"> {{ local_time_str(meta.mtime) or '' }}</td>
                    {% end %}
                    <td class="dir-name">
                      <a href="{% raw link %}">{{ name }}</a>
                      {% if params.get('meta') and meta and meta.symlink_target %}
                        → {{ meta.symlink_target }}
                      {% end %}
                    </td>
                </tr>
                {% end %}
            </table>
        </div>
    </body>
</html>
